diff --git a/disco/api/client.py b/disco/api/client.py index a319bd8..210cfaf 100644 --- a/disco/api/client.py +++ b/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()) diff --git a/disco/api/http.py b/disco/api/http.py index fb2c1a4..c699e8f 100644 --- a/disco/api/http.py +++ b/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) diff --git a/disco/types/guild.py b/disco/types/guild.py index 791689f..c1513e0 100644 --- a/disco/types/guild.py +++ b/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() diff --git a/disco/types/voice.py b/disco/types/voice.py index bb7c055..6fef4cd 100644 --- a/disco/types/voice.py +++ b/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''.format(self.name)