Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,61 @@
TextWithEntities,
)
import re
import struct
from functools import wraps
import telethon.errors.rpcerrorlist
from telethon.tl.tlobject import TLRequest, TLObject


class GetForumTopicsRequest(TLRequest):
"""
Raw TL request for channels.getForumTopics.
Telethon 1.42 does not generate a wrapper for this method,
so we define it manually using the TL schema:
channels.getForumTopics#de560d1 flags:# channel:InputChannel
q:flags.0?string offset_date:int offset_id:int
offset_topic:int limit:int = messages.ForumTopics;
"""
CONSTRUCTOR_ID = 0x0de560d1
SUBCLASS_OF_ID = 0x0

def __init__(self, channel, offset_date, offset_id, offset_topic, limit, q=None):
self.channel = channel
self.q = q
self.offset_date = offset_date
self.offset_id = offset_id
self.offset_topic = offset_topic
self.limit = limit

async def resolve(self, client, utils):
self.channel = utils.get_input_channel(await client.get_input_entity(self.channel))

def _bytes(self):
flags = 0
if self.q is not None:
flags |= 1
return b''.join((
struct.pack('<I', self.CONSTRUCTOR_ID),
struct.pack('<I', flags),
self.channel._bytes(),
TLObject.serialize_bytes(self.q) if self.q is not None else b'',
struct.pack('<i', self.offset_date),
struct.pack('<i', self.offset_id),
struct.pack('<i', self.offset_topic),
struct.pack('<i', self.limit),
))

@classmethod
def from_reader(cls, reader):
flags = reader.read_int()
channel = reader.tgread_object()
q = reader.tgread_string() if flags & 1 else None
offset_date = reader.read_int()
offset_id = reader.read_int()
offset_topic = reader.read_int()
limit = reader.read_int()
return cls(channel=channel, offset_date=offset_date, offset_id=offset_id,
offset_topic=offset_topic, limit=limit, q=q)


class ValidationError(Exception):
Expand Down Expand Up @@ -1212,7 +1265,7 @@ async def list_topics(
return "The specified supergroup does not have forum topics enabled."

result = await client(
functions.channels.GetForumTopicsRequest(
GetForumTopicsRequest(
channel=entity,
offset_date=0,
offset_id=0,
Expand Down
Loading