From 0e786660b4e26812a4f0324c9563fe2693cfe336 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Tue, 17 Jan 2023 11:01:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=AD=E6=96=87=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plugin_examples/cmdcn/__init__.py | 0 tests/plugin_examples/cmdcn/cmdcn.py | 46 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/plugin_examples/cmdcn/__init__.py create mode 100644 tests/plugin_examples/cmdcn/cmdcn.py diff --git a/tests/plugin_examples/cmdcn/__init__.py b/tests/plugin_examples/cmdcn/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/plugin_examples/cmdcn/cmdcn.py b/tests/plugin_examples/cmdcn/cmdcn.py new file mode 100644 index 00000000..e92519d3 --- /dev/null +++ b/tests/plugin_examples/cmdcn/cmdcn.py @@ -0,0 +1,46 @@ +from pkg.plugin.models import * +from pkg.plugin.host import EventContext + +__mapping__ = { + "帮助": "help", + "重置": "reset", + "前一次": "last", + "后一次": "next", + "会话内容": "prompt", + "列出会话": "list", + "重新回答": "resend", + "使用量": "usage", + "绘画": "draw", + "版本": "version", + "热重载": "reload", + "热更新": "update", + "配置": "cfg", +} + + +@register(name="CmdCN", description="命令中文支持", version="0.1", author="RockChinQ") +class CmdCnPlugin(Plugin): + + def __init__(self): + pass + + # 私聊发送指令 + @on(PersonCommandSent) + def person_command_sent(self, event: EventContext, **kwargs): + cmd = kwargs['command'] + if cmd in __mapping__: + + # 返回替换后的指令 + event.add_return("alter", "!"+__mapping__[cmd]+" "+" ".join(kwargs['params'])) + + # 群聊发送指令 + @on(GroupCommandSent) + def group_command_sent(self, event: EventContext, **kwargs): + cmd = kwargs['command'] + if cmd in __mapping__: + + # 返回替换后的指令 + event.add_return("alter", "!"+__mapping__[cmd]+" "+" ".join(kwargs['params'])) + + def __del__(self): + pass