mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
Hoist webhook detection outside of store_user helper
This commit is contained in:
parent
94bf7d8644
commit
f1bade4bda
@ -1041,8 +1041,8 @@ class _InteractionMessageState:
|
||||
def _get_guild(self, guild_id):
|
||||
return self._parent._get_guild(guild_id)
|
||||
|
||||
def store_user(self, data):
|
||||
return self._parent.store_user(data)
|
||||
def store_user(self, data, *, cache: bool = True):
|
||||
return self._parent.store_user(data, cache=cache)
|
||||
|
||||
def create_user(self, data):
|
||||
return self._parent.create_user(data)
|
||||
|
@ -1808,7 +1808,7 @@ class Message(PartialMessage, Hashable):
|
||||
self.nonce = value
|
||||
|
||||
def _handle_author(self, author: UserPayload) -> None:
|
||||
self.author = self._state.store_user(author)
|
||||
self.author = self._state.store_user(author, cache=self.webhook_id is None)
|
||||
if isinstance(self.guild, Guild):
|
||||
found = self.guild.get_member(self.author.id)
|
||||
if found is not None:
|
||||
|
@ -349,19 +349,18 @@ class ConnectionState(Generic[ClientT]):
|
||||
for vc in self.voice_clients:
|
||||
vc.main_ws = ws # type: ignore # Silencing the unknown attribute (ok at runtime).
|
||||
|
||||
def store_user(self, data: Union[UserPayload, PartialUserPayload]) -> User:
|
||||
def store_user(self, data: Union[UserPayload, PartialUserPayload], *, cache: bool = True) -> User:
|
||||
# this way is 300% faster than `dict.setdefault`.
|
||||
user_id = int(data['id'])
|
||||
try:
|
||||
return self._users[user_id]
|
||||
except KeyError:
|
||||
user = User(state=self, data=data)
|
||||
# TODO: with the removal of discrims this becomes a bit annoying
|
||||
if user.discriminator != '0000':
|
||||
if cache:
|
||||
self._users[user_id] = user
|
||||
return user
|
||||
|
||||
def store_user_no_intents(self, data: Union[UserPayload, PartialUserPayload]) -> User:
|
||||
def store_user_no_intents(self, data: Union[UserPayload, PartialUserPayload], *, cache: bool = True) -> User:
|
||||
return User(state=self, data=data)
|
||||
|
||||
def create_user(self, data: Union[UserPayload, PartialUserPayload]) -> User:
|
||||
|
@ -715,9 +715,9 @@ class _WebhookState:
|
||||
return self._parent._get_guild(guild_id)
|
||||
return None
|
||||
|
||||
def store_user(self, data: Union[UserPayload, PartialUserPayload]) -> BaseUser:
|
||||
def store_user(self, data: Union[UserPayload, PartialUserPayload], *, cache: bool = True) -> BaseUser:
|
||||
if self._parent is not None:
|
||||
return self._parent.store_user(data)
|
||||
return self._parent.store_user(data, cache=cache)
|
||||
# state parameter is artificial
|
||||
return BaseUser(state=self, data=data) # type: ignore
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user