Skip to content

Commit 25060e1

Browse files
committed
update requirements.txt, add new command decorators, update utils.py
1 parent 69017ed commit 25060e1

File tree

8 files changed

+170
-62
lines changed

8 files changed

+170
-62
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
black>=22.1
2-
discord.py @ git+https://github.com/Rapptz/discord.py.git@master#egg=discord.py-2.0.0
2+
discord.py>=2.0.0
33
python-dotenv>=0.19

snakecore/commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from snakecore import config
1313
from . import converters, decorators, parser
14-
from .bot import AutoShardedBot, Bot
14+
from .bot import *
1515

1616

1717
def init(global_client: Optional[discord.Client] = None):

snakecore/commands/_types.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import TypeVar
2+
3+
from discord import app_commands
4+
from discord.ext import commands
5+
6+
7+
AnyCommandType = TypeVar(
8+
"AnyCommandType",
9+
commands.Command,
10+
commands.Group,
11+
commands.HybridCommand,
12+
commands.HybridGroup,
13+
app_commands.Command,
14+
app_commands.Group,
15+
)

snakecore/commands/bot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from discord.ext.commands import errors
1616

1717
__all__ = (
18+
"ExtBot",
19+
"ExtAutoShardedBot",
1820
"Bot",
1921
"AutoShardedBot",
2022
)

snakecore/commands/decorators.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
import functools
1010
import inspect
11-
from typing import Any, Callable, Coroutine, Optional
11+
from typing import Any, Callable, Coroutine, Optional, TypeVar, Union
1212

1313
import discord
1414
from discord.ext import commands
15+
from discord import app_commands
16+
1517
from snakecore.commands.parser import parse_command_str
18+
from ._types import AnyCommandType
1619

1720

1821
def kwarg_command(
@@ -153,7 +156,7 @@ async def kwarg_command_wrapper(
153156

154157
def custom_parsing(
155158
*, inside_class: bool = False, inject_message_reference: bool = False
156-
):
159+
) -> Callable[[Callable[..., Coroutine[Any, Any, Any]]], Any]:
157160
"""A decorator that registers a `discord.ext.commands` command function to
158161
use snakecore's custom argument parser. This returns a wrapper function that
159162
bypasses `discord.ext.commands` parsing system, parses the input string from
@@ -237,3 +240,18 @@ async def cmd_func_wrapper(
237240
return cmd_func_wrapper
238241

239242
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

snakecore/utils/embed_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import black
1616
import discord
1717

18-
from .utils import recursive_dict_update
18+
from .utils import recursive_mapping_update
1919

2020

2121
EMBED_TOP_LEVEL_ATTRIBUTES_MASK_DICT = {
@@ -1355,7 +1355,7 @@ def edit_embed(
13551355
for i in range(len(update_embed_dict["fields"]))
13561356
}
13571357

1358-
recursive_dict_update(old_embed_dict, update_embed_dict, add_new_keys=True)
1358+
recursive_mapping_update(old_embed_dict, update_embed_dict, add_new_keys=True)
13591359

13601360
if edit_inner_fields:
13611361
if "fields" in old_embed_dict:
@@ -2035,7 +2035,7 @@ def edit_embed_dict_from_dict(
20352035
for i in range(len(update_embed_dict["fields"]))
20362036
}
20372037

2038-
recursive_dict_update(
2038+
recursive_mapping_update(
20392039
old_embed_dict, update_embed_dict, add_new_keys=add_attributes
20402040
)
20412041

snakecore/utils/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from snakecore import config
1515
from snakecore.constants import NoneType
1616
from snakecore.exceptions import DeserializationError
17-
from snakecore.utils import recursive_dict_compare
17+
from snakecore.utils import recursive_mapping_compare
1818

1919
_DISCORD_MODEL_SERIAL_MAP = {}
2020

@@ -47,7 +47,7 @@ def __setstate__(self, state):
4747
@classmethod
4848
def is_valid_data(cls, data: dict):
4949
if cls.DATA_FORMAT:
50-
return recursive_dict_compare(
50+
return recursive_mapping_compare(
5151
data,
5252
cls.DATA_FORMAT,
5353
compare_func=lambda src, target: isinstance(src, target),

0 commit comments

Comments
 (0)