aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNCPlayz <[email protected]>2019-11-23 12:44:50 +0000
committerRapptz <[email protected]>2019-11-26 05:16:53 -0500
commitf554819506356b9c78fd6dbf07a88eadf9dd4693 (patch)
tree16602ce5c26dba39533c0721670f78250a2a0870
parentFix typo in help.py docs (diff)
downloaddiscord.py-f554819506356b9c78fd6dbf07a88eadf9dd4693.tar.xz
discord.py-f554819506356b9c78fd6dbf07a88eadf9dd4693.zip
Implement `Webhook.type`
-rw-r--r--discord/enums.py5
-rw-r--r--discord/webhook.py14
-rw-r--r--docs/api.rst12
3 files changed, 28 insertions, 3 deletions
diff --git a/discord/enums.py b/discord/enums.py
index 8938ace1..804b3959 100644
--- a/discord/enums.py
+++ b/discord/enums.py
@@ -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``.
diff --git a/discord/webhook.py b/discord/webhook.py
index 971a7ad6..513138a5 100644
--- a/discord/webhook.py
+++ b/discord/webhook.py
@@ -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,
diff --git a/docs/api.rst b/docs/api.rst
index fbb0b4b8..46bbe2a6 100644
--- a/docs/api.rst
+++ b/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
----------------