mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-10 21:10:59 +00:00
refactor: 迁移旧的处理模块
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
# 指令模型
|
||||
import logging
|
||||
|
||||
commands = []
|
||||
"""已注册的指令类
|
||||
{
|
||||
"name": "指令名",
|
||||
"description": "指令描述",
|
||||
"usage": "指令用法",
|
||||
"aliases": ["别名1", "别名2"],
|
||||
"admin_only": "是否仅管理员可用",
|
||||
"func": "指令执行函数"
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def command(name: str, description: str, usage: str, aliases: list = None, admin_only: bool = False):
|
||||
"""指令装饰器"""
|
||||
|
||||
def wrapper(fun):
|
||||
commands.append({
|
||||
"name": name,
|
||||
"description": description,
|
||||
"usage": usage,
|
||||
"aliases": aliases,
|
||||
"admin_only": admin_only,
|
||||
"func": fun
|
||||
})
|
||||
return fun
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def search(cmd: str) -> dict:
|
||||
"""查找指令"""
|
||||
for command in commands:
|
||||
if (command["name"] == cmd) or (cmd in command["aliases"]):
|
||||
return command
|
||||
return None
|
||||
|
||||
|
||||
import pkg.qqbot.cmds.func
|
||||
import pkg.qqbot.cmds.system
|
||||
import pkg.qqbot.cmds.session
|
||||
import pkg.qqbot.cmds.plugin
|
||||
Reference in New Issue
Block a user