mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 03:32:33 +08:00
feat: 中文指令插件示例
This commit is contained in:
parent
6af55d8a1d
commit
0e786660b4
0
tests/plugin_examples/cmdcn/__init__.py
Normal file
0
tests/plugin_examples/cmdcn/__init__.py
Normal file
46
tests/plugin_examples/cmdcn/cmdcn.py
Normal file
46
tests/plugin_examples/cmdcn/cmdcn.py
Normal 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
|
Loading…
Reference in New Issue
Block a user