From e71c441b21c1dc8716020eefba06ab51b29e8aab Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:10:41 +0800 Subject: [PATCH] =?UTF-8?q?annualreport=20=E8=87=AA=E5=8A=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=B9=B4=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- annualreport/main.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/annualreport/main.py b/annualreport/main.py index 7cd9c1fc..b13f8e81 100644 --- a/annualreport/main.py +++ b/annualreport/main.py @@ -2,6 +2,7 @@ # Hello 2023 from os.path import getmtime +from datetime import datetime from time import time from pyrogram.enums import ChatType @@ -16,7 +17,7 @@ async def get_chat_count(): private, group, bots, channel = 0, 0, 0, 0 - async for dialog in bot.get_dialogs(): + for dialog in await bot.get_dialogs_list(): if dialog.chat.type == ChatType.BOT: bots += 1 if dialog.chat.type == ChatType.CHANNEL: @@ -41,15 +42,28 @@ async def get_blocked_count(): async def get_hitokoto(request: AsyncClient): try: htk = (await request.get("https://v1.hitokoto.cn/?charset=utf-8")).json() - text = f"\"{htk['hitokoto']}\" —— {htk['from_who']}「{htk['from']}」" + text = f"\"{htk['hitokoto']}\" —— " + if htk['from_who']: + text += f"{htk['from_who']}" + if htk['from']: + text += f"「{htk['from']}」" except Exception: text = '"用代码表达言语的魅力,用代码书写山河的壮丽。" —— 一言「一言开发者中心」' return text +async def get_year() -> str: + now = datetime.now() + year = now.year + if now.month == 1: + year -= 1 + return str(year) + + @listener(command="annualreport", description="TG年度报告") async def annualreport(client: Client, message: Message, request: AsyncClient): await message.edit("加载中请稍候。。。") + year = await get_year() private, group, bots, channel = await get_chat_count() days = int((time() - getmtime("LICENSE")) / 86400) plg = sorted(__list_plugins()) @@ -71,7 +85,7 @@ async def annualreport(client: Client, message: Message, request: AsyncClient): ) htks = await get_hitokoto(request) msg = f"""{user} 的年度报告 -2022 一路上,你充实而满足 +{year} 一路上,你充实而满足 此Pagermaid-Pyro实例陪伴了你的TG {days} 天,安装了 {len(plg)} 个插件 为你的TG使用体验增光添彩