status适配satori

This commit is contained in:
Expliyh
2024-05-16 21:17:10 +08:00
parent 7abdac7c9c
commit eaf57f2c33
9 changed files with 191 additions and 107 deletions

View File

@ -9,7 +9,21 @@ from liteyuki.utils.message.npl import convert_seconds_to_time
from contextvars import ContextVar
async def get_stat_msg_image(duration: int, period: int, group_id: str = None, bot_id: str = None, ulang: Language = Language()) -> bytes:
async def count_msg_by_bot_id(bot_id: str) -> int:
condition = " AND bot_id = ?"
condition_args = [bot_id]
msg_rows = msg_db.where_all(
MessageEventModel(),
condition,
*condition_args
)
return len(msg_rows)
async def get_stat_msg_image(duration: int, period: int, group_id: str = None, bot_id: str = None,
ulang: Language = Language()) -> bytes:
"""
获取统计消息
Args:
@ -58,15 +72,15 @@ async def get_stat_msg_image(duration: int, period: int, group_id: str = None, b
msg_count[index] += 1
templates = {
"data": [
{
"name" : ulang.get("stat.message")
+ f" Period {convert_seconds_to_time(period)}" + f" Duration {convert_seconds_to_time(duration)}"
+ (f" Group {group_id}" if group_id else "") + (f" Bot {bot_id}" if bot_id else ""),
"times" : timestamps,
"counts": msg_count
}
]
"data": [
{
"name": ulang.get("stat.message")
+ f" Period {convert_seconds_to_time(period)}" + f" Duration {convert_seconds_to_time(duration)}"
+ (f" Group {group_id}" if group_id else "") + (f" Bot {bot_id}" if bot_id else ""),
"times": timestamps,
"counts": msg_count
}
]
}
return await template2image(get_path("templates/stat_msg.html"), templates, debug=True)

View File

@ -6,15 +6,22 @@ from nonebot.message import event_postprocessor
from liteyuki.utils.base.data import Database, LiteModel
from liteyuki.utils.base.ly_typing import v11, satori
from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent
from .common import MessageEventModel, msg_db
from ...utils import satori_utils
require("nonebot_plugin_alconna")
@event_postprocessor
async def general_event_monitor(bot: T_Bot, event: T_MessageEvent):
if isinstance(bot, satori.Bot):
return await satori_event_monitor(bot, event)
else:
return await onebot_v11_event_monitor(bot, event)
async def onebot_v11_event_monitor(bot: v11.Bot, event: v11.MessageEvent):
if event.message_type == "group":
event: v11.GroupMessageEvent
@ -56,6 +63,6 @@ async def satori_event_monitor(bot: satori.Bot, event: satori.MessageEvent):
message=event.message,
message_text=event.message.content,
message_type=event.message_type,
message_type=satori_utils.get_message_type(event),
)
msg_db.save(mem)