From e6d4e99e99df3e46a169073e0532f842393b4554 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 19 Sep 2022 00:59:15 +0800 Subject: [PATCH] =?UTF-8?q?get=5Fstatus=20=E8=8E=B7=E5=8F=96=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E6=88=96=E8=80=85=E4=BB=96=E4=BA=BA=E7=9A=84=E5=A4=A7?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E8=87=AA=E5=AE=9A=E4=B9=89=20emoji=20?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_status/main.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 get_status/main.py diff --git a/get_status/main.py b/get_status/main.py new file mode 100644 index 0000000..4699719 --- /dev/null +++ b/get_status/main.py @@ -0,0 +1,53 @@ +from datetime import datetime +from pytz import timezone + +from pyrogram.errors import DocumentInvalid +from pyrogram.raw.functions.users import GetUsers +from pyrogram.raw.types import InputUserSelf, InputUserFromMessage +from pyrogram.raw.types import EmojiStatus, EmojiStatusEmpty, EmojiStatusUntil + +from pagermaid.listener import listener +from pagermaid.enums import Client, Message + + +async def get_status_emoji(bot: Client, message: Message = None) -> str: + try: + peer = InputUserFromMessage( + peer=(await bot.resolve_peer(message.chat.id)), + msg_id=message.id, + user_id=message.from_user.id, + ) if message else InputUserSelf() + req = await bot.invoke(GetUsers(id=[peer])) + emoji_status = req[0].emoji_status + if not emoji_status or isinstance(emoji_status, EmojiStatusEmpty): + return "你还没有设置自定义 emoji 状态" + if isinstance(emoji_status, EmojiStatus): + return f"你的自定义 emoji 状态是 🔥" + if isinstance(emoji_status, EmojiStatusUntil): + time = datetime.strftime( + datetime.fromtimestamp( + emoji_status.until, timezone("Asia/Shanghai") + ), + "%Y-%m-%d %H:%M:%S" + ) + return f"你的自定义 emoji 状态是 🔥 (有效期至:{time})" + except DocumentInvalid: + return "无法获取自定义 emoji 状态,可能是状态已过期。" + except Exception as e: + raise FileNotFoundError from e + + +@listener(command="get_status", + need_admin=True, + description="获取自己或者他人的大会员自定义 emoji 状态") +async def get_emoji_status(bot: Client, message: Message): + """ 获取自己或者他人的大会员自定义 emoji 状态 """ + if not message.reply_to_message_id: + me = bot.me or await bot.get_me() + if not me.is_premium: + return await message.edit("你好像不是大会员。。。") + try: + string = await get_status_emoji(bot, message.reply_to_message) + except FileNotFoundError: + string = "获取自定义 emoji 状态失败。" + await message.edit(string)