支持 Topic group

This commit is contained in:
xtaodada 2022-11-24 15:08:30 +08:00
parent dd8aef67f5
commit 836ae880e6
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 29 additions and 6 deletions

10
init.py
View File

@ -1,15 +1,16 @@
import logging
import pyrogram
import httpx
from models.sqlite import Sqlite
from defs.glover import api_id, api_hash, ipv6
from scheduler import scheduler
from pyrogram import Client
from logging import getLogger, INFO, ERROR, StreamHandler, basicConfig
from coloredlogs import ColoredFormatter
from cashews import cache
from models.temp_fix import temp_fix
# Config cache
cache.setup("mem://")
# Enable logging
@ -36,7 +37,10 @@ class UserMe:
user_me = UserMe()
sqlite = Sqlite()
bot = Client("bot", api_id=api_id, api_hash=api_hash, ipv6=ipv6, plugins=dict(root="modules"))
bot = pyrogram.Client("bot", api_id=api_id, api_hash=api_hash, ipv6=ipv6, plugins=dict(root="modules"))
# temp fix topics group
setattr(pyrogram.types.Message, "old_parse", getattr(pyrogram.types.Message, "_parse"))
setattr(pyrogram.types.Message, "_parse", temp_fix)
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.72 Safari/537.36"
}

View File

@ -3,7 +3,7 @@ from sqlmodel import SQLModel
from models.models.lofter import Lofter
from models.models.fragment import Fragment
__all__ = ["Lofter", "Fragment"]
__all__ = ["Lofter", "Fragment", "Sqlite"]
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import sessionmaker

19
models/temp_fix.py Normal file
View File

@ -0,0 +1,19 @@
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 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
return parsed

View File

@ -1,5 +1,5 @@
pyrogram==2.0.59
tgcrypto==1.2.4
pyrogram==2.0.62
tgcrypto==1.2.5
httpx
pillow
cashews