iShotaBot/modules/dc.py

49 lines
1.6 KiB
Python
Raw Normal View History

2022-07-25 09:58:06 +00:00
from pyrogram import Client, filters
from pyrogram.types import Message, Chat
from init import bot
2022-07-25 09:58:06 +00:00
def mention_chat(chat: Chat) -> str:
2023-01-12 13:19:54 +00:00
return (
f'<a href="https://t.me/{chat.username}">{chat.title}</a>'
if chat.username
else chat.title
)
2022-07-25 09:58:06 +00:00
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
@bot.on_message(filters.incoming & filters.command(["dc", f"dc@{bot.me.username}"]))
2022-07-25 09:58:06 +00:00
async def dc_command(_: Client, message: Message):
2023-01-12 13:19:54 +00:00
geo_dic = {
"1": "美国-佛罗里达州-迈阿密",
"2": "荷兰-阿姆斯特丹",
"3": "美国-佛罗里达州-迈阿密",
"4": "荷兰-阿姆斯特丹",
"5": "新加坡",
}
2022-07-25 09:58:06 +00:00
dc, mention = get_dc(message)
if dc:
2023-05-27 13:45:56 +00:00
text = f"{mention}所在数据中心为: <b>DC{dc}</b>\n该数据中心位于 <b>{geo_dic[str(dc)]}</b>"
2022-07-25 09:58:06 +00:00
else:
text = f"{mention}需要先<b>设置头像并且对我可见。</b>"
await message.reply(text)