2022-02-19 18:20:19 +08:00
|
|
|
|
from nonebot.exception import MockApiException
|
2022-02-21 15:59:17 +08:00
|
|
|
|
from nonebot.adapters.onebot.v11 import Bot, Message
|
2022-02-19 18:20:19 +08:00
|
|
|
|
from utils.manager import group_manager
|
2022-12-26 18:40:34 +08:00
|
|
|
|
from services.log import logger
|
2022-02-19 18:20:19 +08:00
|
|
|
|
from typing import Dict, Any
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bot.on_calling_api
|
2022-07-31 17:30:29 +08:00
|
|
|
|
async def _(bot: Bot, api: str, data: Dict[str, Any]):
|
2022-02-19 18:20:19 +08:00
|
|
|
|
r = None
|
2022-12-26 19:11:52 +08:00
|
|
|
|
task = None
|
|
|
|
|
|
group_id = None
|
2022-12-26 18:40:34 +08:00
|
|
|
|
try:
|
|
|
|
|
|
if (
|
2022-03-03 00:18:59 +08:00
|
|
|
|
(
|
2022-12-26 18:40:34 +08:00
|
|
|
|
(api == "send_msg" and data.get("message_type") == "group")
|
|
|
|
|
|
or api == "send_group_msg"
|
2022-03-03 00:18:59 +08:00
|
|
|
|
)
|
2022-12-26 18:40:34 +08:00
|
|
|
|
and (
|
|
|
|
|
|
(
|
|
|
|
|
|
r := re.search(
|
|
|
|
|
|
"^\[\[_task\|(.*)]]",
|
|
|
|
|
|
data["message"].strip()
|
|
|
|
|
|
if isinstance(data["message"], str)
|
|
|
|
|
|
else str(data["message"]["text"]).strip(),
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
or (
|
|
|
|
|
|
r := re.search(
|
|
|
|
|
|
"^[[_task\|(.*)]]",
|
|
|
|
|
|
data["message"].strip()
|
|
|
|
|
|
if isinstance(data["message"], str)
|
|
|
|
|
|
else str(data["message"]["text"]).strip(),
|
|
|
|
|
|
)
|
2022-02-21 15:59:17 +08:00
|
|
|
|
)
|
2022-02-20 11:06:04 +08:00
|
|
|
|
)
|
2022-12-26 18:40:34 +08:00
|
|
|
|
and r.group(1) in group_manager.get_task_data().keys()
|
|
|
|
|
|
):
|
|
|
|
|
|
task = r.group(1)
|
|
|
|
|
|
group_id = data["group_id"]
|
2022-12-26 19:11:52 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"TaskHook ERROR {type(e)}:{e}")
|
|
|
|
|
|
else:
|
|
|
|
|
|
if task and group_id:
|
2022-12-26 18:40:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
group_manager.get_group_level(group_id) < 0
|
|
|
|
|
|
or not group_manager.check_task_status(task, group_id)
|
|
|
|
|
|
):
|
|
|
|
|
|
raise MockApiException(f"被动技能 {task} 处于关闭状态...")
|
|
|
|
|
|
else:
|
|
|
|
|
|
msg = str(data["message"]).strip()
|
|
|
|
|
|
msg = msg.replace(f"[[_task|{task}]]", "").replace(
|
|
|
|
|
|
f"[[_task|{task}]]", ""
|
|
|
|
|
|
)
|
|
|
|
|
|
data["message"] = Message(msg)
|