From e5485cddd019e115ecd4758b2a7dbff963538eb1 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 3 Apr 2023 14:40:27 +0000 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E6=9B=B4=E6=94=B9=E4=BD=BF?= =?UTF-8?q?=E7=94=A8!cmd=E6=8C=87=E4=BB=A4=E6=9F=A5=E7=9C=8B=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/cmds/system/cmd.py | 39 +++++++++++++++++++++++++++++++++++ pkg/qqbot/cmds/system/cmds.py | 39 +++++++++++++++++++++++++++++++++++ pkg/qqbot/cmds/system/help.py | 33 +++++++---------------------- 3 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 pkg/qqbot/cmds/system/cmd.py create mode 100644 pkg/qqbot/cmds/system/cmds.py diff --git a/pkg/qqbot/cmds/system/cmd.py b/pkg/qqbot/cmds/system/cmd.py new file mode 100644 index 00000000..431d8628 --- /dev/null +++ b/pkg/qqbot/cmds/system/cmd.py @@ -0,0 +1,39 @@ +from ..mgr import AbstractCommandNode, Context, __command_list__ + + +@AbstractCommandNode.register( + parent=None, + name="cmd", + description="显示指令列表", + usage="!cmd\n!cmd <指令名称>", + aliases=[], + privilege=1 +) +class CmdCommand(AbstractCommandNode): + @classmethod + def process(cls, ctx: Context) -> tuple[bool, list]: + command_list = __command_list__ + + reply = [] + + if len(ctx.params) == 0: + reply_str = "[bot]当前所有指令:\n\n" + + # 遍历顶级指令 + for key in command_list: + command = command_list[key] + if command['parent'] is None: + reply_str += "!{} - {}\n".format(key, command['description']) + + reply_str += "\n请使用 !cmd <指令名称> 来查看指令的详细信息" + + reply = [reply_str] + else: + command_name = ctx.params[0] + if command_name in command_list: + reply = [command_list[command_name]['cls'].help()] + else: + reply = ["[bot]指令 {} 不存在".format(command_name)] + + return True, reply + \ No newline at end of file diff --git a/pkg/qqbot/cmds/system/cmds.py b/pkg/qqbot/cmds/system/cmds.py new file mode 100644 index 00000000..96da5631 --- /dev/null +++ b/pkg/qqbot/cmds/system/cmds.py @@ -0,0 +1,39 @@ +from ..mgr import AbstractCommandNode, Context, __command_list__ + + +@AbstractCommandNode.register( + parent=None, + name="cmd", + description="显示指令列表", + usage="!help\n!help <指令名称>", + aliases=[], + privilege=1 +) +class CmdCommand(AbstractCommandNode): + @classmethod + def process(cls, ctx: Context) -> tuple[bool, list]: + command_list = __command_list__ + + reply = [] + + if len(ctx.params) == 0: + reply_str = "[bot]当前所有指令:\n\n" + + # 遍历顶级指令 + for key in command_list: + command = command_list[key] + if command['parent'] is None: + reply_str += "!{} - {}\n".format(key, command['description']) + + reply_str += "\n请使用 !cmd <指令名称> 来查看指令的详细信息" + + reply = [reply_str] + else: + command_name = ctx.params[0] + if command_name in command_list: + reply = [command_list[command_name]['cls'].help()] + else: + reply = ["[bot]指令 {} 不存在".format(command_name)] + + return True, reply + \ No newline at end of file diff --git a/pkg/qqbot/cmds/system/help.py b/pkg/qqbot/cmds/system/help.py index 08c50b88..427a5537 100644 --- a/pkg/qqbot/cmds/system/help.py +++ b/pkg/qqbot/cmds/system/help.py @@ -1,38 +1,19 @@ -from ..mgr import AbstractCommandNode, Context, __command_list__ +from ..mgr import AbstractCommandNode, Context @AbstractCommandNode.register( parent=None, name="help", - description="显示帮助信息", - usage="!help\n!help <指令名称>", + description="显示自定义的帮助信息", + usage="!help", aliases=[], privilege=1 ) class HelpCommand(AbstractCommandNode): @classmethod def process(cls, ctx: Context) -> tuple[bool, list]: - command_list = __command_list__ + import config + reply = [(config.help_message if hasattr(config, 'help_message') else "") + "\n请输入 !cmds 查看指令列表"] - reply = [] - - if len(ctx.params) == 0: - reply_str = "[bot]当前所有指令:\n\n" - - # 遍历顶级指令 - for key in command_list: - command = command_list[key] - if command['parent'] is None: - reply_str += "!{} - {}\n".format(key, command['description']) - - reply_str += "\n请使用 !help <指令名称> 来查看指令的详细信息" - - reply = [reply_str] - else: - command_name = ctx.params[0] - if command_name in command_list: - reply = [command_list[command_name]['cls'].help()] - else: - reply = ["[bot]指令 {} 不存在".format(command_name)] - - return True, reply \ No newline at end of file + return True, reply + \ No newline at end of file From b6ee3939be0eba8adf1dea01353b7c6349e07dae Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Mon, 3 Apr 2023 14:41:25 +0000 Subject: [PATCH 2/4] Update cmdpriv-template.json --- cmdpriv-template.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cmdpriv-template.json b/cmdpriv-template.json index a5b4a6e7..0af32a92 100644 --- a/cmdpriv-template.json +++ b/cmdpriv-template.json @@ -19,6 +19,7 @@ "prompt": 1, "resend": 1, "reset": 1, + "cmd": 1, "help": 1, "reload": 2, "update": 2, From c9b25fe806a7e82bcc774608c8b3608a68d3ecd2 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 3 Apr 2023 14:55:01 +0000 Subject: [PATCH 3/4] =?UTF-8?q?doc:=20cmds=E6=8C=87=E4=BB=A4=E7=9A=84?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QChatGPT.wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QChatGPT.wiki b/QChatGPT.wiki index 1e3c599c..d0dd0c1a 160000 --- a/QChatGPT.wiki +++ b/QChatGPT.wiki @@ -1 +1 @@ -Subproject commit 1e3c599c0313acb6b1511087c0e579ee8b22dd2c +Subproject commit d0dd0c1ad3ac8635f39982099fae21bdf569ee22 From 9edb32b081d98c42e340e43585874574f4131331 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Tue, 4 Apr 2023 03:15:07 +0000 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20usage=E5=91=BD=E4=BB=A4=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E6=98=BE=E7=A4=BA=E9=A2=9D=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/cmds/system/usage.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pkg/qqbot/cmds/system/usage.py b/pkg/qqbot/cmds/system/usage.py index c1584b2d..9714eeca 100644 --- a/pkg/qqbot/cmds/system/usage.py +++ b/pkg/qqbot/cmds/system/usage.py @@ -29,13 +29,6 @@ class UsageCommand(AbstractCommandNode): .get_image_count_of_key(api_keys[key_name]) reply_str += "{}:\n - 文本长度:{}\n - 图片数量:{}\n".format(key_name, int(text_length), int(image_count)) - # 获取此key的额度 - try: - http_proxy = config.openai_config["http_proxy"] if "http_proxy" in config.openai_config else None - credit_data = credit.fetch_credit_data(api_keys[key_name], http_proxy) - reply_str += " - 使用额度:{:.2f}/{:.2f}\n".format(credit_data['total_used'],credit_data['total_granted']) - except Exception as e: - logging.warning("获取额度失败:{}".format(e)) reply = [reply_str]