🔖 Update to v1.2.24

This commit is contained in:
xtaodada 2023-01-16 10:51:37 +08:00
parent 7465805535
commit 44125f4b19
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 84 additions and 78 deletions

View File

@ -2,7 +2,6 @@ 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
@ -13,9 +12,7 @@ from pagermaid.scheduler import scheduler
import pyromod.listen import pyromod.listen
from pyrogram import Client from pyrogram import Client
from pyromod.listen.temp_fix import temp_fix, read_chat_history pgm_version = "1.2.24"
pgm_version = "1.2.23"
CMD_LIST = {} CMD_LIST = {}
module_dir = __path__[0] module_dir = __path__[0]
working_dir = getcwd() working_dir = getcwd()
@ -66,10 +63,6 @@ bot = Client(
proxy=Config.PROXY, proxy=Config.PROXY,
app_version=f"PagerMaid {pgm_version}", app_version=f"PagerMaid {pgm_version}",
) )
# temp fix topics group
setattr(pyrogram.types.Message, "old_parse", getattr(pyrogram.types.Message, "_parse"))
setattr(pyrogram.types.Message, "_parse", temp_fix)
pyrogram.Client.read_chat_history = read_chat_history
bot.job = scheduler bot.job = scheduler

View File

@ -21,6 +21,7 @@ along with pyromod. If not, see <https://www.gnu.org/licenses/>.
import asyncio import asyncio
import contextlib import contextlib
import functools import functools
from datetime import datetime
from typing import Optional, List, Union from typing import Optional, List, Union
import pyrogram import pyrogram
@ -94,6 +95,34 @@ class Client:
def conversation(self, chat_id: Union[int, str], once_timeout: int = 60, filters=None): def conversation(self, chat_id: Union[int, str], once_timeout: int = 60, filters=None):
return Conversation(self, chat_id, once_timeout, filters) return Conversation(self, chat_id, once_timeout, filters)
@patchable
async def read_chat_history(
self: "pyrogram.Client",
chat_id: Union[int, str],
max_id: int = 0
) -> bool:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, pyrogram.raw.types.InputPeerChannel):
with contextlib.suppress(pyrogram.errors.BadRequest): # noqa
topics: pyrogram.raw.types.messages.ForumTopics = await self.invoke(
pyrogram.raw.functions.channels.GetForumTopics(
channel=peer, # noqa
offset_date=0,
offset_id=0,
offset_topic=0,
limit=0
)
)
for i in topics.topics:
await self.invoke(
pyrogram.raw.functions.messages.ReadDiscussion(
peer=peer,
msg_id=i.id,
read_max_id=i.read_inbox_max_id + i.unread_count,
)
)
return await self.oldread_chat_history(chat_id, max_id) # noqa
@patch(pyrogram.handlers.message_handler.MessageHandler) @patch(pyrogram.handlers.message_handler.MessageHandler)
class MessageHandler: class MessageHandler:
@ -200,7 +229,7 @@ class Message(pyrogram.types.Message):
message_ids=self.id, message_ids=self.id,
revoke=revoke revoke=revoke
) )
except Exception as e: # noqa except Exception: # noqa
return False return False
@patchable @patchable
@ -318,6 +347,59 @@ class Message(pyrogram.types.Message):
edit = edit_text edit = edit_text
@patchable
@staticmethod
async def _parse(
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 hasattr(message.reply_to, "forum_topic") 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
# make message.text as message.caption
parsed.text = parsed.text or parsed.caption
return parsed
@patchable
async def copy(
self,
chat_id: Union[int, str],
caption: str = None,
parse_mode: Optional["pyrogram.enums.ParseMode"] = None,
caption_entities: List["pyrogram.types.MessageEntity"] = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
schedule_date: datetime = None,
protect_content: bool = None,
reply_markup: Union[
"pyrogram.types.InlineKeyboardMarkup",
"pyrogram.types.ReplyKeyboardMarkup",
"pyrogram.types.ReplyKeyboardRemove",
"pyrogram.types.ForceReply"
] = object
) -> Union["pyrogram.types.Message", List["pyrogram.types.Message"]]:
if self.media:
self.text = None
return await self.oldcopy(
chat_id,
caption,
parse_mode,
caption_entities,
disable_notification,
reply_to_message_id,
schedule_date,
protect_content,
reply_markup,
) # noqa
@patch(pyrogram.dispatcher.Dispatcher) # noqa @patch(pyrogram.dispatcher.Dispatcher) # noqa
class Dispatcher(pyrogram.dispatcher.Dispatcher): # noqa class Dispatcher(pyrogram.dispatcher.Dispatcher): # noqa

View File

@ -1,69 +0,0 @@
import contextlib
from typing import Union
import pyrogram
from pyrogram.errors import BadRequest
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 hasattr(message.reply_to, "forum_topic") 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
# make message.text as message.caption
parsed.text = parsed.text or parsed.caption
return parsed
async def read_chat_history(
self: "pyrogram.Client",
chat_id: Union[int, str],
max_id: int = 0
) -> bool:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, pyrogram.raw.types.InputPeerChannel):
q = pyrogram.raw.functions.channels.ReadHistory(
channel=peer,
max_id=max_id
)
else:
q = pyrogram.raw.functions.messages.ReadHistory(
peer=peer,
max_id=max_id
)
await self.invoke(q)
if isinstance(peer, pyrogram.raw.types.InputPeerChannel):
with contextlib.suppress(BadRequest):
topics: pyrogram.raw.types.messages.ForumTopics = await self.invoke(
pyrogram.raw.functions.channels.GetForumTopics(
channel=peer,
offset_date=0,
offset_id=0,
offset_topic=0,
limit=0
)
)
for i in topics.topics:
await self.invoke(
pyrogram.raw.functions.messages.ReadDiscussion(
peer=peer,
msg_id=i.id,
read_max_id=i.read_inbox_max_id + i.unread_count,
)
)
return True