Browse Source

Remove and address stale TODO comments

pull/9454/head
Rapptz 2 years ago
parent
commit
c5da0fe7c1
  1. 2
      discord/abc.py
  2. 36
      discord/guild.py
  3. 1
      discord/message.py
  4. 1
      discord/reaction.py

2
discord/abc.py

@ -946,8 +946,6 @@ class GuildChannel:
if len(permissions) > 0: if len(permissions) > 0:
raise TypeError('Cannot mix overwrite and keyword arguments.') raise TypeError('Cannot mix overwrite and keyword arguments.')
# TODO: wait for event
if overwrite is None: if overwrite is None:
await http.delete_channel_permissions(self.id, target.id, reason=reason) await http.delete_channel_permissions(self.id, target.id, reason=reason)
elif isinstance(overwrite, PermissionOverwrite): elif isinstance(overwrite, PermissionOverwrite):

36
discord/guild.py

@ -502,56 +502,47 @@ class Guild(Hashable):
self.approximate_member_count: Optional[int] = guild.get('approximate_member_count') self.approximate_member_count: Optional[int] = guild.get('approximate_member_count')
self.premium_progress_bar_enabled: bool = guild.get('premium_progress_bar_enabled', False) self.premium_progress_bar_enabled: bool = guild.get('premium_progress_bar_enabled', False)
self.owner_id: Optional[int] = utils._get_as_snowflake(guild, 'owner_id') self.owner_id: Optional[int] = utils._get_as_snowflake(guild, 'owner_id')
self._sync(guild)
self._large: Optional[bool] = None if self._member_count is None else self._member_count >= 250 self._large: Optional[bool] = None if self._member_count is None else self._member_count >= 250
self.afk_channel: Optional[VocalGuildChannel] = self.get_channel(utils._get_as_snowflake(guild, 'afk_channel_id')) # type: ignore if 'channels' in guild:
channels = guild['channels']
# TODO: refactor/remove?
def _sync(self, data: GuildPayload) -> None:
try:
self._large = data['large']
except KeyError:
pass
if 'channels' in data:
channels = data['channels']
for c in channels: for c in channels:
factory, ch_type = _guild_channel_factory(c['type']) factory, ch_type = _guild_channel_factory(c['type'])
if factory: if factory:
self._add_channel(factory(guild=self, data=c, state=self._state)) # type: ignore self._add_channel(factory(guild=self, data=c, state=self._state)) # type: ignore
for obj in data.get('voice_states', []): self.afk_channel: Optional[VocalGuildChannel] = self.get_channel(utils._get_as_snowflake(guild, 'afk_channel_id')) # type: ignore
for obj in guild.get('voice_states', []):
self._update_voice_state(obj, int(obj['channel_id'])) self._update_voice_state(obj, int(obj['channel_id']))
cache_joined = self._state.member_cache_flags.joined cache_joined = self._state.member_cache_flags.joined
cache_voice = self._state.member_cache_flags.voice cache_voice = self._state.member_cache_flags.voice
self_id = self._state.self_id self_id = self._state.self_id
for mdata in data.get('members', []): for mdata in guild.get('members', []):
member = Member(data=mdata, guild=self, state=self._state) # type: ignore # Members will have the 'user' key in this scenario member = Member(data=mdata, guild=self, state=self._state) # type: ignore # Members will have the 'user' key in this scenario
if cache_joined or member.id == self_id or (cache_voice and member.id in self._voice_states): if cache_joined or member.id == self_id or (cache_voice and member.id in self._voice_states):
self._add_member(member) self._add_member(member)
empty_tuple = () empty_tuple = ()
for presence in data.get('presences', []): for presence in guild.get('presences', []):
user_id = int(presence['user']['id']) user_id = int(presence['user']['id'])
member = self.get_member(user_id) member = self.get_member(user_id)
if member is not None: if member is not None:
member._presence_update(presence, empty_tuple) # type: ignore member._presence_update(presence, empty_tuple) # type: ignore
if 'threads' in data: if 'threads' in guild:
threads = data['threads'] threads = guild['threads']
for thread in threads: for thread in threads:
self._add_thread(Thread(guild=self, state=self._state, data=thread)) self._add_thread(Thread(guild=self, state=self._state, data=thread))
if 'stage_instances' in data: if 'stage_instances' in guild:
for s in data['stage_instances']: for s in guild['stage_instances']:
stage_instance = StageInstance(guild=self, data=s, state=self._state) stage_instance = StageInstance(guild=self, data=s, state=self._state)
self._stage_instances[stage_instance.id] = stage_instance self._stage_instances[stage_instance.id] = stage_instance
if 'guild_scheduled_events' in data: if 'guild_scheduled_events' in guild:
for s in data['guild_scheduled_events']: for s in guild['guild_scheduled_events']:
scheduled_event = ScheduledEvent(data=s, state=self._state) scheduled_event = ScheduledEvent(data=s, state=self._state)
self._scheduled_events[scheduled_event.id] = scheduled_event self._scheduled_events[scheduled_event.id] = scheduled_event
@ -3484,7 +3475,6 @@ class Guild(Hashable):
data = await self._state.http.create_role(self.id, reason=reason, **fields) data = await self._state.http.create_role(self.id, reason=reason, **fields)
role = Role(guild=self, data=data, state=self._state) role = Role(guild=self, data=data, state=self._state)
# TODO: add to cache
return role return role
async def edit_role_positions(self, positions: Mapping[Snowflake, int], *, reason: Optional[str] = None) -> List[Role]: async def edit_role_positions(self, positions: Mapping[Snowflake, int], *, reason: Optional[str] = None) -> List[Role]:

1
discord/message.py

@ -1827,7 +1827,6 @@ class Message(PartialMessage, Hashable):
author._update_from_message(member) # type: ignore author._update_from_message(member) # type: ignore
except AttributeError: except AttributeError:
# It's a user here # It's a user here
# TODO: consider adding to cache here
self.author = Member._from_message(message=self, data=member) self.author = Member._from_message(message=self, data=member)
def _handle_mentions(self, mentions: List[UserWithMemberPayload]) -> None: def _handle_mentions(self, mentions: List[UserWithMemberPayload]) -> None:

1
discord/reaction.py

@ -89,7 +89,6 @@ class Reaction:
self.count: int = data.get('count', 1) self.count: int = data.get('count', 1)
self.me: bool = data['me'] self.me: bool = data['me']
# TODO: typeguard
def is_custom_emoji(self) -> bool: def is_custom_emoji(self) -> bool:
""":class:`bool`: If this is a custom emoji.""" """:class:`bool`: If this is a custom emoji."""
return not isinstance(self.emoji, str) return not isinstance(self.emoji, str)

Loading…
Cancel
Save