Skip to content

Commit

Permalink
Add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfies committed Sep 10, 2023
1 parent eaec0ce commit fd240be
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 327 deletions.
8 changes: 5 additions & 3 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ async def _handle_commands(
prev_cursor = cursor
cursor = data['cursor'].get('next')
cmds = data['application_commands']
apps: Dict[int, dict] = {int(app['id']): app for app in data.get('applications') or []}
apps = {int(app['id']): app for app in data.get('applications') or []}

for cmd in cmds:
# Handle faked parameters
Expand All @@ -280,8 +280,10 @@ async def _handle_commands(
except ValueError:
pass

cmd['application'] = apps.get(int(cmd['application_id']))
yield cls(state=state, data=cmd, channel=channel, target=target)
application_data = apps.get(int(cmd['application_id']))
application = state.create_integration_application(application_data) if application_data else None

yield cls(state=state, data=cmd, channel=channel, target=target, application=application)

cmd_ids = None
if application_id or len(cmds) < min(limit if limit else 25, 25) or len(cmds) == limit == 25:
Expand Down
10 changes: 5 additions & 5 deletions discord/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from __future__ import annotations

import datetime
from typing import Callable, Dict, List, Optional, Tuple, TYPE_CHECKING, Union
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple, Union

from . import utils
from .errors import ClientException
Expand All @@ -39,6 +39,7 @@
from .member import VoiceState
from .message import Message
from .state import ConnectionState
from .types.gateway import CallCreateEvent, CallUpdateEvent
from .user import BaseUser, User

_PrivateChannel = Union[abc.DMChannel, abc.GroupChannel]
Expand Down Expand Up @@ -144,7 +145,7 @@ class PrivateCall:
def __init__(
self,
*,
data: dict,
data: Union[CallCreateEvent, CallUpdateEvent],
state: ConnectionState,
message: Optional[Message],
channel: abc.PrivateChannel,
Expand All @@ -153,7 +154,6 @@ def __init__(
self._cs_message = message
self.channel = channel # type: ignore # Will always be a DMChannel here
self._ended: bool = False

self._update(data)

def _delete(self) -> None:
Expand All @@ -168,7 +168,7 @@ def _is_participating(self, user: BaseUser) -> bool:
state = self.voice_state_for(user)
return bool(state and state.channel and state.channel.id == self.channel.id)

def _update(self, data) -> None:
def _update(self, data: Union[CallCreateEvent, CallUpdateEvent]) -> None:
self._message_id = int(data['message_id'])
self.unavailable = data.get('unavailable', False)
try:
Expand All @@ -179,7 +179,7 @@ def _update(self, data) -> None:
channel = self.channel
recipients = self._get_recipients()
lookup = {u.id: u for u in recipients}
self._ringing = tuple(filter(None, map(lookup.get, data.get('ringing', []))))
self._ringing = tuple(filter(None, map(lookup.get, [int(x) for x in data.get('ringing', [])])))

for vs in data.get('voice_states', []):
self._state._update_voice_state(vs, channel.id)
Expand Down
Loading

0 comments on commit fd240be

Please sign in to comment.