From 2ea10b5d07d5343469cbe7230e616649eb10ed6c Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 8 Nov 2019 09:51:08 +0000 Subject: [PATCH] Split function --- disco/gateway/client.py | 28 +++++++++++++++++----------- disco/types/guild.py | 7 +++++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/disco/gateway/client.py b/disco/gateway/client.py index ce50f62..e08c54c 100644 --- a/disco/gateway/client.py +++ b/disco/gateway/client.py @@ -267,21 +267,27 @@ class GatewayClient(LoggingClass): gevent.spawn(self.connect_and_run) self.ws_event.wait() - def request_guild_members(self, guild_id_or_ids, query=None, limit=0, user_id_or_ids=None, presences=None): + def request_guild_members(self, guild_id_or_ids, query=None, limit=0, presences=False): """ Request a batch of Guild members from Discord. Generally this function can be called when initially loading Guilds to fill the local member state. - When calling this function, if user_id_or_ids is passed then query will be ignored. """ - payload = { + self.send(OPCode.REQUEST_GUILD_MEMBERS, { # This is simply unfortunate naming on the part of Discord... 'guild_id': guild_id_or_ids, 'limit': limit, - } - payload.update(optional( - # This is simply Discord sticking to an unfortunate naming scheme... - user_ids=user_id_or_ids, - query=query or '' if user_id_or_ids is None else None, - presences=presences, - )) - self.send(OPCode.REQUEST_GUILD_MEMBERS, payload) + 'presences': presences, + 'query': query or '', + }) + + def request_guild_members_by_id(self, guild_id_or_ids, user_id_or_ids, limit=0, presences=False): + """ + Request a batch of Guild members from Discord by their snowflake(s). + """ + self.send(OPCode.REQUEST_GUILD_MEMBERS, { + 'guild_id': guild_id_or_ids, + 'limit': limit, + 'presences': presences, + # This is simply even more unfortunate naming from Discord... + 'user_ids': user_id_or_ids, + }) diff --git a/disco/types/guild.py b/disco/types/guild.py index 57240e8..7e891a4 100644 --- a/disco/types/guild.py +++ b/disco/types/guild.py @@ -450,8 +450,11 @@ class Guild(SlottedModel, Permissible): return self.client.api.guilds_roles_modify(self.id, to_snowflake(role), **kwargs) - def request_guild_members(self, query=None, limit=0, user_id_or_ids=None, presences=None): - self.client.gw.request_guild_members(self.id, query, limit, user_id_or_ids, presences) + def request_guild_members(self, query=None, limit=0, presences=False): + self.client.gw.request_guild_members(self.id, query, limit, presences) + + def request_guild_members_by_id(self, user_id_or_ids, limit=0, presences=False): + self.client.gw.request_guild_members_by_id(self.id, user_id_or_ids, limit, presences) def sync(self): warnings.warn(