Browse Source

Added several end points + fixed typo (#138)

* Added end points + fixed typo

* mixup fixed

* oauth user add

* typo

* removed "return User.create(self.client, r.json())" from guilds_members_add due to lack of json response when user already in guild and switched name to mandatory arg in guilds_create

* formatting + removed roles/channels in guilds_create

* formatting 2.0, with even less random spaces

* remove guild.create on guilds_delete as no content is returned by Discord's api + reinstate roles and channels in guild_create

* spaces v tabs... FIGHT

* disco/api/client.py:410:9: F841

* Update client.py

* naming and create guilds args
pull/140/head
Luke Mathew-Byrne 6 years ago
committed by Andrei Zbikowski
parent
commit
92e940fcf9
  1. 57
      disco/api/client.py
  2. 5
      disco/api/http.py
  3. 9
      disco/types/guild.py

57
disco/api/client.py

@ -230,7 +230,7 @@ class APIClient(LoggingClass):
self.http(route, obj)
def channels_messages_reactions_delete_all(self, channel, message):
self.http(Routes.CHANNEL_MESSAGES_REACTIONS_DELETE_ALL, dict(channel=channel, message=message))
self.http(Routes.CHANNELS_MESSAGES_REACTIONS_DELETE_ALL, dict(channel=channel, message=message))
def channels_permissions_modify(self, channel, permission, allow, deny, typ, reason=None):
self.http(Routes.CHANNELS_PERMISSIONS_MODIFY, dict(channel=channel, permission=permission), json={
@ -288,7 +288,34 @@ class APIClient(LoggingClass):
return Guild.create(self.client, r.json())
def guilds_delete(self, guild):
r = self.http(Routes.GUILDS_DELETE, dict(guild=guild))
self.http(Routes.GUILDS_DELETE, dict(guild=guild))
def guilds_create(
self,
name,
region=None,
icon=None,
verification_level=None,
default_message_notifications=None,
explicit_content_filter=None,
roles=None,
channels=None):
payload = {
'name': name,
'roles': (roles or []),
'channels': (channels or []),
}
payload.update(optional(
region=region,
icon=icon,
verification_level=verification_level,
default_message_notifications=default_message_notifications,
explicit_content_filter=explicit_content_filter,
))
r = self.http(Routes.GUILDS_CREATE, json=payload)
return Guild.create(self.client, r.json())
def guilds_channels_list(self, guild):
@ -368,6 +395,20 @@ class APIClient(LoggingClass):
def guilds_members_me_nick(self, guild, nick):
self.http(Routes.GUILDS_MEMBERS_ME_NICK, dict(guild=guild), json={'nick': nick})
def guilds_members_add(self, guild, member, access_token, nick=None, roles=None, mute=None, deaf=None):
payload = {
'access_token': access_token
}
payload.update(optional(
nick=nick,
roles=roles,
mute=mute,
deaf=deaf,
))
self.http(Routes.GUILDS_MEMBERS_ADD, dict(guild=guild, member=member), json=payload)
def guilds_members_kick(self, guild, member, reason=None):
self.http(Routes.GUILDS_MEMBERS_KICK, dict(guild=guild, member=member), headers=_reason_header(reason))
@ -375,6 +416,10 @@ class APIClient(LoggingClass):
r = self.http(Routes.GUILDS_BANS_LIST, dict(guild=guild))
return GuildBan.create_hash(self.client, 'user.id', r.json())
def guilds_bans_get(self, guild, user):
r = self.http(Routes.GUILDS_BANS_GET, dict(guild=guild, user=user))
return GuildBan.create(self.client, r.json())
def guilds_bans_create(self, guild, user, delete_message_days=0, reason=None):
self.http(Routes.GUILDS_BANS_CREATE, dict(guild=guild, user=user), params={
'delete-message-days': delete_message_days,
@ -451,10 +496,18 @@ class APIClient(LoggingClass):
r = self.http(Routes.GUILDS_INVITES_LIST, dict(guild=guild))
return Invite.create_map(self.client, r.json())
def guilds_vanity_url_get(self, guild):
r = self.http(Routes.GUILDS_VANITY_URL_GET, dict(guild=guild))
return Invite.create(self.client, r.json())
def guilds_webhooks_list(self, guild):
r = self.http(Routes.GUILDS_WEBHOOKS_LIST, dict(guild=guild))
return Webhook.create_map(self.client, r.json())
def guilds_emojis_get(self, guild, emoji):
r = self.http(Routes.GUILDS_EMOJIS_GET, dict(guild=guild, emoji=emoji))
return GuildEmoji.create(self.client, r.json())
def guilds_emojis_list(self, guild):
r = self.http(Routes.GUILDS_EMOJIS_LIST, dict(guild=guild))
return GuildEmoji.create_map(self.client, r.json())

5
disco/api/http.py

@ -65,6 +65,7 @@ class Routes(object):
# Guilds
GUILDS = '/guilds/{guild}'
GUILDS_GET = (HTTPMethod.GET, GUILDS)
GUILDS_CREATE = (HTTPMethod.POST, '/guilds')
GUILDS_MODIFY = (HTTPMethod.PATCH, GUILDS)
GUILDS_DELETE = (HTTPMethod.DELETE, GUILDS)
GUILDS_CHANNELS_LIST = (HTTPMethod.GET, GUILDS + '/channels')
@ -77,7 +78,9 @@ class Routes(object):
GUILDS_MEMBERS_ROLES_REMOVE = (HTTPMethod.DELETE, GUILDS + '/members/{member}/roles/{role}')
GUILDS_MEMBERS_ME_NICK = (HTTPMethod.PATCH, GUILDS + '/members/@me/nick')
GUILDS_MEMBERS_KICK = (HTTPMethod.DELETE, GUILDS + '/members/{member}')
GUILDS_MEMBERS_ADD = (HTTPMethod.PUT, GUILDS + '/members/{member}')
GUILDS_BANS_LIST = (HTTPMethod.GET, GUILDS + '/bans')
GUILDS_BANS_GET = (HTTPMethod.GET, GUILDS + '/bans/{user}')
GUILDS_BANS_CREATE = (HTTPMethod.PUT, GUILDS + '/bans/{user}')
GUILDS_BANS_DELETE = (HTTPMethod.DELETE, GUILDS + '/bans/{user}')
GUILDS_ROLES_LIST = (HTTPMethod.GET, GUILDS + '/roles')
@ -88,6 +91,7 @@ class Routes(object):
GUILDS_PRUNE_COUNT = (HTTPMethod.GET, GUILDS + '/prune')
GUILDS_PRUNE_BEGIN = (HTTPMethod.POST, GUILDS + '/prune')
GUILDS_VOICE_REGIONS_LIST = (HTTPMethod.GET, GUILDS + '/regions')
GUILDS_VANITY_URL_GET = (HTTPMethod.GET, GUILDS + '/vanity-url')
GUILDS_INVITES_LIST = (HTTPMethod.GET, GUILDS + '/invites')
GUILDS_INTEGRATIONS_LIST = (HTTPMethod.GET, GUILDS + '/integrations')
GUILDS_INTEGRATIONS_CREATE = (HTTPMethod.POST, GUILDS + '/integrations')
@ -99,6 +103,7 @@ class Routes(object):
GUILDS_WEBHOOKS_LIST = (HTTPMethod.GET, GUILDS + '/webhooks')
GUILDS_EMOJIS_LIST = (HTTPMethod.GET, GUILDS + '/emojis')
GUILDS_EMOJIS_CREATE = (HTTPMethod.POST, GUILDS + '/emojis')
GUILDS_EMOJIS_GET = (HTTPMethod.GET, GUILDS + '/emojis/{emoji}')
GUILDS_EMOJIS_MODIFY = (HTTPMethod.PATCH, GUILDS + '/emojis/{emoji}')
GUILDS_EMOJIS_DELETE = (HTTPMethod.DELETE, GUILDS + '/emojis/{emoji}')
GUILDS_AUDITLOGS_LIST = (HTTPMethod.GET, GUILDS + '/audit-logs')

9
disco/types/guild.py

@ -434,6 +434,9 @@ class Guild(SlottedModel, Permissible):
def get_bans(self):
return self.client.api.guilds_bans_list(self.id)
def get_ban(self, user):
return self.client.api.guilds_bans_get(self.id, user)
def delete_ban(self, user, **kwargs):
self.client.api.guilds_bans_delete(self.id, to_snowflake(user), **kwargs)
@ -495,9 +498,15 @@ class Guild(SlottedModel, Permissible):
def get_invites(self):
return self.client.api.guilds_invites_list(self.id)
def get_vanity_url(self):
return self.client.api.guilds_vanity_url_get(self.id)
def get_emojis(self):
return self.client.api.guilds_emojis_list(self.id)
def get_emoji(self, emoji):
return self.client.api.guilds_emojis_get(self.id, emoji)
def get_icon_url(self, fmt='webp', size=1024):
if not self.icon:
return ''

Loading…
Cancel
Save