From 78627343f869ae72089c92557092a6874562ab2b Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 25 Jul 2022 17:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20dc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/dc.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 modules/dc.py diff --git a/modules/dc.py b/modules/dc.py new file mode 100644 index 0000000..ac38459 --- /dev/null +++ b/modules/dc.py @@ -0,0 +1,41 @@ +from pyrogram import Client, filters +from pyrogram.types import Message, Chat + +from init import user_me + + +def mention_chat(chat: Chat) -> str: + return f'{chat.title}' if chat.username else chat.title + + +def get_dc(message: Message): + dc = 0 + mention = "他" + if message.reply_to_message: + if message.reply_to_message.sender_chat: + mention = mention_chat(message.reply_to_message.sender_chat) + dc = message.reply_to_message.sender_chat.dc_id + elif message.reply_to_message.from_user: + mention = message.reply_to_message.from_user.mention + dc = message.reply_to_message.from_user.dc_id + elif message.from_user: + mention = message.from_user.mention + dc = message.from_user.dc_id + elif message.sender_chat: + mention = mention_chat(message.sender_chat) + dc = message.sender_chat.dc_id + return dc, mention + + +@Client.on_message(filters.incoming & filters.group & + filters.command(["dc", f"dc@{user_me.username}"])) +async def dc_command(_: Client, message: Message): + geo_dic = {'1': '美国-佛罗里达州-迈阿密', '2': '荷兰-阿姆斯特丹', '3': '美国-佛罗里达州-迈阿密', + '4': '荷兰-阿姆斯特丹', '5': '新加坡'} + dc, mention = get_dc(message) + if dc: + text = f"{mention}所在数据中心为: DC{dc}\n" \ + f"该数据中心位于 {geo_dic[str(dc)]}" + else: + text = f"{mention}需要先设置头像并且对我可见。" + await message.reply(text)