Skip to content

Commit edfdeac

Browse files
committed
Run black and isort on codebase
1 parent cb967cd commit edfdeac

File tree

11 files changed

+687
-446
lines changed

11 files changed

+687
-446
lines changed

discord_slash/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"""
1010

1111
from .client import SlashCommand # noqa: F401
12-
from .model import SlashCommandOptionType # noqa: F401
13-
from .context import SlashContext # noqa: F401
12+
from .const import __version__ # noqa: F401
1413
from .context import ComponentContext # noqa: F401
14+
from .context import SlashContext # noqa: F401
1515
from .dpy_overrides import ComponentMessage # noqa: F401
16+
from .model import SlashCommandOptionType # noqa: F401
1617
from .utils import manage_commands # noqa: F401
1718
from .utils import manage_components # noqa: F401
18-
from .const import __version__ # noqa: F401

discord_slash/client.py

Lines changed: 218 additions & 124 deletions
Large diffs are not rendered by default.

discord_slash/cog_ext.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import typing
21
import inspect
2+
import typing
3+
34
from .model import CogBaseCommandObject, CogSubcommandObject
45
from .utils import manage_commands
56

67

7-
def cog_slash(*,
8-
name: str = None,
9-
description: str = None,
10-
guild_ids: typing.List[int] = None,
11-
options: typing.List[dict] = None,
12-
default_permission: bool = True,
13-
permissions: typing.Dict[int, list] = None,
14-
connector: dict = None):
8+
def cog_slash(
9+
*,
10+
name: str = None,
11+
description: str = None,
12+
guild_ids: typing.List[int] = None,
13+
options: typing.List[dict] = None,
14+
default_permission: bool = True,
15+
permissions: typing.Dict[int, list] = None,
16+
connector: dict = None
17+
):
1518
"""
1619
Decorator for Cog to add slash command.\n
1720
Almost same as :func:`.client.SlashCommand.slash`.
@@ -43,6 +46,7 @@ async def ping(self, ctx: SlashContext):
4346
:param connector: Kwargs connector for the command. Default ``None``.
4447
:type connector: dict
4548
"""
49+
4650
def wrapper(cmd):
4751
desc = description or inspect.getdoc(cmd)
4852
if options is None:
@@ -58,26 +62,29 @@ def wrapper(cmd):
5862
"default_permission": default_permission,
5963
"api_permissions": permissions,
6064
"connector": connector,
61-
"has_subcommands": False
65+
"has_subcommands": False,
6266
}
6367
return CogBaseCommandObject(name or cmd.__name__, _cmd)
68+
6469
return wrapper
6570

6671

67-
def cog_subcommand(*,
68-
base,
69-
subcommand_group=None,
70-
name=None,
71-
description: str = None,
72-
base_description: str = None,
73-
base_desc: str = None,
74-
base_default_permission: bool = True,
75-
base_permissions: typing.Dict[int, list] = None,
76-
subcommand_group_description: str = None,
77-
sub_group_desc: str = None,
78-
guild_ids: typing.List[int] = None,
79-
options: typing.List[dict] = None,
80-
connector: dict = None):
72+
def cog_subcommand(
73+
*,
74+
base,
75+
subcommand_group=None,
76+
name=None,
77+
description: str = None,
78+
base_description: str = None,
79+
base_desc: str = None,
80+
base_default_permission: bool = True,
81+
base_permissions: typing.Dict[int, list] = None,
82+
subcommand_group_description: str = None,
83+
sub_group_desc: str = None,
84+
guild_ids: typing.List[int] = None,
85+
options: typing.List[dict] = None,
86+
connector: dict = None
87+
):
8188
"""
8289
Decorator for Cog to add subcommand.\n
8390
Almost same as :func:`.client.SlashCommand.subcommand`.
@@ -138,7 +145,7 @@ def wrapper(cmd):
138145
"default_permission": base_default_permission,
139146
"api_permissions": base_permissions,
140147
"connector": {},
141-
"has_subcommands": True
148+
"has_subcommands": True,
142149
}
143150

144151
_sub = {
@@ -149,7 +156,8 @@ def wrapper(cmd):
149156
"sub_group_desc": subcommand_group_description,
150157
"guild_ids": guild_ids,
151158
"api_options": opts,
152-
"connector": connector
159+
"connector": connector,
153160
}
154161
return CogSubcommandObject(base, _cmd, subcommand_group, name or cmd.__name__, _sub)
162+
155163
return wrapper

discord_slash/context.py

Lines changed: 81 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from discord.ext import commands
77
from discord.utils import snowflake_time
88

