Skip to content

Commit

Permalink
[f] fix session del
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha765 committed Oct 21, 2024
1 parent bb6e511 commit 88ce492
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/tg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async def handle_del(_, message):

sessions = {}
selected_squares = {}
session_cleanup_tasks = {}
available_session_ids = []

@app.on_message(filters.text & filters.command("chess", prefixes="/") & filters.group)
Expand Down Expand Up @@ -93,11 +94,17 @@ async def handle_ttt_start(client, message):
selected_squares[session_id] = None
sessions[session_id]["x"]["id"], sessions[session_id]["x"]["name"], message_id = await ttt_start(session_id, sessions, message, get_translation)
sessions[session_id]["message_id"] = message_id
asyncio.create_task(remove_expired_ttt_session(session_id, sessions, selected_squares, available_session_ids, client))
cleanup_task = asyncio.create_task(remove_expired_ttt_session(session_id, sessions, selected_squares, available_session_ids, client))
session_cleanup_tasks[session_id] = cleanup_task
logging.debug(f"Session {session_id}: Add cleanup Task {session_cleanup_tasks[session_id]}.")

@app.on_callback_query(filters.regex(r"join_o_(\d+)"))
async def handle_ttt_join(client, callback_query):
session_id = int(callback_query.data.split('_')[-1])
if session_id in session_cleanup_tasks:
session_cleanup_tasks[session_id].cancel()
logging.debug(f"Session {session_id}: Del cleanup Task {session_cleanup_tasks[session_id]}.")
del session_cleanup_tasks[session_id]
await join_ttt_o(session_id, sessions, client, callback_query, get_translation)

@app.on_callback_query(filters.regex(r"^(\d+)_(\d+)$"))
Expand Down

0 comments on commit 88ce492

Please sign in to comment.