From 59a0df5f985d4391c4b0af612c902bd6ac802920 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 10 Nov 2016 20:31:58 -0500 Subject: [PATCH] Rename try_insert_user to store_user --- discord/channel.py | 4 ++-- discord/client.py | 2 +- discord/member.py | 2 +- discord/message.py | 4 ++-- discord/state.py | 14 +++++++------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 70b0b0b39..b9141fe5f 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -510,7 +510,7 @@ class DMChannel(abc.MessageChannel, Hashable): def __init__(self, *, me, state, data): self._state = state - self.recipient = state.try_insert_user(data['recipients'][0]) + self.recipient = state.store_user(data['recipients'][0]) self.me = me self.id = int(data['id']) @@ -591,7 +591,7 @@ class GroupChannel(abc.MessageChannel, Hashable): def __init__(self, *, me, state, data): self._state = state - self.recipients = [state.try_insert_user(u) for u in data['recipients']] + self.recipients = [state.store_user(u) for u in data['recipients']] self.id = int(data['id']) self.me = me self._update_group(data) diff --git a/discord/client.py b/discord/client.py index 8b69e111f..466445464 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2395,7 +2395,7 @@ class Client: """ data = yield from self.http.get_bans(guild.id) - return [self.connection.try_insert_user(user) for user in data] + return [self.connection.store_user(user) for user in data] @asyncio.coroutine def prune_members(self, guild, *, days): diff --git a/discord/member.py b/discord/member.py index 5584d0bc8..964c17df3 100644 --- a/discord/member.py +++ b/discord/member.py @@ -142,7 +142,7 @@ class Member: def __init__(self, *, data, guild, state): self._state = state - self._user = state.try_insert_user(data['user']) + self._user = state.store_user(data['user']) self.joined_at = utils.parse_time(data.get('joined_at')) self.roles = data.get('roles', []) self.status = Status.offline diff --git a/discord/message.py b/discord/message.py index 1739fd65c..403178a76 100644 --- a/discord/message.py +++ b/discord/message.py @@ -141,7 +141,7 @@ class Message: continue self._try_patch(data, 'edited_timestamp', utils.parse_time) - self._try_patch(data, 'author', self._state.try_insert_user) + self._try_patch(data, 'author', self._state.store_user) self._try_patch(data, 'pinned', bool) self._try_patch(data, 'mention_everyone', bool) self._try_patch(data, 'tts', bool) @@ -161,7 +161,7 @@ class Message: def _handle_mentions(self, mentions): self.mentions = [] if self.guild is None: - self.mentions = [self._state.try_insert_user(m) for m in mentions] + self.mentions = [self._state.store_user(m) for m in mentions] return for mention in mentions: diff --git a/discord/state.py b/discord/state.py index e6e551fd4..c9a330b35 100644 --- a/discord/state.py +++ b/discord/state.py @@ -47,7 +47,7 @@ class ListenerType(enum.Enum): chunk = 0 Listener = namedtuple('Listener', ('type', 'future', 'predicate')) -StateContext = namedtuple('StateContext', 'try_insert_user http self_id') +StateContext = namedtuple('StateContext', 'store_user http self_id') log = logging.getLogger(__name__) ReadyState = namedtuple('ReadyState', ('launch', 'guilds')) @@ -60,7 +60,7 @@ class ConnectionState: self.syncer = syncer self.is_bot = None self._listeners = [] - self.ctx = StateContext(try_insert_user=self.try_insert_user, http=http, self_id=None) + self.ctx = StateContext(store_user=self.store_user, http=http, self_id=None) self.clear() def clear(self): @@ -119,7 +119,7 @@ class ConnectionState: for vc in self.voice_clients: vc.main_ws = ws - def try_insert_user(self, data): + def store_user(self, data): # this way is 300% faster than `dict.setdefault`. user_id = int(data['id']) try: @@ -219,7 +219,7 @@ class ConnectionState: def parse_ready(self, data): self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[]) - self.user = self.try_insert_user(data['user']) + self.user = self.store_user(data['user']) self.ctx.self_id = self.user.id guilds = data.get('guilds') @@ -397,13 +397,13 @@ class ConnectionState: def parse_channel_recipient_add(self, data): channel = self._get_private_channel(int(data['channel_id'])) - user = self.try_insert_user(data['user']) + user = self.store_user(data['user']) channel.recipients.append(user) self.dispatch('group_join', channel, user) def parse_channel_recipient_remove(self, data): channel = self._get_private_channel(int(data['channel_id'])) - user = self.try_insert_user(data['user']) + user = self.store_user(data['user']) try: channel.recipients.remove(user) except ValueError: @@ -577,7 +577,7 @@ class ConnectionState: guild = self._get_guild(int(data['guild_id'])) if guild is not None: if 'user' in data: - user = self.try_insert_user(data['user']) + user = self.store_user(data['user']) self.dispatch('member_unban', guild, user) def parse_guild_role_create(self, data):