Skip to content

Commit 3eb9b3b

Browse files
authored
[FEATURE] Forum Showcase (#264)
* add: forum showcase table * add: forum showcase db * add: forum showcase cog * chore: format * add: relativedelta module * chore: rename migration file * add: forum showcase view * add: forum showcase cog * add: forum showcase data * fix: stop is not async * fix: migrate_db * chore: remove view * feat: add showcase snd scheduling * add: autocomplete fix: schedule * fix: schedule * add: id field * fix: add and delete function * feat: add and delete command * remove: status field * add: toggle command * fix: refreshloopinterval * add: list command * add: config command * Remove forum showcase view * Update config and add command * fix: config command * Refactor scheduling * add: log if showcase is disabled * Disable showcase by default * change config name * Revert old migration file names * Start task forum showcase task if not running * Exclude archived threads in showcase Fix schedule timezone * fix: showcase not running * use utc timezone * Convert UTC+8 to UTC+0 * remove unecessary timezone.utc in datetime.now function * Fix random selection of threars * fix: showcase not running * Catch negative second * Set check to zero * Set interval default to weekly * Add weekday field * Fix migrate error * add: weekday field * Add weekday select * add: scheduler * add: weekday field * add: forum showcase views * add: logger in forum showcase db * add: weekday configuration for forum showcase cog * fix: error running poetry, unittest version not found * add: typehint for migration * refactor: currency converter intialization of symbols * fix: schedule * chore: remove asyncio * fix: selected configuration not syncing * add: log when schedule is changed * chore: remove log * fix: format date * fix: weekly schedule * fix: parsing time * fix: new schedule not updating * chore: separate next_run calculation * fix: set scheduled time to bot state * chore: calculate next run directly * chore: set the state inside the select function * add: interval selection * fix: interval selection * fix: timezone issue
1 parent 9d98acb commit 3eb9b3b

File tree

12 files changed

+889
-207
lines changed

12 files changed

+889
-207
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
alter table pph_auto_responses
2-
add matching_type varchar(255) default 'lenient' not null;
2+
add IF NOT EXISTS matching_type varchar(255) default 'lenient' not null;

migrations/19_thread_showcase.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS pph_forum_showcase (
88
id SERIAL PRIMARY KEY,
99
target_channel BIGINT NOT NULL,
1010
schedule TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
11-
interval forum_showcase_interval NOT NULL DEFAULT 'daily',
11+
interval forum_showcase_interval NOT NULL DEFAULT 'weekly',
1212
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
1313
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
1414
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--
2+
--depends: 19_thread_showcase
3+
4+
CREATE TYPE forum_showcase_weekday AS ENUM ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
5+
6+
ALTER TABLE IF EXISTS pph_forum_showcase ADD COLUMN weekday forum_showcase_weekday NOT NULL DEFAULT 'Monday';

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ description = ""
55
authors = ["Jedddy <jedbalita25@gmail.com>"]
66
readme = "README.md"
77
packages = [
8-
{include = "src"},
9-
{include = "bot", from = "src"},
10-
{include = "cogs", from = "src"},
11-
{include = "*", from = "src/bot"}
8+
{ include = "src" },
9+
{ include = "bot", from = "src" },
10+
{ include = "cogs", from = "src" },
11+
{ include = "*", from = "src/bot" },
1212
]
1313

1414
[tool.poetry.dependencies]

src/bot/main.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
from yoyo.backends.base import DatabaseBackend
4+
35
from src.utils.logging.logger import BotLogger
46
from src.bot.config import Database, Config, get_config
57
from src.utils.logging.discord_handler import DiscordHandler
@@ -23,7 +25,13 @@ class ProgPhil(Bot):
2325
bot_logger: BotLogger
2426
pool: Pool
2527

26-
def __init__(self, pool: Pool, cfg: Config, bot_logger: BotLogger, **kwargs):
28+
def __init__(
29+
self,
30+
pool: Pool,
31+
cfg: Config,
32+
bot_logger: BotLogger,
33+
**kwargs,
34+
):
2735
bot_cfg = cfg.bot
2836
super().__init__(
2937
**kwargs,
@@ -45,11 +53,11 @@ async def on_ready(self) -> None:
4553
logger_config = self.config.logger
4654
log_channel = self.get_channel(logger_config.log_channel)
4755

48-
discord_handler = DiscordHandler(log_channel)
56+
discord_handler = DiscordHandler(log_channel) # type: ignore
4957
bot_logger.add_handler(discord_handler)
5058

5159
logger = bot_logger.get_logger()
52-
logger.info(f"{self.user.display_name} running.")
60+
logger.info(f"{self.user.display_name} running.") # type: ignore
5361

5462
self.logger = logger
5563

@@ -109,13 +117,12 @@ def migrate_db(db: Database, logger: Logger) -> None:
109117
logger.info(f"Starting database migration with URL: {url}")
110118

111119
try:
112-
backend = get_backend(url)
120+
backend: DatabaseBackend = get_backend(url)
113121
migrations = read_migrations("./migrations/")
122+
to_apply = backend.to_apply(migrations)
114123

115-
with backend.lock():
116-
to_apply = backend.to_apply(migrations)
117-
logger.info(f"Found {len(to_apply)} migrations to apply")
118-
backend.apply_migrations(to_apply)
124+
logger.info(f"Found {len(to_apply)} migrations to apply")
125+
backend.apply_migrations(to_apply)
119126
logger.info("Migration completed successfully")
120127
except Exception as e:
121128
logger.error(f"Error during migration: {str(e)}")
@@ -139,7 +146,7 @@ async def main():
139146

140147
migrate_db(db_config, logger.get_logger())
141148

142-
bot = ProgPhil(pool, config, logger)
149+
bot = ProgPhil(pool, config, logger) # type: ignore
143150
await bot.launch()
144151

145152

0 commit comments

Comments
 (0)