diff --git a/src/db.py b/src/db.py index 2ea53c9..a1987da 100644 --- a/src/db.py +++ b/src/db.py @@ -7,14 +7,16 @@ async def get_db() -> aiosqlite.Connection: if not getattr(get_db, "db", None): - db = await aiosqlite.connect(config.SQLITE_DB_FILE_PATH) + db = await aiosqlite.connect(config.SQLITE_DB_FILE_PATH, + timeout=60 * 60 * 24 * 1 # 1 day + ) get_db.db = db return get_db.db async def fetch_all( - sql: LiteralString, params: Iterable[Any] | None = None + sql: LiteralString, params: Iterable[Any] | None = None ) -> list[dict]: cursor = await _get_cursor(sql, params) rows = await cursor.fetchall() @@ -24,7 +26,7 @@ async def fetch_all( async def fetch_one( - sql: LiteralString, params: Iterable[Any] | None = None + sql: LiteralString, params: Iterable[Any] | None = None ) -> dict | None: cursor = await _get_cursor(sql, params) row = await cursor.fetchone() @@ -34,7 +36,7 @@ async def fetch_one( async def execute( - sql: LiteralString, params: Iterable[Any] | None = None, *, autocommit: bool = True + sql: LiteralString, params: Iterable[Any] | None = None, *, autocommit: bool = True ) -> None: db = await get_db() await db.execute(sql, params) @@ -51,7 +53,7 @@ async def _async_close_db() -> None: async def _get_cursor( - sql: LiteralString, params: Iterable[Any] | None + sql: LiteralString, params: Iterable[Any] | None ) -> aiosqlite.Cursor: db = await get_db() db.row_factory = aiosqlite.Row diff --git a/src/handlers/game.py b/src/handlers/game.py index 75d0aee..ad942ba 100644 --- a/src/handlers/game.py +++ b/src/handlers/game.py @@ -38,3 +38,6 @@ async def game(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: ) ) context.bot_data.update(game_metadata) + + # Delete command message + await update.effective_message.delete() diff --git a/src/handlers/save.py b/src/handlers/save.py index 1c0bd77..93892eb 100644 --- a/src/handlers/save.py +++ b/src/handlers/save.py @@ -95,6 +95,13 @@ async def save(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.effective_message.reply_text( "The Game has been saved!. Results: {}".format(game.results) ) + # Delete the poll + await context.bot.delete_message( + chat_id=game.chat_id, + message_id=game.poll_id + ) + # Delete this callback /save message + await update.effective_message.delete() else: await update.effective_message.reply_text( "Something went wrong. Can't process your request."