|
30 | 30 | from typing import Callable, Dict, List, Optional, Union
|
31 | 31 |
|
32 | 32 | from ..enums import SlashCommandOptionType
|
33 |
| -from ..interactions import Interaction |
34 | 33 | from ..member import Member
|
35 | 34 | from ..user import User
|
36 | 35 | from ..message import Message
|
@@ -138,12 +137,10 @@ def __eq__(self, other) -> bool:
|
138 | 137 | and other.description == self.description
|
139 | 138 | )
|
140 | 139 |
|
141 |
| - async def invoke(self, interaction) -> None: |
| 140 | + async def invoke(self, ctx: InteractionContext) -> None: |
142 | 141 | # TODO: Parse the args better, apply custom converters etc.
|
143 |
| - ctx = InteractionContext(interaction) |
144 |
| - |
145 | 142 | kwargs = {}
|
146 |
| - for arg in interaction.data.get("options", []): |
| 143 | + for arg in ctx.interaction.data.get("options", []): |
147 | 144 | op = find(lambda x: x.name == arg["name"], self.options)
|
148 | 145 | arg = arg["value"]
|
149 | 146 |
|
@@ -257,11 +254,11 @@ def command_group(self, name, description) -> SubCommandGroup:
|
257 | 254 | self.subcommands.append(sub_command_group)
|
258 | 255 | return sub_command_group
|
259 | 256 |
|
260 |
| - async def invoke(self, interaction: Interaction) -> None: |
261 |
| - option = interaction.data["options"][0] |
| 257 | + async def invoke(self, ctx: InteractionContext) -> None: |
| 258 | + option = ctx.interaction.data["options"][0] |
262 | 259 | command = find(lambda x: x.name == option["name"], self.subcommands)
|
263 |
| - interaction.data = option |
264 |
| - await command.invoke(interaction) |
| 260 | + ctx.interaction.data = option |
| 261 | + await command.invoke(ctx) |
265 | 262 |
|
266 | 263 |
|
267 | 264 | class UserCommand(ApplicationCommand):
|
@@ -290,29 +287,28 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
|
290 | 287 | def to_dict(self) -> Dict[str, Union[str, int]]:
|
291 | 288 | return {"name": self.name, "description": self.description, "type": self.type}
|
292 | 289 |
|
293 |
| - async def invoke(self, interaction: Interaction) -> None: |
294 |
| - if "members" not in interaction.data["resolved"]: |
295 |
| - _data = interaction.data["resolved"]["users"] |
| 290 | + async def invoke(self, ctx: InteractionContext) -> None: |
| 291 | + if "members" not in ctx.interaction.data["resolved"]: |
| 292 | + _data = ctx.interaction.data["resolved"]["users"] |
296 | 293 | for i, v in _data.items():
|
297 | 294 | v["id"] = int(i)
|
298 | 295 | user = v
|
299 |
| - target = User(state=interaction._state, data=user) |
| 296 | + target = User(state=ctx.interaction._state, data=user) |
300 | 297 | else:
|
301 |
| - _data = interaction.data["resolved"]["members"] |
| 298 | + _data = ctx.interaction.data["resolved"]["members"] |
302 | 299 | for i, v in _data.items():
|
303 | 300 | v["id"] = int(i)
|
304 | 301 | member = v
|
305 |
| - _data = interaction.data["resolved"]["users"] |
| 302 | + _data = ctx.interaction.data["resolved"]["users"] |
306 | 303 | for i, v in _data.items():
|
307 | 304 | v["id"] = int(i)
|
308 | 305 | user = v
|
309 | 306 | member["user"] = user
|
310 | 307 | target = Member(
|
311 | 308 | data=member,
|
312 |
| - guild=interaction._state._get_guild(interaction.guild_id), |
313 |
| - state=interaction._state, |
| 309 | + guild=ctx.interaction._state._get_guild(ctx.interaction.guild_id), |
| 310 | + state=ctx.interaction._state, |
314 | 311 | )
|
315 |
| - ctx = InteractionContext(interaction) |
316 | 312 | await self.callback(ctx, target)
|
317 | 313 |
|
318 | 314 |
|
@@ -340,18 +336,17 @@ def __init__(self, func, *args, **kwargs):
|
340 | 336 | def to_dict(self):
|
341 | 337 | return {"name": self.name, "description": self.description, "type": self.type}
|
342 | 338 |
|
343 |
| - async def invoke(self, interaction): |
344 |
| - _data = interaction.data["resolved"]["messages"] |
| 339 | + async def invoke(self, ctx: InteractionContext): |
| 340 | + _data = ctx.interaction.data["resolved"]["messages"] |
345 | 341 | for i, v in _data.items():
|
346 | 342 | v["id"] = int(i)
|
347 | 343 | message = v
|
348 |
| - channel = interaction._state.get_channel(int(message["channel_id"])) |
| 344 | + channel = ctx.interaction._state.get_channel(int(message["channel_id"])) |
349 | 345 | if channel is None:
|
350 |
| - data = await interaction._state.http.start_private_message( |
| 346 | + data = await ctx.interaction._state.http.start_private_message( |
351 | 347 | int(message["author"]["id"])
|
352 | 348 | )
|
353 |
| - channel = interaction._state.add_dm_channel(data) |
| 349 | + channel = ctx.interaction._state.add_dm_channel(data) |
354 | 350 |
|
355 |
| - target = Message(state=interaction._state, channel=channel, data=message) |
356 |
| - ctx = InteractionContext(interaction) |
| 351 | + target = Message(state=ctx.interaction._state, channel=channel, data=message) |
357 | 352 | await self.callback(ctx, target)
|
0 commit comments