async def error_handler(update: types.Update, error: TelegramAPIError) -> None: for game in GAMES.values(): asyncio.create_task(game.scan_for_stale_timer()) if isinstance(error, MigrateToChat): if update.message.chat.id in GAMES: GAMES[error.migrate_to_chat_id] = GAMES.pop(update.message.chat.id) GAMES[error.migrate_to_chat_id].group_id = error.migrate_to_chat_id async with pool.acquire() as conn: await conn.execute( "UPDATE game SET group_id = $1 WHERE group_id = $2;\n" "UPDATE gameplayer SET group_id = $1 WHERE group_id = $2;\n" "DELETE FROM game WHERE group_id = $2;\n" "DELETE FROM gameplayer WHERE group_id = $2;", error.migrate_to_chat_id, update.message.chat.id) return await bot.send_message( ADMIN_GROUP_ID, f"`{error.__class__.__name__} @ " f"{update.message.chat.id if update.message and update.message.chat else 'idk'}`:\n" f"`{str(error)}`") if not update.message or not update.message.chat: return try: await update.message.reply( "Error occurred. My owner has been notified.") except TelegramAPIError: pass if update.message.chat.id in GAMES: GAMES[update.message.chat.id].state = GameState.KILLGAME await asyncio.sleep(2) try: del GAMES[update.message.chat.id] await update.message.reply("Game ended forcibly.") except: pass
async def error_handler(update: types.Update, error: TelegramAPIError) -> None: for game in GAMES.values( ): # TODO: Do this for group in which error occurs only asyncio.create_task(game.scan_for_stale_timer()) if isinstance(error, MigrateToChat): if update.message.chat.id in GAMES: # TODO: Test old_gid = GAMES[update.message.chat.id].group_id GAMES[error.migrate_to_chat_id] = GAMES.pop(update.message.chat.id) GAMES[error.migrate_to_chat_id].group_id = error.migrate_to_chat_id asyncio.create_task( send_admin_group( f"Game moved from {old_gid} to {error.migrate_to_chat_id}." )) async with pool.acquire() as conn: await conn.execute( """\ UPDATE game SET group_id = $1 WHERE group_id = $2; UPDATE gameplayer SET group_id = $1 WHERE group_id = $2; DELETE FROM game WHERE group_id = $2; DELETE FROM gameplayer WHERE group_id = $2;""", error.migrate_to_chat_id, update.message.chat.id, ) await send_admin_group(f"Group migrated to {error.migrate_to_chat_id}." ) return send_admin_msg = await send_admin_group( f"`{error.__class__.__name__} @ " f"{update.message.chat.id if update.message and update.message.chat else 'idk'}`:\n" f"`{str(error)}`", ) if not update.message or not update.message.chat: return try: await update.message.reply( "Error occurred. My owner has been notified.") except TelegramAPIError: pass if update.message.chat.id in GAMES: asyncio.create_task( send_admin_msg.reply( f"Killing game in {update.message.chat.id} consequently.")) GAMES[update.message.chat.id].state = GameState.KILLGAME await asyncio.sleep(2) try: del GAMES[update.message.chat.id] await update.message.reply("Game ended forcibly.") except: pass