|
@ -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]: |
|
|