feat: 中文指令插件示例

This commit is contained in:
Rock Chin 2023-01-17 11:01:41 +08:00
parent 6af55d8a1d
commit 0e786660b4
2 changed files with 46 additions and 0 deletions

View File

View File

@ -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