Skip to content

Commit 19a7df3

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/417
2 parents a7300ca + e8dacd5 commit 19a7df3

File tree

6 files changed

+127
-6
lines changed

6 files changed

+127
-6
lines changed

.pylintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[MESSAGES CONTROL]
2+
3+
disable=protected-access
4+
5+
enable=bad-indentation,line-too-long
6+
7+
8+
[FORMAT]
9+
10+
indent-string=' '
11+
12+
max-line-length=120

discord/commands/permissions.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@
3535
)
3636

3737
class Permission:
38+
"""The class used in the application command decorators
39+
to hash permission data into a dictionary using the
40+
:meth:`to_dict` method to be sent to the discord API later on.
41+
42+
.. versionadded:: 2.0
43+
44+
Attributes
45+
-----------
46+
id: Union[:class:`int`, :class:`str`]
47+
A string or integer that represents or helps get
48+
the id of the user or role that the permission is tied to.
49+
type: :class:`int`
50+
An integer representing the type of the permission.
51+
permission: :class:`bool`
52+
A boolean representing the permission's value.
53+
guild_id: :class:`int`
54+
The integer which represents the id of the guild that the
55+
permission may be tied to.
56+
"""
3857
def __init__(self, id: Union[int, str], type: int, permission: bool = True, guild_id: int = None):
3958
self.id = id
4059
self.type = type
@@ -45,6 +64,27 @@ def to_dict(self) -> Dict[str, Union[int, bool]]:
4564
return {"id": self.id, "type": self.type, "permission": self.permission}
4665

4766
def permission(role_id: int = None, user_id: int = None, permission: bool = True, guild_id: int = None):
67+
"""The method used to specify application command permissions
68+
for specific users or roles using their id.
69+
70+
This method is meant to be used as a decorator.
71+
72+
.. versionadded:: 2.0
73+
74+
Parameters
75+
-----------
76+
role_id: :class:`int`
77+
An integer which represents the id of the role that the
78+
permission may be tied to.
79+
user_id: :class:`int`
80+
An integer which represents the id of the user that the
81+
permission may be tied to.
82+
permission: :class:`bool`
83+
A boolean representing the permission's value.
84+
guild_id: :class:`int`
85+
The integer which represents the id of the guild that the
86+
permission may be tied to.
87+
"""
4888
def decorator(func: Callable):
4989
if not role_id is None:
5090
app_cmd_perm = Permission(role_id, 1, permission, guild_id)
@@ -65,6 +105,21 @@ def decorator(func: Callable):
65105
return decorator
66106

67107
def has_role(item: Union[int, str], guild_id: int = None):
108+
"""The method used to specify application command role restrictions.
109+
110+
This method is meant to be used as a decorator.
111+
112+
.. versionadded:: 2.0
113+
114+
Parameters
115+
-----------
116+
item: Union[:class:`int`, :class:`str`]
117+
An integer or string that represent the id or name of the role
118+
that the permission is tied to.
119+
guild_id: :class:`int`
120+
The integer which represents the id of the guild that the
121+
permission may be tied to.
122+
"""
68123
def decorator(func: Callable):
69124
# Create __app_cmd_perms__
70125
if not hasattr(func, '__app_cmd_perms__'):
@@ -81,6 +136,22 @@ def decorator(func: Callable):
81136
return decorator
82137

83138
def has_any_role(*items: Union[int, str], guild_id: int = None):
139+
"""The method used to specify multiple application command role restrictions,
140+
The application command runs if the invoker has **any** of the specified roles.
141+
142+
This method is meant to be used as a decorator.
143+
144+
.. versionadded:: 2.0
145+
146+
Parameters
147+
-----------
148+
*items: Union[:class:`int`, :class:`str`]
149+
The integers or strings that represent the ids or names of the roles
150+
that the permission is tied to.
151+
guild_id: :class:`int`
152+
The integer which represents the id of the guild that the
153+
permission may be tied to.
154+
"""
84155
def decorator(func: Callable):
85156
# Create __app_cmd_perms__
86157
if not hasattr(func, '__app_cmd_perms__'):
@@ -98,6 +169,20 @@ def decorator(func: Callable):
98169
return decorator
99170

