Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Included automatic disconnects as an InternalConnectionChangeEvent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fdnt7 authored Oct 4, 2022
1 parent db48b19 commit 69c5a19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lyra/src/lib/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""How many seconds to wait before checking the next time whether the track is confirmed to be stopped"""
ADD_TRACKS_WRAP_LIM: t.Final = 3
"""How many tracks to be displayed in `/play`'s output before the text got summarized to "Added <i> tracks...\""""
INACTIVITY_TIMEOUT: t.Final = 600
INACTIVITY_TIMEOUT: t.Final = 10
"""Timeout duration for the automatic inactivity disconnection in seconds"""
INACTIVITY_REFRESH: t.Final = 10
"""Amount of timeout refreshes to periodically check whether the inactivity condition is still met"""
Expand Down
7 changes: 6 additions & 1 deletion lyra/src/lib/lava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
set_data,
access_data,
)
from .events import ConnectionCommandsInvokedEvent, TrackStoppedEvent
from .events import (
InternalConnectionChangeEvent,
ConnectionCommandsInvokedEvent,
AutomaticConnectionChangeEvent,
TrackStoppedEvent,
)
from .impl import EventHandler
12 changes: 11 additions & 1 deletion lyra/src/lib/lava/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ class BaseLyraEvent(hk.Event, abc.ABC):


@a.frozen
class ConnectionCommandsInvokedEvent(BaseLyraEvent):
class InternalConnectionChangeEvent(BaseLyraEvent):
pass


@a.frozen
class ConnectionCommandsInvokedEvent(InternalConnectionChangeEvent):
pass


@a.frozen
class AutomaticConnectionChangeEvent(InternalConnectionChangeEvent):
pass


Expand Down
16 changes: 11 additions & 5 deletions lyra/src/modules/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
NotConnectedError,
)
from ..lib.cmd import CommandIdentifier as C, with_identifier
from ..lib.lava import ConnectionCommandsInvokedEvent, NodeDataRef, get_data
from ..lib.lava import (
InternalConnectionChangeEvent,
AutomaticConnectionChangeEvent,
NodeDataRef,
get_data,
)
from ..lib.music import __init_component__
from ..lib.connections import logger, cleanup, join_impl_precaught, leave

Expand Down Expand Up @@ -82,13 +87,13 @@ async def get_members_in_vc() -> frozenset[hk.VoiceState]:
assert out_ch

try:
conn_cmd_invoked = await bot.wait_for(
ConnectionCommandsInvokedEvent, timeout=0.5
internal_conn_change = await bot.wait_for(
InternalConnectionChangeEvent, timeout=0.5
)
except asyncio.TimeoutError:
conn_cmd_invoked = None
internal_conn_change = None

if not conn_cmd_invoked and old and old.user_id == bot_u.id:
if not internal_conn_change and old and old.user_id == bot_u.id:
if not new.channel_id:
await cleanup(event.guild_id, ndt, lvc, bot=bot, also_disconn=False)
await bot.rest.create_message(
Expand Down Expand Up @@ -132,6 +137,7 @@ async def on_everyone_leaves_vc():
assert __conn

await cleanup(event.guild_id, ndt, lvc, bot=bot, also_del_np_msg=False)
bot.dispatch(AutomaticConnectionChangeEvent(bot))

_vc: int = __conn['channel_id']
logger.info(
Expand Down

0 comments on commit 69c5a19

Please sign in to comment.