Skip to content

Commit 9058cbe

Browse files
committed
Refactored some code
1 parent 6eb2461 commit 9058cbe

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

discord_slash/context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self,
4444
_discord: typing.Union[discord.Client, commands.Bot],
4545
logger):
4646
self.__token = _json["token"]
47-
self.message = None # Should be set later.
47+
self.message = None # Should be set later.
4848
self.name = self.command = self.invoked_with = _json["data"]["name"]
4949
self.args = []
5050
self.kwargs = {}
@@ -198,10 +198,10 @@ async def send(self,
198198
if self.deferred:
199199
if self._deferred_hidden != hidden:
200200
self._logger.warning(
201-
"deferred response might not be what you set it to! (hidden / visible) "
202-
"This is because it was deferred in a different state"
201+
"Deferred response might not be what you set it to! (hidden / visible) "
202+
"This is because it was deferred in a different state."
203203
)
204-
resp = await self._http.edit(base, self.__token, files = files)
204+
resp = await self._http.edit(base, self.__token, files=files)
205205
self.deferred = False
206206
else:
207207
json_data = {

discord_slash/http.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ def edit(self, _resp, token, message_id="@original", files: typing.List[discord.
157157
return self.request_with_files(_resp, files, token, "PATCH", url_ending = req_url)
158158
return self.command_response(token, True, "PATCH", url_ending = req_url, json=_resp)
159159

160-
161160
def delete(self, token, message_id="@original"):
162161
"""
163162
Sends delete command response POST request to Discord API.

discord_slash/model.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from . import http
77
from . import error
88

9+
910
class ChoiceData:
1011
"""
1112
Command choice data object
1213
1314
:ivar name: Name of the choice, this is what the user will see
1415
:ivar value: Values of the choice, this is what discord will return to you
1516
"""
17+
1618
def __init__(self, name, value):
1719
self.name = name
1820
self.value = value
@@ -31,8 +33,9 @@ class OptionData:
3133
:ivar choices: A list of :class:`ChoiceData`, cannot be present on subcommand groups
3234
:ivar options: List of :class:`OptionData`, this will be present if it's a subcommand group
3335
"""
36+
3437
def __init__(
35-
self, name, description, required=False, choices=None, options=None, **kwargs
38+
self, name, description, required=False, choices=None, options=None, **kwargs
3639
):
3740
self.name = name
3841
self.description = description
@@ -72,7 +75,7 @@ class CommandData:
7275
"""
7376

7477
def __init__(
75-
self, name, description, options = [], id=None, application_id = None, version = None, **kwargs
78+
self, name, description, options=None, id=None, application_id=None, version=None, **kwargs
7679
):
7780
self.name = name
7881
self.description = description
@@ -89,9 +92,9 @@ def __init__(
8992
def __eq__(self, other):
9093
if isinstance(other, CommandData):
9194
return (
92-
self.name == other.name
93-
and self.description == other.description
94-
and self.options == other.options
95+
self.name == other.name
96+
and self.description == other.description
97+
and self.options == other.options
9598
)
9699
else:
97100
return False
@@ -112,6 +115,7 @@ class CommandObject:
112115
:ivar connector: Kwargs connector of the command.
113116
:ivar __commands_checks__: Check of the command.
114117
"""
118+
115119
def __init__(self, name, cmd): # Let's reuse old command formatting.
116120
self.name = name.lower()
117121
self.func = cmd["func"]
@@ -187,8 +191,9 @@ class SubcommandObject(CommandObject):
187191
:ivar base_description: Description of the base command.
188192
:ivar subcommand_group_description: Description of the subcommand_group.
189193
"""
194+
190195
def __init__(self, sub, base, name, sub_group=None):
191-
sub["has_subcommands"] = True # For the inherited class.
196+
sub["has_subcommands"] = True # For the inherited class.
192197
super().__init__(name, sub)
193198
self.base = base.lower()
194199
self.subcommand_group = sub_group.lower() if sub_group else sub_group
@@ -203,6 +208,7 @@ class CogCommandObject(CommandObject):
203208
.. warning::
204209
Do not manually init this model.
205210
"""
211+
206212
def __init__(self, *args):
207213
super().__init__(*args)
208214
self.cog = None # Manually set this later.
@@ -228,6 +234,7 @@ class CogSubcommandObject(SubcommandObject):
228234
.. warning::
229235
Do not manually init this model.
230236
"""
237+
231238
def __init__(self, *args):
232239
super().__init__(*args)
233240
self.cog = None # Manually set this later.
@@ -278,6 +285,7 @@ def from_type(cls, t: type):
278285

279286
class SlashMessage(discord.Message):
280287
"""discord.py's :class:`discord.Message` but overridden ``edit`` and ``delete`` to work for slash command."""
288+
281289
def __init__(self, *, state, channel, data, _http: http.SlashCommandRequest, interaction_token):
282290
# Yes I know it isn't the best way but this makes implementation simple.
283291
super().__init__(state=state, channel=channel, data=data)
@@ -318,15 +326,13 @@ async def _slash_edit(self, **fields):
318326
_resp["allowed_mentions"] = allowed_mentions.to_dict() if allowed_mentions else \
319327
self._state.allowed_mentions.to_dict() if self._state.allowed_mentions else {}
320328

321-
await self._http.edit(_resp, self.__interaction_token, self.id, files = files)
329+
await self._http.edit(_resp, self.__interaction_token, self.id, files=files)
322330

323331
delete_after = fields.get("delete_after")
324332
if delete_after:
325333
await self.delete(delay=delete_after)
326334
if files:
327-
for file in files:
328-
file.close()
329-
335+
[x.close() for x in files]
330336

331337
async def edit(self, **fields):
332338
"""Refer :meth:`discord.Message.edit`."""
@@ -350,4 +356,5 @@ async def wrap():
350356
with suppress(discord.HTTPException):
351357
await asyncio.sleep(delay)
352358
await self._http.delete(self.__interaction_token, self.id)
359+
353360
self._state.loop.create_task(wrap())

0 commit comments

Comments
 (0)