From 5bc2725d1b544f7bd0156964b7c8e95f453f0e04 Mon Sep 17 00:00:00 2001 From: snowy Date: Fri, 24 May 2024 23:41:33 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B6=88=E6=81=AF=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=96=B0=E5=A2=9E=E6=8C=87=E5=AE=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_statistics/stat_api.py | 6 +++++- liteyuki/plugins/liteyuki_statistics/stat_matchers.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/liteyuki/plugins/liteyuki_statistics/stat_api.py b/liteyuki/plugins/liteyuki_statistics/stat_api.py index 9c3c6001..9ccf8783 100644 --- a/liteyuki/plugins/liteyuki_statistics/stat_api.py +++ b/liteyuki/plugins/liteyuki_statistics/stat_api.py @@ -22,7 +22,7 @@ async def count_msg_by_bot_id(bot_id: str) -> int: return len(msg_rows) -async def get_stat_msg_image(duration: int, period: int, group_id: str = None, bot_id: str = None, +async def get_stat_msg_image(duration: int, period: int, group_id: str = None, bot_id: str = None, user_id: str = None, ulang: Language = Language()) -> bytes: """ 获取统计消息 @@ -50,6 +50,10 @@ async def get_stat_msg_image(duration: int, period: int, group_id: str = None, b condition += " AND bot_id = ?" condition_args.append(bot_id) + if user_id: + condition += " AND user_id = ?" + condition_args.append(user_id) + msg_rows = msg_db.where_all( MessageEventModel(), condition, diff --git a/liteyuki/plugins/liteyuki_statistics/stat_matchers.py b/liteyuki/plugins/liteyuki_statistics/stat_matchers.py index 2dac3c88..74f29446 100644 --- a/liteyuki/plugins/liteyuki_statistics/stat_matchers.py +++ b/liteyuki/plugins/liteyuki_statistics/stat_matchers.py @@ -35,6 +35,11 @@ stat_msg = on_alconna( Args["group_id", str, "current"], help_text="指定群组" ), + Option( + "-u|--user", + Args["user_id", str, "current"], + help_text="指定用户" + ), alias={"msg", "m"}, help_text="查看统计次数内的消息" ) @@ -56,6 +61,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: Bot): group_id = result.other_args.get("group_id") bot_id = result.other_args.get("bot_id") + user_id = result.other_args.get("user_id") if group_id in ["current", "c"]: group_id = str(event_utils.get_group_id(event)) @@ -66,5 +72,8 @@ async def _(result: Arparma, event: T_MessageEvent, bot: Bot): if bot_id in ["current", "c"]: bot_id = str(bot.self_id) - img = await get_stat_msg_image(duration, period, group_id, bot_id, ulang) + if user_id in ["current", "c"]: + user_id = str(event_utils.get_user_id(event)) + + img = await get_stat_msg_image(duration=duration, period=period, group_id=group_id, bot_id=bot_id, user_id=user_id, ulang=ulang) await stat_msg.send(UniMessage.image(raw=img))