PagerMaid-Pyro/pagermaid/modules/message.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

193 lines
7.2 KiB
Python
Raw Normal View History

2022-05-23 12:40:30 +00:00
""" Pagermaid message plugin. """
2024-08-13 10:38:13 +00:00
from pyrogram.enums import ChatType
2022-05-23 12:40:30 +00:00
from pyrogram.errors import Forbidden, FloodWait
from pagermaid.config import Config
from pagermaid.enums import Message
2022-05-23 12:40:30 +00:00
from pagermaid.listener import listener
from pagermaid.utils import lang
from pagermaid.utils.bot_utils import log
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(is_plugin=False, outgoing=True, command="id", description=lang("id_des"))
2022-06-20 13:55:14 +00:00
async def userid(message: Message):
2023-03-12 03:56:01 +00:00
"""Query the UserID of the sender of the message you replied to."""
2022-05-23 12:40:30 +00:00
reply = message.reply_to_message
2022-06-20 13:55:14 +00:00
text = f"Message ID: `{str(message.id)}" + "`\n\n"
2022-05-23 12:40:30 +00:00
text += "**Chat**\nid:`" + str(message.chat.id) + "`\n"
msg_from = message.chat
if msg_from.type == ChatType.PRIVATE:
2022-05-23 12:40:30 +00:00
try:
2022-06-20 13:55:14 +00:00
text += f"first_name: `{msg_from.first_name}" + "`\n"
2022-05-23 12:40:30 +00:00
except TypeError:
text += "**死号**\n"
if msg_from.last_name:
2022-06-20 13:55:14 +00:00
text += f"last_name: `{msg_from.last_name}" + "`\n"
2022-05-23 12:40:30 +00:00
if msg_from.username:
2022-06-20 13:55:14 +00:00
text += f"username: @{msg_from.username}" + "\n"
if msg_from.type in [ChatType.SUPERGROUP, ChatType.CHANNEL]:
2022-06-20 13:55:14 +00:00
text += f"title: `{msg_from.title}" + "`\n"
if message.topic:
text += f"topic title: `{message.topic.title}`\n"
text += f"topic ID: `{message.topic.id}`\n"
2022-05-23 12:40:30 +00:00
try:
if msg_from.username:
2022-06-20 13:55:14 +00:00
text += f"username: @{msg_from.username}" + "\n"
2022-05-23 12:40:30 +00:00
except AttributeError:
return await message.edit(lang("leave_not_group"))
2022-06-20 13:55:14 +00:00
text += f"protected: `{str(msg_from.has_protected_content)}" + "`\n"
2022-05-23 12:40:30 +00:00
if reply:
2023-03-12 03:56:01 +00:00
text += "\n" + lang("id_hint") + "\nMessage ID: `" + str(reply.id) + "`"
2024-02-13 13:12:28 +00:00
if reply.photo and reply.photo.file_id:
text += "\nphoto_id: `" + str(reply.photo.file_id) + "`"
if reply.video and reply.video.file_id:
text += "\nvideo_id: `" + str(reply.video.file_id) + "`"
if reply.document and reply.document.file_id:
text += "\ndocument_id: `" + str(reply.document.file_id) + "`"
2022-05-23 12:40:30 +00:00
try:
2022-07-08 14:26:36 +00:00
text += "\n\n**User**\nid: `" + str(reply.from_user.id) + "`"
2022-05-23 12:40:30 +00:00
if reply.from_user.is_bot:
text += f"\nis_bot: {lang('id_is_bot_yes')}"
try:
text += "\nfirst_name: `" + reply.from_user.first_name + "`"
except TypeError:
text += f"\n**{lang('id_da')}**"
if reply.from_user.last_name:
text += "\nlast_name: `" + reply.from_user.last_name + "`"
if reply.from_user.username:
text += "\nusername: @" + reply.from_user.username
if reply.from_user.dc_id:
text += "\ndc: `" + str(reply.from_user.dc_id) + "`"
except AttributeError:
pass
2022-07-08 14:26:36 +00:00
try:
text += "\n\n**Chat**\nid: `" + str(reply.sender_chat.id) + "`"
text += "\ntitle: `" + reply.sender_chat.title + "`"
if reply.sender_chat.username:
text += "\nusername: @" + reply.sender_chat.username
except AttributeError:
pass
2022-05-23 12:40:30 +00:00
if reply.forward_from_chat:
2023-03-12 03:56:01 +00:00
text += (
"\n\n**Forward From Channel**\n"
"id: `"
+ str(reply.forward_from_chat.id)
+ "`\ntitle: `"
+ reply.forward_from_chat.title
+ "`"
)
2022-09-01 03:04:28 +00:00
if reply.forward_from_chat.username:
text += "\nusername: @" + reply.forward_from_chat.username
if reply.forward_from_message_id:
text += "\nmessage_id: `" + str(reply.forward_from_message_id) + "`"
if reply.forward_sender_name:
text += "\npost_author: `" + reply.forward_sender_name + "`"
2022-05-23 12:40:30 +00:00
elif reply.forward_from:
2023-03-12 03:56:01 +00:00
text += (
"\n\n**Forward From User**\nid: `" + str(reply.forward_from.id) + "`"
)
2022-05-23 12:40:30 +00:00
try:
if reply.forward_from.is_bot:
text += f"\nis_bot: {lang('id_is_bot_yes')}"
try:
text += "\nfirst_name: `" + reply.forward_from.first_name + "`"
except TypeError:
text += f"\n**{lang('id_da')}**"
if reply.forward_from.last_name:
text += "\nlast_name: `" + reply.forward_from.last_name + "`"
if reply.forward_from.username:
text += "\nusername: @" + reply.forward_from.username
if reply.forward_from.dc_id:
text += "\ndc: `" + str(reply.forward_from.dc_id) + "`"
except AttributeError:
pass
2022-09-01 03:04:28 +00:00
elif reply.forward_sender_name:
2023-03-12 03:56:01 +00:00
text += (
"\n\n**Forward From User**\nsender_name: `"
+ str(reply.forward_sender_name)
+ "`"
)
2022-05-23 12:40:30 +00:00
await message.edit(text)
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
outgoing=True,
command="uslog",
description=lang("uslog_des"),
parameters="<string>",
)
2022-06-20 13:55:14 +00:00
async def uslog(message: Message):
2023-03-12 03:56:01 +00:00
"""Forwards a message into log group"""
2022-05-23 12:40:30 +00:00
if Config.LOG:
if message.reply_to_message:
reply_msg = message.reply_to_message
await reply_msg.forward(Config.LOG_ID)
elif message.arguments:
await log(message.arguments)
else:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("arg_error"))
await message.edit(lang("uslog_success"))
2022-05-23 12:40:30 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("uslog_log_disable"))
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
outgoing=True,
command="log",
description=lang("log_des"),
parameters="<string>",
)
2022-06-20 13:55:14 +00:00
async def logging(message: Message):
2023-03-12 03:56:01 +00:00
"""Forwards a message into log group"""
2022-05-23 12:40:30 +00:00
if Config.LOG:
if message.reply_to_message:
reply_msg = message.reply_to_message
await reply_msg.forward(Config.LOG_ID)
elif message.arguments:
await log(message.arguments)
else:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("arg_error"))
2022-05-23 12:40:30 +00:00
await message.safe_delete()
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("uslog_log_disable"))
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
outgoing=True,
command="re",
description=lang("re_des"),
parameters=lang("re_parameters"),
)
async def re(message: Message):
2023-03-12 03:56:01 +00:00
"""Forwards a message into this group"""
2022-06-20 13:55:14 +00:00
if reply := message.reply_to_message:
2023-03-12 03:56:01 +00:00
if message.arguments == "":
2022-05-23 12:40:30 +00:00
num = 1
else:
try:
num = int(message.arguments)
if num > 100:
2023-03-12 03:56:01 +00:00
await message.edit(lang("re_too_big"))
2022-06-20 13:55:14 +00:00
except Exception:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("re_arg_error"))
2022-05-23 12:40:30 +00:00
await message.safe_delete()
2022-06-20 13:55:14 +00:00
for _ in range(num):
2022-05-23 12:40:30 +00:00
try:
if not message.chat.has_protected_content:
2024-02-05 13:16:25 +00:00
await reply.forward(
reply.chat.id, message_thread_id=reply.message_thread_id
)
2022-05-23 12:40:30 +00:00
else:
2023-03-12 03:56:01 +00:00
await reply.copy(
reply.chat.id,
2024-02-04 07:33:01 +00:00
message_thread_id=message.message_thread_id,
2023-03-12 03:56:01 +00:00
)
except (Forbidden, FloodWait, Exception):
2022-05-23 12:40:30 +00:00
return
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("not_reply"))