Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ DISCORD_CLIENT_SECRET=discord_client_secret
STEAM_API_KEY=some_steam_api_key
CSRF_TRUSTED_ORIGINS=http://localhost:8002
CORS_ALLOW_ALL_ORIGINS=True
SECURE_SSL_REDIRECT=False
SECURE_SSL_REDIRECT=False
DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_PASSWORD=password
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,6 @@ pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/django,python
*.sqlite3
*.env.prod
*.env.prod

.idea/
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

21 changes: 0 additions & 21 deletions .idea/cs2-battle-bot-api.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/material_theme_project_new.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/ruff.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ RUN poetry config virtualenvs.create false
#RUN poetry config installer.no-binary cryptography

# Copy the project files for dependency installation
COPY pyproject.toml ./poetry.lock /code/
COPY ./pyproject.toml ./poetry.lock /code/

# Install project dependencies using Poetry
RUN poetry install --no-interaction --no-ansi



# Stage 2: Runtime environment
FROM builder AS runtime
ENV PYTHONUNBUFFERED 1
Expand All @@ -31,9 +33,11 @@ WORKDIR /app
# Copy only the necessary files from the build stage
COPY --from=builder /code /app

COPY --from=builder /code/pyproject.toml /app/


# Copy the source code
COPY src /app/
COPY scripts /app/scripts


# Change ownership to the dedicated user
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cs2-battle-bot-api"
version = "0.0.35"
version = "0.0.36"
description = ""
authors = ["Adrian Ciolek <[email protected]>"]
readme = "README.md"
Expand All @@ -11,7 +11,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.11"
django = "^5.0.2"
django = "^5.0.6"
httpx = "^0.27.0"
psycopg2-binary = "^2.9.9"
django-prefix-id = "^1.0.0"
Expand Down
24 changes: 1 addition & 23 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,2 @@
#!/bin/bash
echo "Building the project"
docker compose up -d --build
echo "Project is running"

# Run migrations
echo "Running migrations"
docker compose exec app sh -c "cd src && python manage.py migrate"
echo "Migrations complete"

# Loading map fixtures
echo "Loading map fixtures"
docker compose exec app sh -c "cd src && python manage.py loaddata maps"
echo "Map fixtures loaded"

echo "Creating superuser"
# Create superuser
SUPER_USER=$(docker compose exec app sh -c "cd src && python manage.py shell -c \"from django.contrib.auth import get_user_model; User = get_user_model(); user = User.objects.create_superuser('admin', '[email protected]', 'password'); print(user);\"")
echo "Superuser $SUPER_USER created"

echo "Creating API key"
# Create the API key
API_KEY=$(docker compose exec app sh -c "cd src && python manage.py shell -c \"from rest_framework_api_key.models import APIKey; api_key, key = APIKey.objects.create_key(name='cs2-battle-bot'); print(key);\"")
echo "Api key created: $API_KEY"
docker compose exec app sh -c "cd src && ./install.sh"
8 changes: 5 additions & 3 deletions src/cs2_battle_bot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@
def get_spectacular_settings():
# Load the pyproject.toml file
pyproject_path = Path(__file__).resolve().parent.parent / "pyproject.toml"
if DEBUG is True:
pyproject_data = None
try:
pyproject_data = toml.load(pyproject_path)
except FileNotFoundError:
pyproject_path = Path(__file__).resolve().parent.parent.parent / "pyproject.toml"
pyproject_data = toml.load(pyproject_path)
pyproject_data = toml.load(pyproject_path)

# Get the name, version, and description
name = pyproject_data.get("tool", {}).get("poetry", {}).get("name", "")
Expand All @@ -204,6 +207,5 @@ def get_spectacular_settings():
# Assign them to the SPECTACULAR_SETTINGS dictionary
return {"TITLE": name, "VERSION": version, "DESCRIPTION": description}


# Use the function
SPECTACULAR_SETTINGS = get_spectacular_settings()
7 changes: 6 additions & 1 deletion src/guilds/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

from guilds.models import Guild

class GuildAdmin(admin.ModelAdmin):
list_filter = ('created_at', 'updated_at')
search_fields = ('name', 'created_at', 'updated_at')
readonly_fields = ('id', 'created_at', 'updated_at')

# Register your models here.
admin.site.register(Guild)
admin.site.register(Guild, GuildAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 5.0.6 on 2024-05-10 10:20

import django.db.models.deletion
import prefix_id.field
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('guilds', '0004_remove_guild_members'),
]

operations = [
migrations.CreateModel(
name='Embed',
fields=[
('id', prefix_id.field.PrefixIDField(editable=False, max_length=28, prefix='embed', primary_key=True, serialize=False, unique=True)),
('title', models.CharField(blank=True, max_length=255, null=True)),
('description', models.TextField(blank=True, null=True)),
('color', models.CharField(blank=True, max_length=255, null=True)),
('footer', models.CharField(blank=True, max_length=255, null=True)),
('image', models.CharField(blank=True, max_length=255, null=True)),
('thumbnail', models.CharField(blank=True, max_length=255, null=True)),
('author', models.CharField(blank=True, max_length=255, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='EmbedField',
fields=[
('id', prefix_id.field.PrefixIDField(editable=False, max_length=34, prefix='embed_field', primary_key=True, serialize=False, unique=True)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('value', models.CharField(blank=True, max_length=255, null=True)),
('inline', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.AddField(
model_name='guild',
name='embed',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='guilds.embed'),
),
migrations.AddField(
model_name='embed',
name='fields',
field=models.ManyToManyField(blank=True, to='guilds.embedfield'),
),
]
18 changes: 18 additions & 0 deletions src/guilds/migrations/0006_embedfield_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-05-10 12:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('guilds', '0005_embed_embedfield_guild_embed_embed_fields'),
]

operations = [
migrations.AddField(
model_name='embedfield',
name='order',
field=models.IntegerField(default=1),
),
]
Loading