🔖 Update to v1.2.15

Support topic group
This commit is contained in:
xtaodada 2022-11-15 10:52:29 +08:00
parent c1b0ee22d4
commit d215e293f8
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
6 changed files with 62 additions and 21 deletions

View File

@ -2,6 +2,7 @@ import contextlib
from typing import Callable, Awaitable, Set, Dict
import pyrogram.types
from coloredlogs import ColoredFormatter
from datetime import datetime, timezone
from logging import getLogger, StreamHandler, CRITICAL, INFO, basicConfig, DEBUG, Formatter, FileHandler
@ -12,7 +13,9 @@ from pagermaid.scheduler import scheduler
import pyromod.listen
from pyrogram import Client
pgm_version = "1.2.14"
from pyromod.listen.temp_fix import temp_fix
pgm_version = "1.2.15"
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
@ -60,6 +63,9 @@ bot = Client("pagermaid",
api_hash=Config.API_HASH,
ipv6=Config.IPV6,
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

View File

@ -69,13 +69,13 @@ async def profile(client: Client, message: Message):
f"{lang('profile_type')}: {user_type} \n" \
f"[{first_name}](tg://user?id={user.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:
await client.send_photo(
message.chat.id,
photo,
caption=caption,
reply_to_message_id=reply_to.id if reply_to else None
reply_to_message_id=reply_to
)
await message.delete()
return remove(photo)

View File

@ -1,11 +1,13 @@
""" Pagermaid message plugin. """
from pyrogram.enums import ChatType
from pyrogram.errors import Forbidden, FloodWait
from pyrogram.raw.functions.messages import ForwardMessages
from pagermaid import log
from pagermaid.config import Config
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",
@ -16,7 +18,7 @@ async def userid(message: Message):
text = f"Message ID: `{str(message.id)}" + "`\n\n"
text += "**Chat**\nid:`" + str(message.chat.id) + "`\n"
msg_from = message.chat
if msg_from.type == "private":
if msg_from.type == ChatType.PRIVATE:
try:
text += f"first_name: `{msg_from.first_name}" + "`\n"
except TypeError:
@ -25,7 +27,7 @@ async def userid(message: Message):
text += f"last_name: `{msg_from.last_name}" + "`\n"
if msg_from.username:
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"
try:
if msg_from.username:
@ -129,7 +131,7 @@ async def logging(message: Message):
@listener(is_plugin=False, outgoing=True, command="re",
description=lang('re_des'),
parameters=lang('re_parameters'))
async def re(message: Message):
async def re(bot: Client, message: Message):
""" Forwards a message into this group """
if reply := message.reply_to_message:
if message.arguments == '':
@ -145,16 +147,26 @@ async def re(message: Message):
for _ in range(num):
try:
if not message.chat.has_protected_content:
await reply.forward(reply.chat.id)
await forward_msg(bot, message.reply_to_message)
else:
await reply.copy(reply.chat.id)
except Forbidden:
return
except FloodWait:
return
except ValueError:
return
except Exception as e: # noqa
await reply.copy(reply.chat.id, reply_to_message_id=message.reply_to_top_message_id)
except (Forbidden, FloodWait, Exception):
return
else:
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,
)
)

View File

@ -160,4 +160,5 @@ async def send_prune_notify(bot: Client, message: Message, count_buffer, count):
return await bot.send_message(
message.chat.id,
f"{lang('spn_deleted')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}",
reply_to_message_id=message.reply_to_top_message_id,
)

View File

@ -7,6 +7,8 @@ from sys import exit
from platform import node
from getpass import getuser
from pyrogram.enums import ParseMode
from pagermaid.listener import listener
from pagermaid.enums import Message
from pagermaid.services import bot
@ -64,9 +66,11 @@ async def restart(message: Message):
parameters=lang('eval_parameters'))
async def sh_eval(message: Message):
""" Run python commands from Telegram. """
dev_mode = exists(f"data{sep}dev")
try:
assert dev_mode
cmd = message.text.split(" ", maxsplit=1)[1]
except IndexError:
except (IndexError, AssertionError):
return await message.edit(lang('eval_need_dev'))
old_stderr = sys.stderr
old_stdout = sys.stdout
@ -89,9 +93,9 @@ async def sh_eval(message: Message):
evaluation = stdout
else:
evaluation = "Success"
final_output = f"**>>>** ```{cmd}``` \n```{evaluation}```"
final_output = f"**>>>** `{cmd}` \n`{evaluation}`"
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)
else:
await message.edit(final_output)
@ -106,7 +110,7 @@ async def send_log(message: Message):
return await message.edit(lang("send_log_not_found"))
await upload_attachment("pagermaid.log.txt",
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",
caption=lang("send_log_caption"))
await message.safe_delete()

View 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