Skip to content

Commit

Permalink
fix for timer events in server specific data. (#2385)
Browse files Browse the repository at this point in the history
* hot fix for timer events in server specific data.

* fix both events.
  • Loading branch information
itsTheFae committed Feb 5, 2024
1 parent 270da4d commit 37bcf1f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def __init__(self, config_file=None, perms_file=None, aliases_file=None):
"auto_paused": False,
"halt_playlist_unpack": False,
"inactive_player_timer": (
asyncio.Event(),
None, # will be an asyncio.Event()
False, # event state tracking.
),
"inactive_vc_timer": (
asyncio.Event(),
None, # also a asyncio.Event(),
False,
), # The boolean is going show if the timeout is active or not
}
Expand Down Expand Up @@ -547,6 +547,10 @@ async def disconnect_voice_client(self, guild):

if self.config.leave_inactive_channel:
event, active = self.server_specific_data[guild.id]["inactive_vc_timer"]
# TODO: do server specific defaults properly!
if event is None:
event = asyncio.Event()

if active and not event.is_set():
event.set()

Expand Down Expand Up @@ -1553,6 +1557,10 @@ def _remove_url_from_autoplaylist(self, url):
async def handle_vc_inactivity(self, guild: discord.Guild):
event, active = self.server_specific_data[guild.id]["inactive_vc_timer"]

# TODO: do server specific defaults properly!
if event is None:
event = asyncio.Event()

if active:
log.debug(f"Channel activity already waiting in guild: {guild}")
return
Expand Down Expand Up @@ -1586,6 +1594,9 @@ async def handle_player_inactivity(self, player):
event, event_active = self.server_specific_data[guild.id][
"inactive_player_timer"
]
# TODO: do server specific defaults properly!
if event is None:
event = asyncio.Event()

if str(channel.id) in str(self.config.autojoin_channels):
log.debug(
Expand Down Expand Up @@ -1626,6 +1637,9 @@ async def reset_player_inactivity(self, player):
return
guild = player.voice_client.channel.guild
event, active = self.server_specific_data[guild.id]["inactive_player_timer"]
# TODO: do server specific defaults properly!
if event is None:
event = asyncio.Event()
if active and not event.is_set():
event.set()
log.debug("Player activity timer is being reset.")
Expand Down Expand Up @@ -5106,6 +5120,10 @@ async def on_voice_state_update(
guild = member.guild
event, active = self.server_specific_data[guild.id]["inactive_vc_timer"]

# TODO: do server specific defaults properly!
if event is None:
event = asyncio.Event()

if before.channel and self.user in before.channel.members:
if str(before.channel.id) in str(self.config.autojoin_channels):
log.info(
Expand Down

0 comments on commit 37bcf1f

Please sign in to comment.