Browse Source

Rename try_insert_user to store_user

pull/447/head
Rapptz 9 years ago
parent
commit
59a0df5f98
  1. 4
      discord/channel.py
  2. 2
      discord/client.py
  3. 2
      discord/member.py
  4. 4
      discord/message.py
  5. 14
      discord/state.py

4
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)

2
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):

2
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

4
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:

14
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):

Loading…
Cancel
Save