From d08794579ca6abe35a09ddbfa6b28aa8cbc8ffb4 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sun, 19 Mar 2023 14:33:01 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=B0=E6=9C=89=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/cmds/func.py | 14 +++++ pkg/qqbot/cmds/model.py | 38 +++++++---- pkg/qqbot/cmds/session.py | 128 ++++++++++++++++++++++++++++++++++++++ pkg/qqbot/cmds/system.py | 98 +++++++++++++++++++++++++++++ 4 files changed, 265 insertions(+), 13 deletions(-) create mode 100644 pkg/qqbot/cmds/func.py create mode 100644 pkg/qqbot/cmds/session.py create mode 100644 pkg/qqbot/cmds/system.py diff --git a/pkg/qqbot/cmds/func.py b/pkg/qqbot/cmds/func.py new file mode 100644 index 00000000..4a53c1ba --- /dev/null +++ b/pkg/qqbot/cmds/func.py @@ -0,0 +1,14 @@ +from pkg.qqbot.cmds.model import command + +@command( + "draw", + "使用DALL·E模型作画", + "!draw <图片提示语>", + [], + False +) +def cmd_draw(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """使用DALL·E模型作画""" + pass \ No newline at end of file diff --git a/pkg/qqbot/cmds/model.py b/pkg/qqbot/cmds/model.py index 74c21542..cc5d6ef3 100644 --- a/pkg/qqbot/cmds/model.py +++ b/pkg/qqbot/cmds/model.py @@ -1,18 +1,30 @@ # 指令模型 -commands = {} -"""已注册的指令类""" +commands = [] +"""已注册的指令类 +{ + "name": "指令名", + "description": "指令描述", + "usage": "指令用法", + "aliases": ["别名1", "别名2"], + "admin_only": "是否仅管理员可用", + "func": "指令执行函数" +} +""" -class AbsCommand: - """指令抽象类""" - @staticmethod - def execute(cls, cmd: str, params: list, session_name: str, text_message: str, launcher_type: str, launcher_id: int, - sender_id: int, is_admin: bool) -> list: - raise NotImplementedError +def command(name: str, description: str, usage: str, aliases: list = None, admin_only: bool = False): + """指令装饰器""" - -def register(cls: type): - """注册指令类""" - commands[cls.name] = cls - return cls + def wrapper(fun: function): + commands.append({ + "name": name, + "description": description, + "usage": usage, + "aliases": aliases, + "admin_only": admin_only, + "func": fun + }) + return fun + + return wrapper diff --git a/pkg/qqbot/cmds/session.py b/pkg/qqbot/cmds/session.py new file mode 100644 index 00000000..a2a87fdb --- /dev/null +++ b/pkg/qqbot/cmds/session.py @@ -0,0 +1,128 @@ +# 会话管理相关指令 +from pkg.qqbot.cmds.model import command + + +@command( + "reset", + "重置当前会话", + "!reset\n!reset [使用情景预设名称]", + [], + False +) +def cmd_reset(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """重置会话""" + pass + + +@command( + "last", + "切换到前一次会话", + "!last", + [], + False +) +def cmd_last(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """切换到前一次会话""" + pass + + +@command( + "next", + "切换到后一次会话", + "!next", + [], + False +) +def cmd_next(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: int, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """切换到后一次会话""" + pass + + +@command( + "prompt", + "获取当前会话的前文", + "!prompt", + [], + False +) +def cmd_prompt(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """获取当前会话的前文""" + pass + + +@command( + "list", + "列出当前会话的所有历史记录", + "!list\n!list [页数]", + [], + False +) +def cmd_list(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """列出当前会话的所有历史记录""" + pass + + +@command( + "resend" + "重新获取上一次问题的回复", + "!resend", + [], + False +) +def cmd_resend(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """重新获取上一次问题的回复""" + pass + + +@command( + "del", + "删除当前会话的历史记录", + "!del <序号>\n!del all", + [], + False +) +def cmd_del(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """删除当前会话的历史记录""" + pass + + +@command( + "default", + "操作情景预设", + "!default\n!default [指定情景预设为默认]", + [], + False +) +def cmd_default(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """操作情景预设""" + pass + + +@command( + "delhst", + "删除指定会话的所有历史记录", + "!delhst <会话名称>\n!delhst all", + [], + True +) +def cmd_delhst(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """删除指定会话的所有历史记录""" + pass diff --git a/pkg/qqbot/cmds/system.py b/pkg/qqbot/cmds/system.py new file mode 100644 index 00000000..d4a42749 --- /dev/null +++ b/pkg/qqbot/cmds/system.py @@ -0,0 +1,98 @@ +from pkg.qqbot.cmds.model import command + +@command( + "help", + "获取帮助信息", + "!help", + [], + False +) +def cmd_help(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """获取帮助信息""" + pass + + +@command( + "usage", + "获取使用情况", + "!usage", + [], + False +) +def cmd_usage(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """获取使用情况""" + pass + + +@command( + "version", + "查看版本信息", + "!version", + [], + False +) +def cmd_version(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """查看版本信息""" + pass + + +@command( + "plugin", + "插件相关操作", + "!plugin\n!plugin <插件仓库地址>", + [], + False +) +def cmd_plugin(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """插件相关操作""" + pass + + +@command( + "reload", + "执行热重载", + "!reload", + [], + True +) +def cmd_reload(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """执行热重载""" + pass + + +@command( + "update", + "更新程序", + "!update", + [], + True +) +def cmd_update(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """更新程序""" + pass + + +@command( + "cfg", + "配置文件相关操作", + "!cfg all\n!cfg <配置项名称>\n!cfg <配置项名称> <配置项新值>", + [], + True +) +def cmd_cfg(cmd: str, params: list, session_name: str, + text_message: str, launcher_type: str, launcher_id: int, + sender_id: int, is_admin: bool) -> list: + """配置文件相关操作""" + pass