|
8 | 8 |
|
9 | 9 | import functools |
10 | 10 | import inspect |
11 | | -from typing import Any, Callable, Coroutine, Optional |
| 11 | +from typing import Any, Callable, Coroutine, Optional, TypeVar, Union |
12 | 12 |
|
13 | 13 | import discord |
14 | 14 | from discord.ext import commands |
| 15 | +from discord import app_commands |
| 16 | + |
15 | 17 | from snakecore.commands.parser import parse_command_str |
| 18 | +from ._types import AnyCommandType |
16 | 19 |
|
17 | 20 |
|
18 | 21 | def kwarg_command( |
@@ -153,7 +156,7 @@ async def kwarg_command_wrapper( |
153 | 156 |
|
154 | 157 | def custom_parsing( |
155 | 158 | *, inside_class: bool = False, inject_message_reference: bool = False |
156 | | -): |
| 159 | +) -> Callable[[Callable[..., Coroutine[Any, Any, Any]]], Any]: |
157 | 160 | """A decorator that registers a `discord.ext.commands` command function to |
158 | 161 | use snakecore's custom argument parser. This returns a wrapper function that |
159 | 162 | bypasses `discord.ext.commands` parsing system, parses the input string from |
@@ -237,3 +240,18 @@ async def cmd_func_wrapper( |
237 | 240 | return cmd_func_wrapper |
238 | 241 |
|
239 | 242 | return custom_parsing_inner_deco |
| 243 | + |
| 244 | + |
| 245 | +def with_extras(**extras: Any) -> AnyCommandType: |
| 246 | + """A convenience decorator for adding data into the `extras` |
| 247 | + attribute of a command object. |
| 248 | +
|
| 249 | + Args: |
| 250 | + **extras: The extras. |
| 251 | + """ |
| 252 | + |
| 253 | + def inner_with_extras(cmd: AnyCommandType) -> AnyCommandType: |
| 254 | + cmd.extras.update(extras) |
| 255 | + return cmd |
| 256 | + |
| 257 | + return inner_with_extras |
0 commit comments