Browse Source

Add voice regions + conform guild.vanity_url to standard seen for other url properties on guild.

pull/153/head
Luke 6 years ago
parent
commit
e5be243775
  1. 9
      disco/api/client.py
  2. 4
      disco/api/http.py
  3. 18
      disco/types/guild.py
  4. 16
      disco/types/voice.py

9
disco/api/client.py

@ -14,6 +14,7 @@ from disco.types.message import Message
from disco.types.guild import Guild, GuildMember, GuildBan, Role, GuildEmoji, AuditLogEntry
from disco.types.channel import Channel
from disco.types.invite import Invite
from disco.types.voice import VoiceRegion
from disco.types.webhook import Webhook
@ -492,6 +493,10 @@ class APIClient(LoggingClass):
def guilds_roles_delete(self, guild, role, reason=None):
self.http(Routes.GUILDS_ROLES_DELETE, dict(guild=guild, role=role), headers=_reason_header(reason))
def guilds_regions_list(self, guild):
r = self.http(Routes.GUILDS_VOICE_REGIONS_LIST, dict(guild=guild))
return VoiceRegion.create_hash(self.client, 'id', r.json())
def guilds_invites_list(self, guild):
r = self.http(Routes.GUILDS_INVITES_LIST, dict(guild=guild))
return Invite.create_map(self.client, r.json())
@ -576,6 +581,10 @@ class APIClient(LoggingClass):
r = self.http(Routes.INVITES_DELETE, dict(invite=invite), headers=_reason_header(reason))
return Invite.create(self.client, r.json())
def regions_list(self):
r = self.http(Routes.VOICE_REGIONS_LIST)
return VoiceRegion.create_hash(self.client, 'id', r.json())
def webhooks_get(self, webhook):
r = self.http(Routes.WEBHOOKS_GET, dict(webhook=webhook))
return Webhook.create(self.client, r.json())

4
disco/api/http.py

@ -124,6 +124,10 @@ class Routes(object):
INVITES_GET = (HTTPMethod.GET, INVITES + '/{invite}')
INVITES_DELETE = (HTTPMethod.DELETE, INVITES + '/{invite}')
# Voice
VOICE = '/voice'
VOICE_REGIONS_LIST = (HTTPMethod.GET, VOICE + '/regions')
# Webhooks
WEBHOOKS = '/webhooks/{webhook}'
WEBHOOKS_GET = (HTTPMethod.GET, WEBHOOKS)

18
disco/types/guild.py

@ -357,11 +357,6 @@ class Guild(SlottedModel, Permissible):
def owner(self):
return self.members.get(self.owner_id)
@property
def vanity_url(self):
if self.vanity_url_code:
return 'https://discord.gg/' + self.vanity_url_code
def get_permissions(self, member):
"""
Get the permissions a user has in this guild.
@ -528,6 +523,9 @@ class Guild(SlottedModel, Permissible):
def get_emoji(self, emoji):
return self.client.api.guilds_emojis_get(self.id, emoji)
def get_regions(self):
return self.client.api.guilds_regions_list(self.id)
def get_icon_url(self, fmt=None, size=1024):
if not self.icon:
return ''
@ -538,6 +536,12 @@ class Guild(SlottedModel, Permissible):
else:
return 'https://cdn.discordapp.com/icons/{}/{}.webp?size={}'.format(self.id, self.icon, size)
def get_vanity_url(self):
if not self.vanity_url_code:
return ''
return 'https://discord.gg/' + self.vanity_url_code
def get_splash_url(self, fmt='webp', size=1024):
if not self.splash:
return ''
@ -554,6 +558,10 @@ class Guild(SlottedModel, Permissible):
def icon_url(self):
return self.get_icon_url()
@property
def vanity_url(self):
return self.get_vanity_url()
@property
def splash_url(self):
return self.get_splash_url()

16
disco/types/voice.py

@ -1,4 +1,4 @@
from disco.types.base import SlottedModel, Field, snowflake, cached_property
from disco.types.base import SlottedModel, text, Field, snowflake, cached_property
class VoiceState(SlottedModel):
@ -23,3 +23,17 @@ class VoiceState(SlottedModel):
@cached_property
def user(self):
return self.client.state.users.get(self.user_id)
class VoiceRegion(SlottedModel):
id = Field(text)
name = Field(text)
vip = Field(bool)
optimal = Field(bool)
deprecated = Field(bool)
custom = Field(bool)
def __str__(self):
return self.id
def __repr__(self):
return u'<Region {}>'.format(self.name)

Loading…
Cancel
Save