2023-01-14 20:34:33 +08:00
|
|
|
|
# 指令处理模块
|
|
|
|
|
import logging
|
|
|
|
|
import json
|
|
|
|
|
import datetime
|
2023-01-17 12:30:45 +08:00
|
|
|
|
import os
|
2023-01-14 20:34:33 +08:00
|
|
|
|
import threading
|
2023-03-12 22:43:02 +08:00
|
|
|
|
import traceback
|
2023-01-14 20:34:33 +08:00
|
|
|
|
|
|
|
|
|
import pkg.openai.session
|
|
|
|
|
import pkg.openai.manager
|
|
|
|
|
import pkg.utils.reloader
|
|
|
|
|
import pkg.utils.updater
|
|
|
|
|
import pkg.utils.context
|
|
|
|
|
import pkg.qqbot.message
|
2023-02-28 10:38:25 +08:00
|
|
|
|
import pkg.utils.credit as credit
|
2023-03-28 11:12:19 +08:00
|
|
|
|
# import pkg.qqbot.cmds.model as cmdmodel
|
2023-04-06 18:37:07 +08:00
|
|
|
|
import pkg.qqbot.cmds.aamgr as cmdmgr
|
2023-01-14 20:34:33 +08:00
|
|
|
|
|
|
|
|
|
from mirai import Image
|
|
|
|
|
|
|
|
|
|
|
2023-01-17 00:11:07 +08:00
|
|
|
|
|
2023-01-15 13:57:05 +08:00
|
|
|
|
def process_command(session_name: str, text_message: str, mgr, config,
|
2023-02-25 15:39:31 +08:00
|
|
|
|
launcher_type: str, launcher_id: int, sender_id: int, is_admin: bool) -> list:
|
2023-01-14 20:34:33 +08:00
|
|
|
|
reply = []
|
|
|
|
|
try:
|
|
|
|
|
logging.info(
|
|
|
|
|
"[{}]发起指令:{}".format(session_name, text_message[:min(20, len(text_message))] + (
|
|
|
|
|
"..." if len(text_message) > 20 else "")))
|
|
|
|
|
|
|
|
|
|
cmd = text_message[1:].strip().split(' ')[0]
|
|
|
|
|
|
|
|
|
|
params = text_message[1:].strip().split(' ')[1:]
|
|
|
|
|
|
2023-04-02 14:43:34 +08:00
|
|
|
|
# 把!~开头的转换成!cfg
|
2023-03-20 20:06:02 +08:00
|
|
|
|
if cmd.startswith('~'):
|
|
|
|
|
params = [cmd[1:]] + params
|
|
|
|
|
cmd = 'cfg'
|
|
|
|
|
|
2023-03-28 11:12:19 +08:00
|
|
|
|
# 包装参数
|
|
|
|
|
context = cmdmgr.Context(
|
|
|
|
|
command=cmd,
|
|
|
|
|
crt_command=cmd,
|
|
|
|
|
params=params,
|
2023-03-30 19:11:39 +08:00
|
|
|
|
crt_params=params[:],
|
2023-03-28 11:12:19 +08:00
|
|
|
|
session_name=session_name,
|
|
|
|
|
text_message=text_message,
|
|
|
|
|
launcher_type=launcher_type,
|
|
|
|
|
launcher_id=launcher_id,
|
|
|
|
|
sender_id=sender_id,
|
|
|
|
|
is_admin=is_admin,
|
|
|
|
|
privilege=2 if is_admin else 1, # 普通用户1,管理员2
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
reply = cmdmgr.execute(context)
|
|
|
|
|
except cmdmgr.CommandPrivilegeError as e:
|
2023-04-01 16:09:07 +08:00
|
|
|
|
reply = ["{}".format(e)]
|
2023-03-20 20:06:02 +08:00
|
|
|
|
|
|
|
|
|
return reply
|
2023-01-14 20:34:33 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
mgr.notify_admin("{}指令执行失败:{}".format(session_name, e))
|
|
|
|
|
logging.exception(e)
|
|
|
|
|
reply = ["[bot]err:{}".format(e)]
|
|
|
|
|
|
|
|
|
|
return reply
|