2024-05-12 00:18:53 +08:00
|
|
|
import time
|
|
|
|
|
|
|
|
from nonebot import require
|
|
|
|
from nonebot.message import event_postprocessor
|
|
|
|
|
2024-05-12 02:47:14 +08:00
|
|
|
from liteyuki.utils.base.data import Database, LiteModel
|
2024-05-16 19:20:54 +08:00
|
|
|
from liteyuki.utils.base.ly_typing import v11, satori
|
2024-05-12 00:18:53 +08:00
|
|
|
|
2024-05-16 21:17:10 +08:00
|
|
|
from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent
|
|
|
|
|
2024-05-12 00:18:53 +08:00
|
|
|
from .common import MessageEventModel, msg_db
|
2024-05-17 00:25:27 +08:00
|
|
|
from liteyuki.utils import satori_utils
|
2024-05-12 00:18:53 +08:00
|
|
|
|
|
|
|
require("nonebot_plugin_alconna")
|
|
|
|
|
|
|
|
|
2024-05-16 21:17:10 +08:00
|
|
|
async def general_event_monitor(bot: T_Bot, event: T_MessageEvent):
|
2024-05-17 14:18:55 +08:00
|
|
|
print("POST PROCESS")
|
|
|
|
# if isinstance(bot, satori.Bot):
|
|
|
|
# print("POST PROCESS SATORI EVENT")
|
|
|
|
# return await satori_event_monitor(bot, event)
|
|
|
|
# elif isinstance(bot, v11.Bot):
|
|
|
|
# print("POST PROCESS V11 EVENT")
|
|
|
|
# return await onebot_v11_event_monitor(bot, event)
|
2024-05-12 00:18:53 +08:00
|
|
|
|
|
|
|
|
2024-05-17 14:18:55 +08:00
|
|
|
@event_postprocessor
|
2024-05-12 00:18:53 +08:00
|
|
|
async def onebot_v11_event_monitor(bot: v11.Bot, event: v11.MessageEvent):
|
|
|
|
if event.message_type == "group":
|
|
|
|
event: v11.GroupMessageEvent
|
|
|
|
group_id = str(event.group_id)
|
|
|
|
else:
|
|
|
|
group_id = ""
|
|
|
|
mem = MessageEventModel(
|
|
|
|
time=int(time.time()),
|
|
|
|
bot_id=bot.self_id,
|
|
|
|
adapter="onebot.v11",
|
|
|
|
group_id=group_id,
|
|
|
|
user_id=str(event.user_id),
|
|
|
|
|
|
|
|
message_id=str(event.message_id),
|
|
|
|
|
|
|
|
message=event.message,
|
|
|
|
message_text=event.raw_message,
|
|
|
|
message_type=event.message_type,
|
|
|
|
)
|
|
|
|
msg_db.save(mem)
|
2024-05-16 19:20:54 +08:00
|
|
|
|
|
|
|
|
2024-05-17 14:18:55 +08:00
|
|
|
@event_postprocessor
|
2024-05-16 19:20:54 +08:00
|
|
|
async def satori_event_monitor(bot: satori.Bot, event: satori.MessageEvent):
|
|
|
|
if event.guild is not None:
|
|
|
|
event: satori.MessageEvent
|
|
|
|
group_id = str(event.guild.id)
|
|
|
|
else:
|
|
|
|
group_id = ""
|
|
|
|
|
|
|
|
mem = MessageEventModel(
|
|
|
|
time=int(time.time()),
|
|
|
|
bot_id=bot.self_id,
|
|
|
|
adapter="satori",
|
|
|
|
group_id=group_id,
|
|
|
|
user_id=str(event.user.id),
|
|
|
|
message_id=str(event.message.id),
|
|
|
|
message=event.message,
|
|
|
|
message_text=event.message.content,
|
2024-05-16 21:17:10 +08:00
|
|
|
message_type=satori_utils.get_message_type(event),
|
2024-05-16 19:20:54 +08:00
|
|
|
)
|
|
|
|
msg_db.save(mem)
|