Skip to content

Commit

Permalink
Merge branch 'main' into hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibo-Ulens committed Dec 19, 2023
2 parents 432717f + 29fe4a1 commit dae645b
Show file tree
Hide file tree
Showing 21 changed files with 872 additions and 84 deletions.
24 changes: 24 additions & 0 deletions alembic/versions/5014a1d75251_merge_freudpoints_and_confession_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""merge freudpoints and confession exposure
Revision ID: 5014a1d75251
Revises: 65f0d772d7ba, 7f5cc27e7f61
Create Date: 2023-10-12 16:13:29.299389
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "5014a1d75251"
down_revision = ("65f0d772d7ba", "7f5cc27e7f61")
branch_labels = None
depends_on = None


def upgrade() -> None:
pass


def downgrade() -> None:
pass
87 changes: 87 additions & 0 deletions alembic/versions/65f0d772d7ba_add_freudpoint_related_things.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""add FreudPoint related things
Revision ID: 65f0d772d7ba
Revises: 2adbec7716ff
Create Date: 2023-10-05 16:26:53.915342
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "65f0d772d7ba"
down_revision = "2adbec7716ff"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
"profile_statistics",
sa.Column(
"profile_discord_id",
sa.BigInteger,
sa.ForeignKey("profile.discord_id"),
nullable=False,
),
sa.Column(
"config_guild_id",
sa.BigInteger,
sa.ForeignKey("config.guild_id"),
nullable=False,
),
sa.Column(
"freudpoints", sa.Integer, nullable=False, default=0, server_default="0"
),
sa.Column(
"spendable_freudpoints",
sa.Integer,
nullable=False,
default=1,
server_default="1",
),
)

op.create_primary_key(
"pk_profilestat_discordid_guildid",
"profile_statistics",
["profile_discord_id", "config_guild_id"],
)

op.create_check_constraint(
"freudpoints_min_0", "profile_statistics", "freudpoints >= 0"
)
op.create_check_constraint(
"spendable_freudpoints_min_0",
"profile_statistics",
"spendable_freudpoints >= 0",
)

op.add_column(
"config",
sa.Column(
"max_spendable_freudpoints",
sa.Integer,
nullable=False,
default=5,
server_default="5",
),
)

op.create_check_constraint(
"max_spendable_freudpoints_min_0", "config", "max_spendable_freudpoints >= 0"
)


def downgrade() -> None:
op.drop_constraint("max_spendable_freudpoints_min_0", "config", type_="check")

op.drop_column("config", "max_spendable_freudpoints")

op.drop_constraint(
"spendable_freudpoints_min_0", "profile_statistics", type_="check"
)
op.drop_constraint("freudpoints_min_0", "profile_statistics", type_="check")

op.drop_table("profile_statistics")
29 changes: 29 additions & 0 deletions alembic/versions/7f5cc27e7f61_add_confession_exposure_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""add confession exposure counter
Revision ID: 7f5cc27e7f61
Revises: 2adbec7716ff
Create Date: 2023-10-07 21:43:38.674746
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "7f5cc27e7f61"
down_revision = "2adbec7716ff"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"profile",
sa.Column(
"confession_exposed_count", sa.Integer, nullable=False, server_default="0"
),
)


def downgrade() -> None:
op.drop_column("profile", "confession_exposed_count")
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""move exposed count to profile_statistics
Revision ID: a37a393bc831
Revises: 5014a1d75251
Create Date: 2023-10-12 16:16:04.210967
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "a37a393bc831"
down_revision = "5014a1d75251"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"profile_statistics",
sa.Column(
"confession_exposed_count",
sa.Integer,
nullable=False,
default=0,
server_default="0",
),
)

op.execute(
"update profile_statistics set confession_exposed_count=p.confession_exposed_count from profile p where profile_discord_id=p.discord_id"
)

op.drop_column("profile", "confession_exposed_count")


def downgrade() -> None:
op.add_column(
"profile",
sa.Column(
"confession_exposed_count",
sa.Integer,
nullable=False,
default=0,
server_default="0",
),
)

op.execute(
"update profile set confession_exposed_count=s.confession_exposed_count from profile_statistics s where discord_id=s.profile_discord_id"
)

op.drop_column("profile_statistics", "confession_exposed_count")
3 changes: 3 additions & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ async def main():
logger.info("Loading extensions...")
await bot.instance.load_extensions()

logger.info("Starting tasks...")
await bot.instance.start_tasks()

logger.info("Starting bot...")
await bot.instance.start(DISCORD_TOKEN)

Expand Down
27 changes: 26 additions & 1 deletion bot/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from contextlib import suppress
import importlib.util
from typing import Sequence

import logging
Expand All @@ -19,9 +20,11 @@ class Bot(commands.Bot):
"""Custom discord bot class"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.logger: Logger = None
self.discord_logger: GuildAdapter = None
super().__init__(*args, **kwargs)
self.loop = asyncio.get_running_loop()

@classmethod
async def create(cls) -> "Bot":
Expand Down Expand Up @@ -51,6 +54,28 @@ async def load_extensions(self) -> None:
await self.load_extension(ext)
logger.info(f"loaded extension '{ext}'")

async def start_tasks(self) -> None:
"""Start all bot-related tasks"""

from bot.tasks import TASKS

await self._async_setup_hook()

for task in TASKS:
await self._start_task(task)
logger.info(f"started task '{task}'")

async def _start_task(self, name: str):
spec = importlib.util.find_spec(name)
if spec is None:
raise ImportError(f"Task {name} not found")

lib = importlib.util.module_from_spec(spec)
spec.loader.exec_module(lib)

setup = getattr(lib, "setup")
await setup(self)

async def add_cog(
self,
cog: commands.Cog,
Expand Down
Loading

0 comments on commit dae645b

Please sign in to comment.