mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-21 08:17:47 +00:00
Implement Webhook.type
This commit is contained in:
parent
dc86670d7f
commit
f554819506
@ -49,6 +49,7 @@ __all__ = (
|
||||
'FriendFlags',
|
||||
'TeamMembershipState',
|
||||
'Theme',
|
||||
'WebhookType',
|
||||
)
|
||||
|
||||
def _create_value_cls(name):
|
||||
@ -419,6 +420,10 @@ class TeamMembershipState(Enum):
|
||||
invited = 1
|
||||
accepted = 2
|
||||
|
||||
class WebhookType(Enum):
|
||||
incoming = 1
|
||||
channel_follower = 2
|
||||
|
||||
def try_enum(cls, val):
|
||||
"""A function that tries to turn the value into enum ``cls``.
|
||||
|
||||
|
@ -33,6 +33,7 @@ import aiohttp
|
||||
|
||||
from . import utils
|
||||
from .errors import InvalidArgument, HTTPException, Forbidden, NotFound
|
||||
from .enums import try_enum, WebhookType
|
||||
from .user import BaseUser, User
|
||||
from .asset import Asset
|
||||
|
||||
@ -401,6 +402,8 @@ class Webhook:
|
||||
------------
|
||||
id: :class:`int`
|
||||
The webhook's ID
|
||||
type: :class:`WebhookType`
|
||||
The type of the webhook.
|
||||
token: Optional[:class:`str`]
|
||||
The authentication token of the webhook. If this is ``None``
|
||||
then the webhook cannot be used to make requests.
|
||||
@ -417,11 +420,12 @@ class Webhook:
|
||||
The default avatar of the webhook.
|
||||
"""
|
||||
|
||||
__slots__ = ('id', 'guild_id', 'channel_id', 'user', 'name', 'avatar',
|
||||
'token', '_state', '_adapter')
|
||||
__slots__ = ('id', 'type', 'guild_id', 'channel_id', 'user', 'name',
|
||||
'avatar', 'token', '_state', '_adapter')
|
||||
|
||||
def __init__(self, data, *, adapter, state=None):
|
||||
self.id = int(data['id'])
|
||||
self.type = try_enum(WebhookType, int(data['type']))
|
||||
self.channel_id = utils._get_as_snowflake(data, 'channel_id')
|
||||
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
|
||||
self.name = data.get('name')
|
||||
@ -470,6 +474,7 @@ class Webhook:
|
||||
|
||||
data = {
|
||||
'id': id,
|
||||
'type': 1,
|
||||
'token': token
|
||||
}
|
||||
|
||||
@ -497,13 +502,16 @@ class Webhook:
|
||||
m = re.search(r'discordapp.com/api/webhooks/(?P<id>[0-9]{17,21})/(?P<token>[A-Za-z0-9\.\-\_]{60,68})', url)
|
||||
if m is None:
|
||||
raise InvalidArgument('Invalid webhook URL given.')
|
||||
return cls(m.groupdict(), adapter=adapter)
|
||||
data = m.groupdict()
|
||||
data['type'] = 1
|
||||
return cls(data, adapter=adapter)
|
||||
|
||||
@classmethod
|
||||
def _as_follower(cls, data, *, channel, user):
|
||||
name = "{} #{}".format(channel.guild, channel)
|
||||
feed = {
|
||||
'id': data['webhook_id'],
|
||||
'type': 2,
|
||||
'name': name,
|
||||
'channel_id': channel.id,
|
||||
'guild_id': channel.guild.id,
|
||||
|
12
docs/api.rst
12
docs/api.rst
@ -1662,6 +1662,18 @@ of :class:`enum.Enum`.
|
||||
|
||||
Represents a member currently in the team.
|
||||
|
||||
.. class:: WebhookType
|
||||
|
||||
Represents the type of webhook that can be received.
|
||||
|
||||
.. attribute:: incoming
|
||||
|
||||
Represents a webhook that can post messages to channels with a token.
|
||||
|
||||
.. attribute:: channel_follower
|
||||
|
||||
Represents a webhook that is internally managed by Discord, used for following channels.
|
||||
|
||||
Async Iterator
|
||||
----------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user