From 432eba80a9324b8352dc34cfd1eaf83be312b9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=B9=E6=8C=87?= <2438650745@qq.com> Date: Fri, 29 Jul 2022 19:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=A8=80=E8=AE=B0=E5=BD=95=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=B6=88=E6=81=AF=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_history/chat_message_handle.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/basic_plugins/chat_history/chat_message_handle.py b/basic_plugins/chat_history/chat_message_handle.py index baef6a4c..b050490f 100644 --- a/basic_plugins/chat_history/chat_message_handle.py +++ b/basic_plugins/chat_history/chat_message_handle.py @@ -16,11 +16,12 @@ __zx_plugin_name__ = "消息统计" __plugin_usage__ = """ usage: 发言记录统计 - regex:(周|月)?消息排行(des|DES)?(n=[0-9]{1,2})? + regex:(周|月|日)?消息排行(des|DES)?(n=[0-9]{1,2})? 指令: 消息统计?(des)?(n=?) 周消息统计?(des)?(n=?) 月消息统计?(des)?(n=?) + 日消息统计?(des)?(n=?) 示例: 消息统计 消息统计des @@ -31,7 +32,8 @@ __plugin_des__ = "发言消息排行" __plugin_cmd__ = [ "消息统计", "周消息统计", - "月消息统计" + "月消息统计", + "日消息统计" ] __plugin_type__ = ("数据统计", 1) __plugin_version__ = 0.1 @@ -42,7 +44,7 @@ __plugin_settings__ = { } -msg_handler = on_regex(r"^(周|月)?消息统计(des|DES)?(n=[0-9]{1,2})?$", priority=5, block=True) +msg_handler = on_regex(r"^(周|月|日)?消息统计(des|DES)?(n=[0-9]{1,2})?$", priority=5, block=True) @msg_handler.handle() @@ -53,10 +55,14 @@ async def _(event: GroupMessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()) num = num.split("=")[-1] if num else 10 if num and is_number(num) and 10 < int(num) < 50: num = int(num) - if date in ["周"]: - date_scope = (datetime.now() - timedelta(days=7), datetime.now()) + time_now = datetime.now() + zero_today = time_now - timedelta(hours=time_now.hour, minutes=time_now.minute, seconds=time_now.second) + if date in ["日"]: + date_scope = (zero_today, time_now) + elif date in ["周"]: + date_scope = (time_now - timedelta(days=7), time_now) elif date in ["月"]: - date_scope = (datetime.now() - timedelta(days=30), datetime.now()) + date_scope = (time_now - timedelta(days=30), time_now) if rank_data := await ChatHistory.get_group_msg_rank( gid, num, order or "DESC", date_scope ): @@ -79,7 +85,7 @@ async def _(event: GroupMessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()) pytz.timezone("Asia/Shanghai") ).replace(microsecond=0) else: - date_scope = datetime.now().replace(microsecond=0) + date_scope = time_now.replace(microsecond=0) date_str = f"日期:{date_scope} - 至今" else: date_str = f"日期:{date_scope[0].replace(microsecond=0)} - {date_scope[1].replace(microsecond=0)}"