Add support for voice channel parties

Basically the same thing as https://www.npmjs.com/package/discord-together and https://pypi.org/project/discord-together/
This commit is contained in:
Wasi Master 2021-08-29 23:04:12 +06:00
parent 9356e385d8
commit 3f8683de31
3 changed files with 74 additions and 1 deletions

View File

@ -27,7 +27,7 @@ import asyncio
import discord.abc import discord.abc
from .permissions import Permissions from .permissions import Permissions
from .enums import ChannelType, try_enum, VoiceRegion from .enums import ChannelType, try_enum, VoiceRegion, PartyType
from .mixins import Hashable from .mixins import Hashable
from . import utils from . import utils
from .asset import Asset from .asset import Asset
@ -734,6 +734,37 @@ class VoiceChannel(VocalGuildChannel):
await self._edit(options, reason=reason) await self._edit(options, reason=reason)
async def create_party(self, application_id: PartyType, max_age: int = 86400 , max_uses: int = 0):
"""|coro|
Creates a party in this voice channel.
.. versionadded:: 1.7.3.8
Parameters
----------
application_id : PartyType
The id of the application the party belongs to. currently any of
``PartyType.youtube``, ``PartyType.poker``, ``PartyType.betrayal``, ``PartyType.fishing``, ``PartyType.chess``.
max_age : int, optional
Duration in seconds after which the invite expires, by default 1 day.
max_uses : int, optional
maximum number of times this invite can be used, by default Unlimited.
Raises
-------
Forbidden
You do not have permissions to create a party.
HTTPException
Party creation failed.
Returns
--------
:class:`Party`
The created party.
"""
return Party(await self._state.http.create_party(self.id, application_id.value, max_age=max_age, max_uses=max_uses))
class StageChannel(VocalGuildChannel): class StageChannel(VocalGuildChannel):
"""Represents a Discord guild stage channel. """Represents a Discord guild stage channel.
@ -1461,6 +1492,29 @@ class GroupChannel(discord.abc.Messageable, Hashable):
await self._state.http.leave_group(self.id) await self._state.http.leave_group(self.id)
class Party:
"""Represents a party in a voice channel."""
__slots__ = ('code', 'uses', 'max_uses', 'max_age', 'temporary', 'created_at')
def __init__(self, data):
self.code = data['code']
self.uses = data['uses']
self.max_uses = data['max_uses']
self.max_age = data['max_age']
self.temporary = data['temporary']
self.created_at = utils.parse_time(data.get('created_at'))
# TODO: add more fields here Such as guild, raw data: https://mystb.in/AdvertisersExperiencesMothers.json
def __repr__(self):
return f'<Party code={self.code}>'
def __str__(self):
return f'https://discord.gg/{self.code}'
def __eq__(self, other):
return isinstance(other, Party) and self.code == other.code
def _channel_factory(channel_type): def _channel_factory(channel_type):
value = try_enum(ChannelType, channel_type) value = try_enum(ChannelType, channel_type)
if value is ChannelType.text: if value is ChannelType.text:

View File

@ -30,6 +30,7 @@ __all__ = (
'Enum', 'Enum',
'ChannelType', 'ChannelType',
'MessageType', 'MessageType',
'PartyType',
'VoiceRegion', 'VoiceRegion',
'SpeakingState', 'SpeakingState',
'VerificationLevel', 'VerificationLevel',
@ -179,6 +180,13 @@ class MessageType(Enum):
guild_discovery_grace_period_initial_warning = 16 guild_discovery_grace_period_initial_warning = 16
guild_discovery_grace_period_final_warning = 17 guild_discovery_grace_period_final_warning = 17
class PartyType(Enum):
youtube = 755600276941176913
poker = 755827207812677713
betrayal = 773336526917861400
fishing = 814288819477020702
chess = 832012774040141894
class VoiceRegion(Enum): class VoiceRegion(Enum):
us_west = 'us-west' us_west = 'us-west'
us_east = 'us-east' us_east = 'us-east'

View File

@ -701,6 +701,17 @@ class HTTPClient:
def delete_channel(self, channel_id, *, reason=None): def delete_channel(self, channel_id, *, reason=None):
return self.request(Route('DELETE', '/channels/{channel_id}', channel_id=channel_id), reason=reason) return self.request(Route('DELETE', '/channels/{channel_id}', channel_id=channel_id), reason=reason)
def create_party(self, channel_id, application_id, max_age: int, max_uses: int):
payload = {
'max_age': max_age,
'max_uses': max_uses,
'target_application_id': application_id,
'target_type': 2,
'temporary': False,
'validate': None
}
return self.request(Route("POST", "/channels/{channel_id}/invites", channel_id=channel_id), json=payload)
# Webhook management # Webhook management
def create_webhook(self, channel_id, *, name, avatar=None, reason=None): def create_webhook(self, channel_id, *, name, avatar=None, reason=None):