Browse Source

Fix error with templates not having access to member cache flags.

This also changes the attribute from having an underscore

Fix #5986
pull/6076/head
Rapptz 4 years ago
parent
commit
431ee8794b
  1. 4
      discord/ext/commands/converter.py
  2. 4
      discord/guild.py
  3. 12
      discord/state.py
  4. 14
      discord/template.py

4
discord/ext/commands/converter.py

@ -129,7 +129,7 @@ class MemberConverter(IDConverter):
"""
async def query_member_named(self, guild, argument):
cache = guild._state._member_cache_flags.joined
cache = guild._state.member_cache_flags.joined
if len(argument) > 5 and argument[-5] == '#':
username, _, discriminator = argument.rpartition('#')
members = await guild.query_members(username, limit=100, cache=cache)
@ -140,7 +140,7 @@ class MemberConverter(IDConverter):
async def query_member_by_id(self, bot, guild, user_id):
ws = bot._get_websocket(shard_id=guild.shard_id)
cache = guild._state._member_cache_flags.joined
cache = guild._state.member_cache_flags.joined
if ws.is_ratelimited():
# If we're being rate limited on the WS, then fall back to using the HTTP API
# So we don't have to wait ~60 seconds for the query to finish

4
discord/guild.py

@ -305,8 +305,8 @@ class Guild(Hashable):
self._rules_channel_id = utils._get_as_snowflake(guild, 'rules_channel_id')
self._public_updates_channel_id = utils._get_as_snowflake(guild, 'public_updates_channel_id')
cache_online_members = self._state._member_cache_flags.online
cache_joined = self._state._member_cache_flags.joined
cache_online_members = self._state.member_cache_flags.online
cache_joined = self._state.member_cache_flags.joined
self_id = self._state.self_id
for mdata in guild.get('members', []):
member = Member(data=mdata, guild=self, state=state)

12
discord/state.py

@ -181,7 +181,7 @@ class ConnectionState:
cache_flags._verify_intents(intents)
self._member_cache_flags = cache_flags
self.member_cache_flags = cache_flags
self._activity = activity
self._status = status
self._intents = intents
@ -604,7 +604,7 @@ class ConnectionState:
user = data['user']
member_id = int(user['id'])
member = guild.get_member(member_id)
flags = self._member_cache_flags
flags = self.member_cache_flags
if member is None:
if 'username' not in user:
# sometimes we receive 'incomplete' member data post-removal.
@ -742,7 +742,7 @@ class ConnectionState:
return
member = Member(guild=guild, data=data, state=self)
if self._member_cache_flags.joined:
if self.member_cache_flags.joined:
guild._add_member(member)
try:
@ -786,7 +786,7 @@ class ConnectionState:
self.dispatch('member_update', old_member, member)
else:
if self._member_cache_flags.joined:
if self.member_cache_flags.joined:
member = Member(data=data, guild=guild, state=self)
guild._add_member(member)
log.debug('GUILD_MEMBER_UPDATE referencing an unknown member ID: %s. Discarding.', user_id)
@ -817,7 +817,7 @@ class ConnectionState:
return self._add_guild_from_data(data)
async def chunk_guild(self, guild, *, wait=True, cache=None):
cache = cache or self._member_cache_flags.joined
cache = cache or self.member_cache_flags.joined
request = self._chunk_requests.get(guild.id)
if request is None:
self._chunk_requests[guild.id] = request = ChunkRequest(guild.id, self.loop, self._get_guild, cache=cache)
@ -984,7 +984,7 @@ class ConnectionState:
def parse_voice_state_update(self, data):
guild = self._get_guild(utils._get_as_snowflake(data, 'guild_id'))
channel_id = utils._get_as_snowflake(data, 'channel_id')
flags = self._member_cache_flags
flags = self.member_cache_flags
self_id = self.user.id
if guild is not None:
if int(data['user_id']) == self_id:

14
discord/template.py

@ -42,11 +42,11 @@ class _PartialTemplateState:
def __init__(self, *, state):
self.__state = state
self.http = _FriendlyHttpAttributeErrorHelper()
@property
def is_bot(self):
return self.__state.is_bot
@property
def shard_count(self):
return self.__state.shard_count
@ -54,14 +54,18 @@ class _PartialTemplateState:
@property
def user(self):
return self.__state.user
@property
def self_id(self):
return self.__state.user.id
@property
def member_cache_flags(self):
return self.__state.member_cache_flags
def store_emoji(self, guild, packet):
return None
def _get_voice_client(self, id):
return None

Loading…
Cancel
Save