Fix rejoin loop crash when pending_joins missing

This commit is contained in:
3nd3r
2025-12-28 23:08:04 -06:00
parent a8b4196cf2
commit 5efe1e70bf

View File

@@ -23,6 +23,9 @@ class DuckHuntBot:
self.writer: Optional[asyncio.StreamWriter] = None self.writer: Optional[asyncio.StreamWriter] = None
self.registered = False self.registered = False
self.channels_joined = set() self.channels_joined = set()
# Track requested joins / pending server confirmation.
# Used by auto-rejoin and (in newer revisions) admin join/leave reporting.
self.pending_joins = {}
self.shutdown_requested = False self.shutdown_requested = False
self.rejoin_attempts = {} # Track rejoin attempts per channel self.rejoin_attempts = {} # Track rejoin attempts per channel
self.rejoin_tasks = {} # Track active rejoin tasks self.rejoin_tasks = {} # Track active rejoin tasks
@@ -273,6 +276,10 @@ class DuckHuntBot:
async def schedule_rejoin(self, channel): async def schedule_rejoin(self, channel):
"""Schedule automatic rejoin attempts for a channel after being kicked""" """Schedule automatic rejoin attempts for a channel after being kicked"""
try: try:
# Backward/forward compatibility: ensure attribute exists.
if not hasattr(self, 'pending_joins') or not isinstance(self.pending_joins, dict):
self.pending_joins = {}
# Cancel any existing rejoin task for this channel # Cancel any existing rejoin task for this channel
if channel in self.rejoin_tasks: if channel in self.rejoin_tasks:
self.rejoin_tasks[channel].cancel() self.rejoin_tasks[channel].cancel()