mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
🐛 修复调用统计异常 (#1674)
This commit is contained in:
parent
f08114f6c5
commit
bd50e17c58
@ -5,6 +5,7 @@ from nonebot.adapters import Bot, Event
|
|||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
from nonebot.message import run_postprocessor
|
from nonebot.message import run_postprocessor
|
||||||
from nonebot_plugin_session import EventSession
|
from nonebot_plugin_session import EventSession
|
||||||
|
from nonebot_plugin_apscheduler import scheduler
|
||||||
from nonebot.adapters.onebot.v11 import PokeNotifyEvent
|
from nonebot.adapters.onebot.v11 import PokeNotifyEvent
|
||||||
|
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
@ -22,6 +23,8 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
).dict(),
|
).dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TEMP_LIST = []
|
||||||
|
|
||||||
|
|
||||||
@run_postprocessor
|
@run_postprocessor
|
||||||
async def _(
|
async def _(
|
||||||
@ -34,15 +37,32 @@ async def _(
|
|||||||
if matcher.type == "notice" and not isinstance(event, PokeNotifyEvent):
|
if matcher.type == "notice" and not isinstance(event, PokeNotifyEvent):
|
||||||
"""过滤除poke外的notice"""
|
"""过滤除poke外的notice"""
|
||||||
return
|
return
|
||||||
if session.id1:
|
if session.id1 and matcher.plugin:
|
||||||
plugin = await PluginInfo.get_or_none(module=matcher.module_name)
|
plugin = await PluginInfo.get_plugin(module_path=matcher.plugin.module_name)
|
||||||
plugin_type = plugin.plugin_type if plugin else None
|
plugin_type = plugin.plugin_type if plugin else None
|
||||||
if plugin_type == PluginType.NORMAL:
|
if plugin_type == PluginType.NORMAL:
|
||||||
logger.debug(f"提交调用记录: {matcher.plugin_name}...", session=session)
|
logger.debug(f"提交调用记录: {matcher.plugin_name}...", session=session)
|
||||||
await Statistics.create(
|
TEMP_LIST.append(
|
||||||
|
Statistics(
|
||||||
user_id=session.id1,
|
user_id=session.id1,
|
||||||
group_id=session.id3 or session.id2,
|
group_id=session.id3 or session.id2,
|
||||||
plugin_name=matcher.plugin_name,
|
plugin_name=matcher.plugin_name,
|
||||||
create_time=datetime.now(),
|
create_time=datetime.now(),
|
||||||
bot_id=bot.self_id,
|
bot_id=bot.self_id,
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@scheduler.scheduled_job(
|
||||||
|
"interval",
|
||||||
|
minutes=1,
|
||||||
|
)
|
||||||
|
async def _():
|
||||||
|
try:
|
||||||
|
call_list = TEMP_LIST.copy()
|
||||||
|
TEMP_LIST.clear()
|
||||||
|
if call_list:
|
||||||
|
await Statistics.bulk_create(call_list)
|
||||||
|
logger.debug(f"批量添加调用记录 {len(call_list)} 条", "定时任务")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("定时批量添加调用记录", "定时任务", e=e)
|
||||||
|
|||||||
@ -28,5 +28,5 @@ class Statistics(Model):
|
|||||||
# 将user_qq改为user_id
|
# 将user_qq改为user_id
|
||||||
"ALTER TABLE statistics ALTER COLUMN user_id TYPE character varying(255);",
|
"ALTER TABLE statistics ALTER COLUMN user_id TYPE character varying(255);",
|
||||||
"ALTER TABLE statistics ALTER COLUMN group_id TYPE character varying(255);",
|
"ALTER TABLE statistics ALTER COLUMN group_id TYPE character varying(255);",
|
||||||
"ALTER TABLE statistics ADD boe_id Text DEFAULT '';",
|
"ALTER TABLE statistics ADD bot_id Text DEFAULT '';",
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user