9-
from . import http
10-
from . import error
11-
from . import model
12-
from . dpy_overrides import ComponentMessage
9+
from . import error, http, model
10+
from .dpy_overrides import ComponentMessage
1311

1412

1513
class InteractionContext:
@@ -34,11 +32,13 @@ class InteractionContext:
3432
:ivar author: User or Member instance of the command invoke.
3533
"""
3634

37-
def __init__(self,
38-
_http: http.SlashCommandRequest,
39-
_json: dict,
40-
_discord: typing.Union[discord.Client, commands.Bot],
41-
logger):
35+
def __init__(
36+
self,
37+
_http: http.SlashCommandRequest,
38+
_json: dict,
39+
_discord: typing.Union[discord.Client, commands.Bot],
40+
logger,
41+
):
4242
self._token = _json["token"]
4343
self.message = None # Should be set later.
4444
self.interaction_id = _json["id"]
@@ -49,10 +49,14 @@ def __init__(self,
4949
self.responded = False
5050
self._deferred_hidden = False # To check if the patch to the deferred response matches
5151
self.guild_id = int(_json["guild_id"]) if "guild_id" in _json.keys() else None
52-
self.author_id = int(_json["member"]["user"]["id"] if "member" in _json.keys() else _json["user"]["id"])
52+
self.author_id = int(
53+
_json["member"]["user"]["id"] if "member" in _json.keys() else _json["user"]["id"]
54+
)
5355
self.channel_id = int(_json["channel_id"])
5456
if self.guild:
55-
self.author = discord.Member(data=_json["member"], state=self.bot._connection, guild=self.guild)
57+
self.author = discord.Member(
58+
data=_json["member"], state=self.bot._connection, guild=self.guild
59+
)
5660
elif self.guild_id:
5761
self.author = discord.User(data=_json["member"]["user"], state=self.bot._connection)
5862
else:
@@ -61,12 +65,20 @@ def __init__(self,
6165

6266
@property
6367
def _deffered_hidden(self):
64-
warn("`_deffered_hidden` as been renamed to `_deferred_hidden`.", DeprecationWarning, stacklevel=2)
68+
warn(
69+
"`_deffered_hidden` as been renamed to `_deferred_hidden`.",
70+
DeprecationWarning,
71+
stacklevel=2,
72+
)
6573
return self._deferred_hidden
6674

6775
@_deffered_hidden.setter
6876
def _deffered_hidden(self, value):
69-
warn("`_deffered_hidden` as been renamed to `_deferred_hidden`.", DeprecationWarning, stacklevel=2)
77+
warn(
78+
"`_deffered_hidden` as been renamed to `_deferred_hidden`.",
79+
DeprecationWarning,
80+
stacklevel=2,
81+
)
7082
self._deferred_hidden = value
7183

7284
@property
@@ -112,18 +124,20 @@ async def defer(self, hidden: bool = False):
112124
await self._http.post_initial_response(base, self.interaction_id, self._token)
113125
self.deferred = True
114126

115-
async def send(self,
116-
content: str = "", *,
117-
embed: discord.Embed = None,
118-
embeds: typing.List[discord.Embed] = None,
119-
tts: bool = False,
120-
file: discord.File = None,
121-
files: typing.List[discord.File] = None,
122-
allowed_mentions: discord.AllowedMentions = None,
123-
hidden: bool = False,
124-
delete_after: float = None,
125-
components: typing.List[dict] = None,
126-
) -> model.SlashMessage:
127+
async def send(
128+
self,
129+
content: str = "",
130+
*,
131+
embed: discord.Embed = None,
132+
embeds: typing.List[discord.Embed] = None,
133+
tts: bool = False,
134+
file: discord.File = None,
135+
files: typing.List[discord.File] = None,
136+
allowed_mentions: discord.AllowedMentions = None,
137+
hidden: bool = False,
138+
delete_after: float = None,
139+
components: typing.List[dict] = None,
140+
) -> model.SlashMessage:
127141
"""
128142
Sends response of the slash command.
129143
@@ -170,14 +184,19 @@ async def send(self,
170184
if delete_after and hidden:
171185
raise error.IncorrectFormat("You can't delete a hidden message!")
172186
if components and not all(comp.get("type") == 1 for comp in components):
173-
raise error.IncorrectFormat("The top level of the components list must be made of ActionRows!")
187+
raise error.IncorrectFormat(
188+
"The top level of the components list must be made of ActionRows!"
189+
)
174190

175191
base = {
176192
"content": content,
177193
"tts": tts,
178194
"embeds": [x.to_dict() for x in embeds] if embeds else [],
179-
"allowed_mentions": allowed_mentions.to_dict() if allowed_mentions
180-
else self.bot.allowed_mentions.to_dict() if self.bot.allowed_mentions else {},
195+
"allowed_mentions": allowed_mentions.to_dict()
196+
if allowed_mentions
197+
else self.bot.allowed_mentions.to_dict()
198+
if self.bot.allowed_mentions
199+
else {},
181200
"components": components or [],
182201
}
183202
if hidden:
@@ -197,10 +216,7 @@ async def send(self,
197216
resp = await self._http.edit(base, self._token, files=files)
198217
self.deferred = False
199218
else:
200-
json_data = {
201-
"type": 4,
202-
"data": base
203-
}
219+
json_data = {"type": 4, "data": base}
204220
await self._http.post_initial_response(json_data, self.interaction_id, self._token)
205221
if not hidden:
206222
resp = await self._http.edit({}, self._token)
@@ -213,11 +229,13 @@ async def send(self,
213229
for file in files:
214230
file.close()
215231
if not hidden:
216-
smsg = model.SlashMessage(state=self.bot._connection,
217-
data=resp,
218-
channel=self.channel or discord.Object(id=self.channel_id),
219-
_http=self._http,
220-
interaction_token=self._token)
232+
smsg = model.SlashMessage(
233+
state=self.bot._connection,
234+
data=resp,
235+
channel=self.channel or discord.Object(id=self.channel_id),
236+
_http=self._http,
237+
interaction_token=self._token,
238+
)
221239
if delete_after:
222240
self.bot.loop.create_task(smsg.delete(delay=delete_after))
223241
if initial_message:
@@ -238,11 +256,14 @@ class SlashContext(InteractionContext):
238256
:ivar subcommand_group: Subcommand group of the command.
239257
:ivar command_id: ID of the command.
240258
"""
241-
def __init__(self,
242-
_http: http.SlashCommandRequest,
243-
_json: dict,
244-
_discord: typing.Union[discord.Client, commands.Bot],
245-
logger):
259+
260+
def __init__(
261+
self,
262+
_http: http.SlashCommandRequest,
263+
_json: dict,
264+
_discord: typing.Union[discord.Client, commands.Bot],
265+
logger,
266+
):
246267
self.name = self.command = self.invoked_with = _json["data"]["name"]
247268
self.args = []
248269
self.kwargs = {}
@@ -262,20 +283,24 @@ class ComponentContext(InteractionContext):
262283
:ivar origin_message: The origin message of the component. Not available if the origin message was ephemeral.
263284
:ivar origin_message_id: The ID of the origin message.
264285
"""
265-
def __init__(self,
266-
_http: http.SlashCommandRequest,
267-
_json: dict,
268-
_discord: typing.Union[discord.Client, commands.Bot],
269-
logger):
286+
287+
def __init__(
288+
self,
289+
_http: http.SlashCommandRequest,
290+
_json: dict,
291+
_discord: typing.Union[discord.Client, commands.Bot],
292+
logger,
293+
):
270294
self.custom_id = self.component_id = _json["data"]["custom_id"]
271295
self.component_type = _json["data"]["component_type"]
272296
super().__init__(_http=_http, _json=_json, _discord=_discord, logger=logger)
273297
self.origin_message = None
274298
self.origin_message_id = int(_json["message"]["id"]) if "message" in _json.keys() else None
275299

276300
if self.origin_message_id and (_json["message"]["flags"] & 64) != 64:
277-
self.origin_message = ComponentMessage(state=self.bot._connection, channel=self.channel,
278-
data=_json["message"])
301+
self.origin_message = ComponentMessage(
302+
state=self.bot._connection, channel=self.channel, data=_json["message"]
303+
)
279304

280305
async def defer(self, hidden: bool = False, edit_origin: bool = False):
281306
"""
@@ -329,8 +354,13 @@ async def edit_origin(self, **fields):
329354
_resp["embeds"] = [x.to_dict() for x in embeds]
330355

331356
allowed_mentions = fields.get("allowed_mentions")
332-
_resp["allowed_mentions"] = allowed_mentions.to_dict() if allowed_mentions else \
333-
self.bot.allowed_mentions.to_dict() if self.bot.allowed_mentions else {}
357+
_resp["allowed_mentions"] = (
358+
allowed_mentions.to_dict()
359+
if allowed_mentions
360+
else self.bot.allowed_mentions.to_dict()
361+
if self.bot.allowed_mentions
362+
else {}
363+
)
334364

335365
if not self.responded:
336366
if files and not self.deferred:

0 commit comments

Comments
 (0)