2022-12-10 16:40:05 +08:00
|
|
|
|
import asyncio
|
2022-12-11 17:17:33 +08:00
|
|
|
|
import json
|
|
|
|
|
import os
|
2022-12-10 16:40:05 +08:00
|
|
|
|
import threading
|
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
|
2023-01-17 15:43:28 +08:00
|
|
|
|
from mirai import At, GroupMessage, MessageEvent, Mirai, StrangerMessage, WebSocketAdapter, HTTPAdapter, \
|
2023-04-21 17:51:58 +08:00
|
|
|
|
FriendMessage, Image, MessageChain, Plain
|
2023-02-22 23:37:13 +08:00
|
|
|
|
from func_timeout import func_set_timeout
|
2022-12-09 16:18:25 +08:00
|
|
|
|
|
2022-12-07 23:37:52 +08:00
|
|
|
|
import pkg.openai.session
|
2022-12-15 18:50:15 +08:00
|
|
|
|
import pkg.openai.manager
|
2022-12-26 19:37:25 +08:00
|
|
|
|
from func_timeout import FunctionTimedOut
|
2022-12-08 21:58:02 +08:00
|
|
|
|
import logging
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-11 17:17:33 +08:00
|
|
|
|
import pkg.qqbot.filter
|
2022-12-26 19:37:25 +08:00
|
|
|
|
import pkg.qqbot.process as processor
|
2023-01-01 23:18:32 +08:00
|
|
|
|
import pkg.utils.context
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2023-01-13 16:49:56 +08:00
|
|
|
|
import pkg.plugin.host as plugin_host
|
|
|
|
|
import pkg.plugin.models as plugin_models
|
2023-04-07 13:20:57 +08:00
|
|
|
|
import tips as tips_custom
|
2023-01-13 16:49:56 +08:00
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
import pkg.qqbot.adapter as msadapter
|
|
|
|
|
|
2023-03-06 17:50:34 +08:00
|
|
|
|
|
2022-12-19 17:07:31 +08:00
|
|
|
|
# 检查消息是否符合泛响应匹配机制
|
2023-04-25 09:31:44 +08:00
|
|
|
|
def check_response_rule(group_id:int, text: str):
|
2023-01-04 17:09:57 +08:00
|
|
|
|
config = pkg.utils.context.get_config()
|
2022-12-19 17:15:17 +08:00
|
|
|
|
|
2022-12-19 17:07:31 +08:00
|
|
|
|
rules = config.response_rules
|
2023-04-25 09:31:44 +08:00
|
|
|
|
|
|
|
|
|
# 检查是否有特定规则
|
|
|
|
|
if 'prefix' not in config.response_rules:
|
|
|
|
|
if str(group_id) in config.response_rules:
|
|
|
|
|
rules = config.response_rules[str(group_id)]
|
|
|
|
|
else:
|
|
|
|
|
rules = config.response_rules['default']
|
|
|
|
|
|
2022-12-19 17:07:31 +08:00
|
|
|
|
# 检查前缀匹配
|
2022-12-19 17:15:17 +08:00
|
|
|
|
if 'prefix' in rules:
|
|
|
|
|
for rule in rules['prefix']:
|
|
|
|
|
if text.startswith(rule):
|
|
|
|
|
return True, text.replace(rule, "", 1)
|
2022-12-19 17:07:31 +08:00
|
|
|
|
|
|
|
|
|
# 检查正则表达式匹配
|
2022-12-19 17:15:17 +08:00
|
|
|
|
if 'regexp' in rules:
|
|
|
|
|
for rule in rules['regexp']:
|
|
|
|
|
import re
|
|
|
|
|
match = re.match(rule, text)
|
|
|
|
|
if match:
|
2022-12-19 17:17:49 +08:00
|
|
|
|
return True, text
|
2022-12-19 17:07:31 +08:00
|
|
|
|
|
|
|
|
|
return False, ""
|
|
|
|
|
|
|
|
|
|
|
2023-04-25 09:31:44 +08:00
|
|
|
|
def response_at(group_id: int):
|
2023-03-06 17:50:34 +08:00
|
|
|
|
config = pkg.utils.context.get_config()
|
2023-04-25 09:31:44 +08:00
|
|
|
|
|
|
|
|
|
use_response_rule = config.response_rules
|
|
|
|
|
|
|
|
|
|
# 检查是否有特定规则
|
|
|
|
|
if 'prefix' not in config.response_rules:
|
|
|
|
|
if str(group_id) in config.response_rules:
|
|
|
|
|
use_response_rule = config.response_rules[str(group_id)]
|
|
|
|
|
else:
|
|
|
|
|
use_response_rule = config.response_rules['default']
|
|
|
|
|
|
|
|
|
|
if 'at' not in use_response_rule:
|
2023-03-06 17:50:34 +08:00
|
|
|
|
return True
|
|
|
|
|
|
2023-04-25 09:31:44 +08:00
|
|
|
|
return use_response_rule['at']
|
2023-03-06 17:50:34 +08:00
|
|
|
|
|
|
|
|
|
|
2023-04-25 09:31:44 +08:00
|
|
|
|
def random_responding(group_id):
|
2023-03-06 17:50:34 +08:00
|
|
|
|
config = pkg.utils.context.get_config()
|
2023-04-25 09:31:44 +08:00
|
|
|
|
|
|
|
|
|
use_response_rule = config.response_rules
|
|
|
|
|
|
|
|
|
|
# 检查是否有特定规则
|
|
|
|
|
if 'prefix' not in config.response_rules:
|
|
|
|
|
if str(group_id) in config.response_rules:
|
|
|
|
|
use_response_rule = config.response_rules[str(group_id)]
|
|
|
|
|
else:
|
|
|
|
|
use_response_rule = config.response_rules['default']
|
|
|
|
|
|
|
|
|
|
if 'random_rate' in use_response_rule:
|
2023-03-06 17:50:34 +08:00
|
|
|
|
import random
|
2023-04-25 09:31:44 +08:00
|
|
|
|
return random.random() < use_response_rule['random_rate']
|
2023-03-06 17:50:34 +08:00
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
2022-12-11 16:10:12 +08:00
|
|
|
|
# 控制QQ消息输入输出的类
|
2022-12-07 23:37:52 +08:00
|
|
|
|
class QQBotManager:
|
|
|
|
|
retry = 3
|
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
adapter: msadapter.MessageSourceAdapter = None
|
|
|
|
|
|
|
|
|
|
bot_account_id: int = 0
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-11 17:17:33 +08:00
|
|
|
|
reply_filter = None
|
|
|
|
|
|
2023-01-07 16:50:34 +08:00
|
|
|
|
enable_banlist = False
|
|
|
|
|
|
|
|
|
|
ban_person = []
|
|
|
|
|
ban_group = []
|
|
|
|
|
|
2023-04-21 17:15:32 +08:00
|
|
|
|
def __init__(self, first_time_init=True):
|
|
|
|
|
import config
|
|
|
|
|
|
|
|
|
|
self.timeout = config.process_message_timeout
|
|
|
|
|
self.retry = config.retry_times
|
2023-03-06 08:50:28 +08:00
|
|
|
|
|
2023-01-02 13:06:48 +08:00
|
|
|
|
# 由于YiriMirai的bot对象是单例的,且shutdown方法暂时无法使用
|
|
|
|
|
# 故只在第一次初始化时创建bot对象,重载之后使用原bot对象
|
|
|
|
|
# 因此,bot的配置不支持热重载
|
2023-01-02 00:35:36 +08:00
|
|
|
|
if first_time_init:
|
2023-04-23 23:40:08 +08:00
|
|
|
|
logging.info("Use adapter:" + config.msg_source_adapter)
|
2023-04-21 17:51:58 +08:00
|
|
|
|
if config.msg_source_adapter == 'yirimirai':
|
|
|
|
|
from pkg.qqbot.sources.yirimirai import YiriMiraiAdapter
|
2023-04-23 23:40:08 +08:00
|
|
|
|
|
|
|
|
|
mirai_http_api_config = config.mirai_http_api_config
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.bot_account_id = config.mirai_http_api_config['qq']
|
|
|
|
|
self.adapter = YiriMiraiAdapter(mirai_http_api_config)
|
2023-04-23 15:58:37 +08:00
|
|
|
|
elif config.msg_source_adapter == 'nakuru':
|
2023-04-23 23:40:08 +08:00
|
|
|
|
from pkg.qqbot.sources.nakuru import NakuruProjectAdapter
|
|
|
|
|
self.adapter = NakuruProjectAdapter(config.nakuru_config)
|
2023-04-24 10:34:51 +08:00
|
|
|
|
self.bot_account_id = self.adapter.bot_account_id
|
2023-01-02 00:35:36 +08:00
|
|
|
|
else:
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter = pkg.utils.context.get_qqbot_manager().adapter
|
2023-01-02 00:35:36 +08:00
|
|
|
|
|
|
|
|
|
pkg.utils.context.set_qqbot_manager(self)
|
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
# 注册诸事件
|
2023-01-02 11:33:26 +08:00
|
|
|
|
# Caution: 注册新的事件处理器之后,请务必在unsubscribe_all中编写相应的取消订阅代码
|
2023-04-21 17:51:58 +08:00
|
|
|
|
def on_friend_message(event: FriendMessage):
|
2023-01-14 19:59:51 +08:00
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
def friend_message_handler():
|
2023-01-15 00:04:47 +08:00
|
|
|
|
# 触发事件
|
|
|
|
|
args = {
|
|
|
|
|
"launcher_type": "person",
|
|
|
|
|
"launcher_id": event.sender.id,
|
|
|
|
|
"sender_id": event.sender.id,
|
|
|
|
|
"message_chain": event.message_chain,
|
|
|
|
|
}
|
|
|
|
|
plugin_event = plugin_host.emit(plugin_models.PersonMessageReceived, **args)
|
|
|
|
|
|
|
|
|
|
if plugin_event.is_prevented_default():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.on_person_message(event)
|
|
|
|
|
|
2023-03-08 15:21:37 +08:00
|
|
|
|
pkg.utils.context.get_thread_ctl().submit_user_task(
|
|
|
|
|
friend_message_handler,
|
|
|
|
|
)
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.register_listener(
|
|
|
|
|
FriendMessage,
|
|
|
|
|
on_friend_message
|
|
|
|
|
)
|
2023-01-02 11:33:26 +08:00
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
def on_stranger_message(event: StrangerMessage):
|
2023-01-14 19:59:51 +08:00
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
def stranger_message_handler():
|
2023-01-15 00:04:47 +08:00
|
|
|
|
# 触发事件
|
|
|
|
|
args = {
|
|
|
|
|
"launcher_type": "person",
|
|
|
|
|
"launcher_id": event.sender.id,
|
|
|
|
|
"sender_id": event.sender.id,
|
|
|
|
|
"message_chain": event.message_chain,
|
|
|
|
|
}
|
|
|
|
|
plugin_event = plugin_host.emit(plugin_models.PersonMessageReceived, **args)
|
|
|
|
|
|
|
|
|
|
if plugin_event.is_prevented_default():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.on_person_message(event)
|
2023-01-14 19:59:51 +08:00
|
|
|
|
|
2023-03-08 15:21:37 +08:00
|
|
|
|
pkg.utils.context.get_thread_ctl().submit_user_task(
|
|
|
|
|
stranger_message_handler,
|
|
|
|
|
)
|
2023-04-23 23:40:08 +08:00
|
|
|
|
# nakuru不区分好友和陌生人,故仅为yirimirai注册陌生人事件
|
|
|
|
|
if config.msg_source_adapter == 'yirimirai':
|
|
|
|
|
self.adapter.register_listener(
|
|
|
|
|
StrangerMessage,
|
|
|
|
|
on_stranger_message
|
|
|
|
|
)
|
2023-01-02 11:33:26 +08:00
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
def on_group_message(event: GroupMessage):
|
2023-01-15 00:04:47 +08:00
|
|
|
|
|
|
|
|
|
def group_message_handler(event: GroupMessage):
|
|
|
|
|
# 触发事件
|
|
|
|
|
args = {
|
|
|
|
|
"launcher_type": "group",
|
|
|
|
|
"launcher_id": event.group.id,
|
|
|
|
|
"sender_id": event.sender.id,
|
|
|
|
|
"message_chain": event.message_chain,
|
|
|
|
|
}
|
|
|
|
|
plugin_event = plugin_host.emit(plugin_models.GroupMessageReceived, **args)
|
|
|
|
|
|
|
|
|
|
if plugin_event.is_prevented_default():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.on_group_message(event)
|
|
|
|
|
|
2023-03-08 15:21:37 +08:00
|
|
|
|
pkg.utils.context.get_thread_ctl().submit_user_task(
|
|
|
|
|
group_message_handler,
|
|
|
|
|
event
|
|
|
|
|
)
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.register_listener(
|
|
|
|
|
GroupMessage,
|
|
|
|
|
on_group_message
|
|
|
|
|
)
|
2023-01-02 11:33:26 +08:00
|
|
|
|
|
|
|
|
|
def unsubscribe_all():
|
2023-01-02 13:06:48 +08:00
|
|
|
|
"""取消所有订阅
|
|
|
|
|
|
|
|
|
|
用于在热重载流程中卸载所有事件处理器
|
|
|
|
|
"""
|
2023-04-24 11:21:51 +08:00
|
|
|
|
import config
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.unregister_listener(
|
|
|
|
|
FriendMessage,
|
|
|
|
|
on_friend_message
|
|
|
|
|
)
|
2023-04-24 11:21:51 +08:00
|
|
|
|
if config.msg_source_adapter == 'yirimirai':
|
|
|
|
|
self.adapter.unregister_listener(
|
|
|
|
|
StrangerMessage,
|
|
|
|
|
on_stranger_message
|
|
|
|
|
)
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.unregister_listener(
|
|
|
|
|
GroupMessage,
|
|
|
|
|
on_group_message
|
|
|
|
|
)
|
2023-01-02 11:33:26 +08:00
|
|
|
|
|
|
|
|
|
self.unsubscribe_all = unsubscribe_all
|
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
# 加载禁用列表
|
|
|
|
|
if os.path.exists("banlist.py"):
|
|
|
|
|
import banlist
|
|
|
|
|
self.enable_banlist = banlist.enable
|
|
|
|
|
self.ban_person = banlist.person
|
|
|
|
|
self.ban_group = banlist.group
|
|
|
|
|
logging.info("加载禁用列表: person: {}, group: {}".format(self.ban_person, self.ban_group))
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
config = pkg.utils.context.get_config()
|
|
|
|
|
if os.path.exists("sensitive.json") \
|
|
|
|
|
and config.sensitive_word_filter is not None \
|
|
|
|
|
and config.sensitive_word_filter:
|
|
|
|
|
with open("sensitive.json", "r", encoding="utf-8") as f:
|
|
|
|
|
sensitive_json = json.load(f)
|
|
|
|
|
self.reply_filter = pkg.qqbot.filter.ReplyFilter(
|
|
|
|
|
sensitive_words=sensitive_json['words'],
|
|
|
|
|
mask=sensitive_json['mask'] if 'mask' in sensitive_json else '*',
|
|
|
|
|
mask_word=sensitive_json['mask_word'] if 'mask_word' in sensitive_json else ''
|
|
|
|
|
)
|
2022-12-26 19:37:25 +08:00
|
|
|
|
else:
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.reply_filter = pkg.qqbot.filter.ReplyFilter([])
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2023-01-01 17:20:54 +08:00
|
|
|
|
def send(self, event, msg, check_quote=True):
|
2023-01-04 17:09:57 +08:00
|
|
|
|
config = pkg.utils.context.get_config()
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.reply_message(
|
|
|
|
|
event,
|
|
|
|
|
msg,
|
|
|
|
|
quote_origin=True if config.quote_origin and check_quote else False
|
|
|
|
|
)
|
2022-12-12 22:04:38 +08:00
|
|
|
|
|
2022-12-11 16:10:12 +08:00
|
|
|
|
# 私聊消息处理
|
2022-12-12 22:04:38 +08:00
|
|
|
|
def on_person_message(self, event: MessageEvent):
|
2023-02-22 23:37:13 +08:00
|
|
|
|
import config
|
2022-12-07 23:37:52 +08:00
|
|
|
|
reply = ''
|
|
|
|
|
|
2023-04-21 17:51:58 +08:00
|
|
|
|
if event.sender.id == self.bot_account_id:
|
2022-12-07 23:37:52 +08:00
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
if Image in event.message_chain:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
2022-12-12 22:04:38 +08:00
|
|
|
|
# 超时则重试,重试超过次数则放弃
|
|
|
|
|
failed = 0
|
|
|
|
|
for i in range(self.retry):
|
|
|
|
|
try:
|
2023-02-22 23:37:13 +08:00
|
|
|
|
|
|
|
|
|
@func_set_timeout(config.process_message_timeout)
|
|
|
|
|
def time_ctrl_wrapper():
|
|
|
|
|
reply = processor.process_message('person', event.sender.id, str(event.message_chain),
|
|
|
|
|
event.message_chain,
|
|
|
|
|
event.sender.id)
|
|
|
|
|
return reply
|
|
|
|
|
|
|
|
|
|
reply = time_ctrl_wrapper()
|
2022-12-12 22:04:38 +08:00
|
|
|
|
break
|
|
|
|
|
except FunctionTimedOut:
|
2023-01-25 22:43:49 +08:00
|
|
|
|
logging.warning("person_{}: 超时,重试中({})".format(event.sender.id, i))
|
2022-12-13 16:04:51 +08:00
|
|
|
|
pkg.openai.session.get_session('person_{}'.format(event.sender.id)).release_response_lock()
|
2023-01-08 14:49:23 +08:00
|
|
|
|
if "person_{}".format(event.sender.id) in pkg.qqbot.process.processing:
|
|
|
|
|
pkg.qqbot.process.processing.remove('person_{}'.format(event.sender.id))
|
2022-12-12 22:04:38 +08:00
|
|
|
|
failed += 1
|
|
|
|
|
continue
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-12 22:04:38 +08:00
|
|
|
|
if failed == self.retry:
|
2022-12-13 16:04:51 +08:00
|
|
|
|
pkg.openai.session.get_session('person_{}'.format(event.sender.id)).release_response_lock()
|
2022-12-13 00:45:56 +08:00
|
|
|
|
self.notify_admin("{} 请求超时".format("person_{}".format(event.sender.id)))
|
2023-04-07 13:23:58 +08:00
|
|
|
|
reply = [tips_custom.reply_message]
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-26 23:53:56 +08:00
|
|
|
|
if reply:
|
2023-01-01 17:20:54 +08:00
|
|
|
|
return self.send(event, reply, check_quote=False)
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-11 16:10:12 +08:00
|
|
|
|
# 群消息处理
|
2022-12-12 22:04:38 +08:00
|
|
|
|
def on_group_message(self, event: GroupMessage):
|
2023-02-22 23:37:13 +08:00
|
|
|
|
import config
|
2022-12-07 23:37:52 +08:00
|
|
|
|
reply = ''
|
2022-12-21 14:17:57 +08:00
|
|
|
|
def process(text=None) -> str:
|
2022-12-19 17:07:31 +08:00
|
|
|
|
replys = ""
|
2023-04-21 17:51:58 +08:00
|
|
|
|
if At(self.bot_account_id) in event.message_chain:
|
|
|
|
|
event.message_chain.remove(At(self.bot_account_id))
|
2022-12-08 12:06:04 +08:00
|
|
|
|
|
2022-12-12 22:04:38 +08:00
|
|
|
|
# 超时则重试,重试超过次数则放弃
|
|
|
|
|
failed = 0
|
|
|
|
|
for i in range(self.retry):
|
|
|
|
|
try:
|
2023-02-22 23:37:13 +08:00
|
|
|
|
@func_set_timeout(config.process_message_timeout)
|
|
|
|
|
def time_ctrl_wrapper():
|
|
|
|
|
replys = processor.process_message('group', event.group.id,
|
|
|
|
|
str(event.message_chain).strip() if text is None else text,
|
|
|
|
|
event.message_chain,
|
|
|
|
|
event.sender.id)
|
|
|
|
|
return replys
|
|
|
|
|
|
|
|
|
|
replys = time_ctrl_wrapper()
|
2022-12-12 22:04:38 +08:00
|
|
|
|
break
|
|
|
|
|
except FunctionTimedOut:
|
2023-01-25 22:43:49 +08:00
|
|
|
|
logging.warning("group_{}: 超时,重试中({})".format(event.group.id, i))
|
2023-01-02 00:11:10 +08:00
|
|
|
|
pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock()
|
2023-01-25 22:51:09 +08:00
|
|
|
|
if "group_{}".format(event.group.id) in pkg.qqbot.process.processing:
|
|
|
|
|
pkg.qqbot.process.processing.remove('group_{}'.format(event.group.id))
|
2022-12-12 22:04:38 +08:00
|
|
|
|
failed += 1
|
|
|
|
|
continue
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-12 22:04:38 +08:00
|
|
|
|
if failed == self.retry:
|
2023-01-02 00:11:10 +08:00
|
|
|
|
pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock()
|
|
|
|
|
self.notify_admin("{} 请求超时".format("group_{}".format(event.group.id)))
|
2023-04-07 13:23:58 +08:00
|
|
|
|
replys = [tips_custom.replys_message]
|
2022-12-19 17:07:31 +08:00
|
|
|
|
|
|
|
|
|
return replys
|
|
|
|
|
|
|
|
|
|
if Image in event.message_chain:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
2023-04-25 09:31:44 +08:00
|
|
|
|
if At(self.bot_account_id) in event.message_chain and response_at(event.group.id):
|
2023-03-06 17:50:34 +08:00
|
|
|
|
# 直接调用
|
|
|
|
|
reply = process()
|
|
|
|
|
else:
|
2023-04-25 09:31:44 +08:00
|
|
|
|
check, result = check_response_rule(event.group.id, str(event.message_chain).strip())
|
2023-03-06 17:50:34 +08:00
|
|
|
|
|
|
|
|
|
if check:
|
|
|
|
|
reply = process(result.strip())
|
|
|
|
|
# 检查是否随机响应
|
2023-04-25 09:31:44 +08:00
|
|
|
|
elif random_responding(event.group.id):
|
2023-03-06 17:50:34 +08:00
|
|
|
|
logging.info("随机响应group_{}消息".format(event.group.id))
|
|
|
|
|
reply = process()
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-26 23:53:56 +08:00
|
|
|
|
if reply:
|
2022-12-12 22:04:38 +08:00
|
|
|
|
return self.send(event, reply)
|
2022-12-07 23:37:52 +08:00
|
|
|
|
|
2022-12-11 16:10:12 +08:00
|
|
|
|
# 通知系统管理员
|
2022-12-10 16:40:05 +08:00
|
|
|
|
def notify_admin(self, message: str):
|
2023-01-04 17:09:57 +08:00
|
|
|
|
config = pkg.utils.context.get_config()
|
2023-04-06 20:34:56 +08:00
|
|
|
|
if config.admin_qq != 0 and config.admin_qq != []:
|
2022-12-13 13:36:16 +08:00
|
|
|
|
logging.info("通知管理员:{}".format(message))
|
2023-02-25 15:39:31 +08:00
|
|
|
|
if type(config.admin_qq) == int:
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.send_message(
|
|
|
|
|
"person",
|
|
|
|
|
config.admin_qq,
|
|
|
|
|
MessageChain([Plain("[bot]{}".format(message))])
|
|
|
|
|
)
|
2023-02-25 15:39:31 +08:00
|
|
|
|
else:
|
|
|
|
|
for adm in config.admin_qq:
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.send_message(
|
|
|
|
|
"person",
|
|
|
|
|
adm,
|
|
|
|
|
MessageChain([Plain("[bot]{}".format(message))])
|
|
|
|
|
)
|
2023-02-10 19:03:25 +08:00
|
|
|
|
|
|
|
|
|
def notify_admin_message_chain(self, message):
|
|
|
|
|
config = pkg.utils.context.get_config()
|
2023-04-06 20:34:56 +08:00
|
|
|
|
if config.admin_qq != 0 and config.admin_qq != []:
|
2023-02-10 19:03:25 +08:00
|
|
|
|
logging.info("通知管理员:{}".format(message))
|
2023-02-25 15:39:31 +08:00
|
|
|
|
if type(config.admin_qq) == int:
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.send_message(
|
|
|
|
|
"person",
|
|
|
|
|
config.admin_qq,
|
|
|
|
|
message
|
|
|
|
|
)
|
2023-02-25 15:39:31 +08:00
|
|
|
|
else:
|
|
|
|
|
for adm in config.admin_qq:
|
2023-04-21 17:51:58 +08:00
|
|
|
|
self.adapter.send_message(
|
|
|
|
|
"person",
|
|
|
|
|
adm,
|
|
|
|
|
message
|
|
|
|
|
)
|