66from discord .ext import commands
77from 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
1513class 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