mirror of
https://github.com/TeamPGM/PagerMaid-Pyro.git
synced 2024-11-24 14:39:28 +00:00
🔖 Update to v1.2.15
Support topic group
This commit is contained in:
parent
c1b0ee22d4
commit
d215e293f8
@ -2,6 +2,7 @@ import contextlib
|
|||||||
|
|
||||||
from typing import Callable, Awaitable, Set, Dict
|
from typing import Callable, Awaitable, Set, Dict
|
||||||
|
|
||||||
|
import pyrogram.types
|
||||||
from coloredlogs import ColoredFormatter
|
from coloredlogs import ColoredFormatter
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from logging import getLogger, StreamHandler, CRITICAL, INFO, basicConfig, DEBUG, Formatter, FileHandler
|
from logging import getLogger, StreamHandler, CRITICAL, INFO, basicConfig, DEBUG, Formatter, FileHandler
|
||||||
@ -12,7 +13,9 @@ from pagermaid.scheduler import scheduler
|
|||||||
import pyromod.listen
|
import pyromod.listen
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
pgm_version = "1.2.14"
|
from pyromod.listen.temp_fix import temp_fix
|
||||||
|
|
||||||
|
pgm_version = "1.2.15"
|
||||||
CMD_LIST = {}
|
CMD_LIST = {}
|
||||||
module_dir = __path__[0]
|
module_dir = __path__[0]
|
||||||
working_dir = getcwd()
|
working_dir = getcwd()
|
||||||
@ -60,6 +63,9 @@ bot = Client("pagermaid",
|
|||||||
api_hash=Config.API_HASH,
|
api_hash=Config.API_HASH,
|
||||||
ipv6=Config.IPV6,
|
ipv6=Config.IPV6,
|
||||||
proxy=Config.PROXY)
|
proxy=Config.PROXY)
|
||||||
|
# temp fix topics group
|
||||||
|
setattr(pyrogram.types.Message, "old_parse", getattr(pyrogram.types.Message, "_parse"))
|
||||||
|
setattr(pyrogram.types.Message, "_parse", temp_fix)
|
||||||
bot.job = scheduler
|
bot.job = scheduler
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,13 +69,13 @@ async def profile(client: Client, message: Message):
|
|||||||
f"{lang('profile_type')}: {user_type} \n" \
|
f"{lang('profile_type')}: {user_type} \n" \
|
||||||
f"[{first_name}](tg://user?id={user.id})"
|
f"[{first_name}](tg://user?id={user.id})"
|
||||||
photo = await client.download_media(user.photo.big_file_id)
|
photo = await client.download_media(user.photo.big_file_id)
|
||||||
reply_to = message.reply_to_message
|
reply_to = message.reply_to_message.id if message.reply_to_message else message.reply_to_top_message_id
|
||||||
try:
|
try:
|
||||||
await client.send_photo(
|
await client.send_photo(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
photo,
|
photo,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
reply_to_message_id=reply_to.id if reply_to else None
|
reply_to_message_id=reply_to
|
||||||
)
|
)
|
||||||
await message.delete()
|
await message.delete()
|
||||||
return remove(photo)
|
return remove(photo)
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
""" Pagermaid message plugin. """
|
""" Pagermaid message plugin. """
|
||||||
|
from pyrogram.enums import ChatType
|
||||||
from pyrogram.errors import Forbidden, FloodWait
|
from pyrogram.errors import Forbidden, FloodWait
|
||||||
|
from pyrogram.raw.functions.messages import ForwardMessages
|
||||||
|
|
||||||
from pagermaid import log
|
from pagermaid import log
|
||||||
from pagermaid.config import Config
|
from pagermaid.config import Config
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, Message
|
from pagermaid.utils import lang
|
||||||
|
from pagermaid.enums import Client, Message
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=False, outgoing=True, command="id",
|
@listener(is_plugin=False, outgoing=True, command="id",
|
||||||
@ -16,7 +18,7 @@ async def userid(message: Message):
|
|||||||
text = f"Message ID: `{str(message.id)}" + "`\n\n"
|
text = f"Message ID: `{str(message.id)}" + "`\n\n"
|
||||||
text += "**Chat**\nid:`" + str(message.chat.id) + "`\n"
|
text += "**Chat**\nid:`" + str(message.chat.id) + "`\n"
|
||||||
msg_from = message.chat
|
msg_from = message.chat
|
||||||
if msg_from.type == "private":
|
if msg_from.type == ChatType.PRIVATE:
|
||||||
try:
|
try:
|
||||||
text += f"first_name: `{msg_from.first_name}" + "`\n"
|
text += f"first_name: `{msg_from.first_name}" + "`\n"
|
||||||
except TypeError:
|
except TypeError:
|
||||||
@ -25,7 +27,7 @@ async def userid(message: Message):
|
|||||||
text += f"last_name: `{msg_from.last_name}" + "`\n"
|
text += f"last_name: `{msg_from.last_name}" + "`\n"
|
||||||
if msg_from.username:
|
if msg_from.username:
|
||||||
text += f"username: @{msg_from.username}" + "\n"
|
text += f"username: @{msg_from.username}" + "\n"
|
||||||
if msg_from.type in ["supergroup", "channel"]:
|
if msg_from.type in [ChatType.SUPERGROUP, ChatType.CHANNEL]:
|
||||||
text += f"title: `{msg_from.title}" + "`\n"
|
text += f"title: `{msg_from.title}" + "`\n"
|
||||||
try:
|
try:
|
||||||
if msg_from.username:
|
if msg_from.username:
|
||||||
@ -129,7 +131,7 @@ async def logging(message: Message):
|
|||||||
@listener(is_plugin=False, outgoing=True, command="re",
|
@listener(is_plugin=False, outgoing=True, command="re",
|
||||||
description=lang('re_des'),
|
description=lang('re_des'),
|
||||||
parameters=lang('re_parameters'))
|
parameters=lang('re_parameters'))
|
||||||
async def re(message: Message):
|
async def re(bot: Client, message: Message):
|
||||||
""" Forwards a message into this group """
|
""" Forwards a message into this group """
|
||||||
if reply := message.reply_to_message:
|
if reply := message.reply_to_message:
|
||||||
if message.arguments == '':
|
if message.arguments == '':
|
||||||
@ -145,16 +147,26 @@ async def re(message: Message):
|
|||||||
for _ in range(num):
|
for _ in range(num):
|
||||||
try:
|
try:
|
||||||
if not message.chat.has_protected_content:
|
if not message.chat.has_protected_content:
|
||||||
await reply.forward(reply.chat.id)
|
await forward_msg(bot, message.reply_to_message)
|
||||||
else:
|
else:
|
||||||
await reply.copy(reply.chat.id)
|
await reply.copy(reply.chat.id, reply_to_message_id=message.reply_to_top_message_id)
|
||||||
except Forbidden:
|
except (Forbidden, FloodWait, Exception):
|
||||||
return
|
|
||||||
except FloodWait:
|
|
||||||
return
|
|
||||||
except ValueError:
|
|
||||||
return
|
|
||||||
except Exception as e: # noqa
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
await message.edit(lang('not_reply'))
|
await message.edit(lang('not_reply'))
|
||||||
|
|
||||||
|
|
||||||
|
async def forward_msg(bot: Client, message: Message):
|
||||||
|
message_ids = [message.id]
|
||||||
|
await bot.invoke(
|
||||||
|
ForwardMessages(
|
||||||
|
to_peer=await bot.resolve_peer(message.chat.id),
|
||||||
|
from_peer=await bot.resolve_peer(message.chat.id),
|
||||||
|
id=message_ids,
|
||||||
|
silent=None,
|
||||||
|
random_id=[bot.rnd_id() for _ in message_ids],
|
||||||
|
schedule_date=None,
|
||||||
|
noforwards=None,
|
||||||
|
top_msg_id=message.reply_to_top_message_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@ -160,4 +160,5 @@ async def send_prune_notify(bot: Client, message: Message, count_buffer, count):
|
|||||||
return await bot.send_message(
|
return await bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"{lang('spn_deleted')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}",
|
f"{lang('spn_deleted')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}",
|
||||||
|
reply_to_message_id=message.reply_to_top_message_id,
|
||||||
)
|
)
|
||||||
|
@ -7,6 +7,8 @@ from sys import exit
|
|||||||
from platform import node
|
from platform import node
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
|
|
||||||
|
from pyrogram.enums import ParseMode
|
||||||
|
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.enums import Message
|
from pagermaid.enums import Message
|
||||||
from pagermaid.services import bot
|
from pagermaid.services import bot
|
||||||
@ -64,9 +66,11 @@ async def restart(message: Message):
|
|||||||
parameters=lang('eval_parameters'))
|
parameters=lang('eval_parameters'))
|
||||||
async def sh_eval(message: Message):
|
async def sh_eval(message: Message):
|
||||||
""" Run python commands from Telegram. """
|
""" Run python commands from Telegram. """
|
||||||
|
dev_mode = exists(f"data{sep}dev")
|
||||||
try:
|
try:
|
||||||
|
assert dev_mode
|
||||||
cmd = message.text.split(" ", maxsplit=1)[1]
|
cmd = message.text.split(" ", maxsplit=1)[1]
|
||||||
except IndexError:
|
except (IndexError, AssertionError):
|
||||||
return await message.edit(lang('eval_need_dev'))
|
return await message.edit(lang('eval_need_dev'))
|
||||||
old_stderr = sys.stderr
|
old_stderr = sys.stderr
|
||||||
old_stdout = sys.stdout
|
old_stdout = sys.stdout
|
||||||
@ -89,9 +93,9 @@ async def sh_eval(message: Message):
|
|||||||
evaluation = stdout
|
evaluation = stdout
|
||||||
else:
|
else:
|
||||||
evaluation = "Success"
|
evaluation = "Success"
|
||||||
final_output = f"**>>>** ```{cmd}``` \n```{evaluation}```"
|
final_output = f"**>>>** `{cmd}` \n`{evaluation}`"
|
||||||
if len(final_output) > 4096:
|
if len(final_output) > 4096:
|
||||||
message = await message.edit(f"**>>>** ```{cmd}```")
|
message = await message.edit(f"**>>>** `{cmd}`", parse_mode=ParseMode.MARKDOWN)
|
||||||
await attach_log(evaluation, message.chat.id, "output.log", message.id)
|
await attach_log(evaluation, message.chat.id, "output.log", message.id)
|
||||||
else:
|
else:
|
||||||
await message.edit(final_output)
|
await message.edit(final_output)
|
||||||
@ -106,7 +110,7 @@ async def send_log(message: Message):
|
|||||||
return await message.edit(lang("send_log_not_found"))
|
return await message.edit(lang("send_log_not_found"))
|
||||||
await upload_attachment("pagermaid.log.txt",
|
await upload_attachment("pagermaid.log.txt",
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
message.reply_to_message_id,
|
message.reply_to_message_id or message.reply_to_top_message_id,
|
||||||
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
|
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
|
||||||
caption=lang("send_log_caption"))
|
caption=lang("send_log_caption"))
|
||||||
await message.safe_delete()
|
await message.safe_delete()
|
||||||
|
18
pyromod/listen/temp_fix.py
Normal file
18
pyromod/listen/temp_fix.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import pyrogram
|
||||||
|
|
||||||
|
|
||||||
|
async def temp_fix(
|
||||||
|
client: "pyrogram.Client",
|
||||||
|
message: pyrogram.raw.base.Message,
|
||||||
|
users: dict,
|
||||||
|
chats: dict,
|
||||||
|
is_scheduled: bool = False,
|
||||||
|
replies: int = 1
|
||||||
|
):
|
||||||
|
parsed = await pyrogram.types.Message.old_parse(client, message, users, chats, is_scheduled, replies) # noqa
|
||||||
|
if isinstance(message, pyrogram.raw.types.Message) and message.reply_to \
|
||||||
|
and message.reply_to.forum_topic and not message.reply_to.reply_to_top_id:
|
||||||
|
parsed.reply_to_top_message_id = parsed.reply_to_message_id
|
||||||
|
parsed.reply_to_message_id = None
|
||||||
|
parsed.reply_to_message = None
|
||||||
|
return parsed
|
Loading…
Reference in New Issue
Block a user