100171
def is_user(user: int, guild_id: int = None):
172+
"""The method used to specify application command user restrictions.
173+
174+
This method is meant to be used as a decorator.
175+
176+
.. versionadded:: 2.0
177+
178+
Parameters
179+
-----------
180+
user: :class:`int`
181+
An integer that represent the id of the user that the permission is tied to.
182+
guild_id: :class:`int`
183+
The integer which represents the id of the guild that the
184+
permission may be tied to.
185+
"""
101186
def decorator(func: Callable):
102187
# Create __app_cmd_perms__
103188
if not hasattr(func, '__app_cmd_perms__'):
@@ -114,6 +199,19 @@ def decorator(func: Callable):
114199
return decorator
115200

116201
def is_owner(guild_id: int = None):
202+
"""The method used to limit application commands exclusively
203+
to the owner of the bot.
204+
205+
This method is meant to be used as a decorator.
206+
207+
.. versionadded:: 2.0
208+
209+
Parameters
210+
-----------
211+
guild_id: :class:`int`
212+
The integer which represents the id of the guild that the
213+
permission may be tied to.
214+
"""
117215
def decorator(func: Callable):
118216
# Create __app_cmd_perms__
119217
if not hasattr(func, '__app_cmd_perms__'):
@@ -127,4 +225,4 @@ def decorator(func: Callable):
127225

128226
return func
129227

130-
return decorator
228+
return decorator

discord/webhook/async_.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ async def send(
13121312
view: View = MISSING,
13131313
thread: Snowflake = MISSING,
13141314
wait: bool = False,
1315+
delete_after: float = None,
13151316
) -> Optional[WebhookMessage]:
13161317
"""|coro|
13171318
@@ -1377,6 +1378,9 @@ async def send(
13771378
The thread to send this webhook to.
13781379
13791380
.. versionadded:: 2.0
1381+
delete_after: :class:`float`
1382+
If provided, the number of seconds to wait in the background
1383+
before deleting the message we just sent.
13801384
13811385
Raises
13821386
--------
@@ -1459,6 +1463,12 @@ async def send(
14591463
message_id = None if msg is None else msg.id
14601464
self._state.store_view(view, message_id)
14611465

1466+
if delete_after is not None:
1467+
async def delete():
1468+
await asyncio.sleep(delete_after)
1469+
await msg.delete()
1470+
asyncio.ensure_future(delete(), loop=self._state.loop)
1471+
14621472
return msg
14631473

14641474
async def fetch_message(

docs/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@
159159
html_theme = 'basic'
160160

161161
html_context = {
162-
'discord_invite': 'https://discord.gg/rdXkRJG7pS',
162+
'discord_invite': 'https://pycord.dev/discord',
163163
'discord_extensions': [
164164
('discord.ext.commands', 'ext/commands'),
165165
('discord.ext.tasks', 'ext/tasks'),
166166
],
167167
}
168168

169169
resource_links = {
170-
'discord': 'https://discord.gg/rdXkRJG7pS',
170+
'discord': 'https://pycord.dev/discord',
171171
'issues': 'https://github.com/Pycord-Development/pycord/issues',
172172
'discussions': 'https://github.com/Pycord-Development/pycord/discussions',
173173
'examples': f'https://github.com/Pycord-Development/pycord/tree/{branch}/examples',
@@ -357,5 +357,5 @@
357357
def setup(app):
358358
if app.config.language == 'ja':
359359
app.config.intersphinx_mapping['py'] = ('https://docs.python.org/ja/3', None)
360-
app.config.html_context['discord_invite'] = 'https://discord.gg/rdXkRJG7pS'
361-
app.config.resource_links['discord'] = 'https://discord.gg/rdXkRJG7pS'
360+
app.config.html_context['discord_invite'] = 'https://pycord.dev/discord'
361+
app.config.resource_links['discord'] = 'https://pycord.dev/discord'

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@
9393
'Topic :: Software Development :: Libraries :: Python Modules',
9494
'Topic :: Utilities',
9595
'Typing :: Typed',
96-
]
96+
],
97+
test_suite='tests',
9798
)

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)