Skip to content

Commit

Permalink
type the event handler (dispatch)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drapersniper committed Mar 29, 2022
1 parent 68e4922 commit 08368ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lavalink/lavalink.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import Optional, Tuple
from typing import Optional, Tuple, Union

import discord
from discord.ext.commands import Bot
Expand Down Expand Up @@ -261,7 +261,9 @@ async def _handle_update(player, data: node.PositionTime, raw_data: dict):
await player.handle_player_update(data)


def _get_update_args(data: enums.PlayerState, raw_data: dict):
def _get_update_args(
data: Union[node.PositionTime, enums.LavalinkEvents, node.Stats], raw_data: dict
):
guild_id = int(raw_data.get("guildId"))

try:
Expand Down Expand Up @@ -327,7 +329,11 @@ def unregister_stats_listener(coro):
pass


def dispatch(op: enums.LavalinkIncomingOp, data, raw_data: dict):
def dispatch(
op: enums.LavalinkIncomingOp,
data: Union[node.PositionTime, enums.LavalinkEvents, node.Stats],
raw_data: dict,
):
listeners = []
args = []
if op == enums.LavalinkIncomingOp.EVENT:
Expand Down
4 changes: 2 additions & 2 deletions lavalink/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ async def _handle_op(self, op: LavalinkIncomingOp, data):
self.event_handler(op, event, data)
elif op == LavalinkIncomingOp.PLAYER_UPDATE:
state = data.get("state", {})
state = PositionTime(
position = PositionTime(
position=state.get("position", 0),
time=state.get("time", 0),
connected=state.get("connected", False),
)
self.event_handler(op, state, data)
self.event_handler(op, position, data)
elif op == LavalinkIncomingOp.STATS:
stats = Stats(
memory=data.get("memory"),
Expand Down

0 comments on commit 08368ba

Please sign in to comment.