Implement Webhook.type
This commit is contained in:
parent
dc86670d7f
commit
f554819506
@ -49,6 +49,7 @@ __all__ = (
|
|||||||
'FriendFlags',
|
'FriendFlags',
|
||||||
'TeamMembershipState',
|
'TeamMembershipState',
|
||||||
'Theme',
|
'Theme',
|
||||||
|
'WebhookType',
|
||||||
)
|
)
|
||||||
|
|
||||||
def _create_value_cls(name):
|
def _create_value_cls(name):
|
||||||
@ -419,6 +420,10 @@ class TeamMembershipState(Enum):
|
|||||||
invited = 1
|
invited = 1
|
||||||
accepted = 2
|
accepted = 2
|
||||||
|
|
||||||
|
class WebhookType(Enum):
|
||||||
|
incoming = 1
|
||||||
|
channel_follower = 2
|
||||||
|
|
||||||
def try_enum(cls, val):
|
def try_enum(cls, val):
|
||||||
"""A function that tries to turn the value into enum ``cls``.
|
"""A function that tries to turn the value into enum ``cls``.
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import aiohttp
|
|||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .errors import InvalidArgument, HTTPException, Forbidden, NotFound
|
from .errors import InvalidArgument, HTTPException, Forbidden, NotFound
|
||||||
|
from .enums import try_enum, WebhookType
|
||||||
from .user import BaseUser, User
|
from .user import BaseUser, User
|
||||||
from .asset import Asset
|
from .asset import Asset
|
||||||
|
|
||||||
@ -401,6 +402,8 @@ class Webhook:
|
|||||||
------------
|
------------
|
||||||
id: :class:`int`
|
id: :class:`int`
|
||||||
The webhook's ID
|
The webhook's ID
|
||||||
|
type: :class:`WebhookType`
|
||||||
|
The type of the webhook.
|
||||||
token: Optional[:class:`str`]
|
token: Optional[:class:`str`]
|
||||||
The authentication token of the webhook. If this is ``None``
|
The authentication token of the webhook. If this is ``None``
|
||||||
then the webhook cannot be used to make requests.
|
then the webhook cannot be used to make requests.
|
||||||
@ -417,11 +420,12 @@ class Webhook:
|
|||||||
The default avatar of the webhook.
|
The default avatar of the webhook.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ('id', 'guild_id', 'channel_id', 'user', 'name', 'avatar',
|
__slots__ = ('id', 'type', 'guild_id', 'channel_id', 'user', 'name',
|
||||||
'token', '_state', '_adapter')
|
'avatar', 'token', '_state', '_adapter')
|
||||||
|
|
||||||
def __init__(self, data, *, adapter, state=None):
|
def __init__(self, data, *, adapter, state=None):
|
||||||
self.id = int(data['id'])
|
self.id = int(data['id'])
|
||||||
|
self.type = try_enum(WebhookType, int(data['type']))
|
||||||
self.channel_id = utils._get_as_snowflake(data, 'channel_id')
|
self.channel_id = utils._get_as_snowflake(data, 'channel_id')
|
||||||
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
|
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
|
||||||
self.name = data.get('name')
|
self.name = data.get('name')
|
||||||
@ -470,6 +474,7 @@ class Webhook:
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': id,
|
'id': id,
|
||||||
|
'type': 1,
|
||||||
'token': token
|
'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)
|
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:
|
if m is None:
|
||||||
raise InvalidArgument('Invalid webhook URL given.')
|
raise InvalidArgument('Invalid webhook URL given.')
|
||||||
return cls(m.groupdict(), adapter=adapter)
|
data = m.groupdict()
|
||||||
|
data['type'] = 1
|
||||||
|
return cls(data, adapter=adapter)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _as_follower(cls, data, *, channel, user):
|
def _as_follower(cls, data, *, channel, user):
|
||||||
name = "{} #{}".format(channel.guild, channel)
|
name = "{} #{}".format(channel.guild, channel)
|
||||||
feed = {
|
feed = {
|
||||||
'id': data['webhook_id'],
|
'id': data['webhook_id'],
|
||||||
|
'type': 2,
|
||||||
'name': name,
|
'name': name,
|
||||||
'channel_id': channel.id,
|
'channel_id': channel.id,
|
||||||
'guild_id': channel.guild.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.
|
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
|
Async Iterator
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user