Update cog_ext.py
Support for cogs
import typing
+import inspect
from .model import CogCommandObject, CogSubcommandObject, SlashCommandOptionType
+from .utils import manage_commands
def cog_slash(*,
@@ -51,12 +53,18 @@ def cog_slash(*,
auto_convert[x["name"]] = x["type"]
def wrapper(cmd):
+ desc = description or inspect.getdoc(cmd) or "No description"
+ if options is None:
+ opts = manage_commands.create_options_from_args(cmd, desc)
+ else:
+ opts = options
+
_cmd = {
"func": cmd,
- "description": description if description else "No description.",
+ "description": desc,
"auto_convert": auto_convert,
"guild_ids": guild_ids,
- "api_options": options if options else [],
+ "api_options": opts,
"has_subcommands": False
}
return CogCommandObject(cmd.__name__ if not name else name, _cmd)
@@ -127,19 +135,25 @@ def cog_subcommand(*,
raise Exception("You can't use subcommand or subcommand_group type!")
auto_convert[x["name"]] = x["type"]
- base_description = base_description if base_description else base_desc
- subcommand_group_description = subcommand_group_description if subcommand_group_description else sub_group_desc
+ base_description = base_description or base_desc
+ subcommand_group_description = subcommand_group_description or sub_group_desc
def wrapper(cmd):
+ desc = description or inspect.getdoc(cmd) or "No description"
+ if options is None:
+ opts = manage_commands.create_options_from_args(cmd, desc)
+ else:
+ opts = options
+
_sub = {
"func": cmd,
"name": cmd.__name__ if not name else name,
- "description": description if description else "No Description.",
- "base_desc": base_description if base_description else "No Description.",
- "sub_group_desc": subcommand_group_description if subcommand_group_description else "No Description.",
+ "description": desc,
+ "base_desc": base_description or "No Description.",
+ "sub_group_desc": subcommand_group_description or "No Description.",
"auto_convert": auto_convert,
"guild_ids": guild_ids,
- "api_options": options if options else []
+ "api_options": opts
}
- return CogSubcommandObject(_sub, base, cmd.__name__ if not name else name, subcommand_group)
+ return CogSubcommandObject(_sub, base, name or cmd.__name__, subcommand_group)
return wrapper
