Add command to backfill room history from Telegram
Currently supports backfilling one room at a time and backfills everything after the last bridged message.
This commit is contained in:
@@ -20,7 +20,8 @@ import base64
|
||||
import re
|
||||
|
||||
from telethon.errors import (InviteHashInvalidError, InviteHashExpiredError, OptionsTooMuchError,
|
||||
UserAlreadyParticipantError, ChatIdInvalidError)
|
||||
UserAlreadyParticipantError, ChatIdInvalidError,
|
||||
TakeoutInitDelayError)
|
||||
from telethon.tl.patched import Message
|
||||
from telethon.tl.types import (User as TLUser, TypeUpdates, MessageMediaGame, MessageMediaPoll,
|
||||
TypeInputPeer)
|
||||
@@ -35,7 +36,8 @@ from ... import puppet as pu, portal as po
|
||||
from ...abstract_user import AbstractUser
|
||||
from ...db import Message as DBMessage
|
||||
from ...types import TelegramID
|
||||
from ...commands import command_handler, CommandEvent, SECTION_MISC, SECTION_CREATING_PORTALS
|
||||
from ...commands import (command_handler, CommandEvent, SECTION_MISC, SECTION_CREATING_PORTALS,
|
||||
SECTION_PORTAL_MANAGEMENT)
|
||||
|
||||
|
||||
@command_handler(needs_auth=False,
|
||||
@@ -303,3 +305,15 @@ async def vote(evt: CommandEvent) -> EventID:
|
||||
return await evt.reply("You passed too many options.")
|
||||
# TODO use response
|
||||
return await evt.mark_read()
|
||||
|
||||
|
||||
@command_handler(help_section=SECTION_PORTAL_MANAGEMENT,
|
||||
help_args="<_number of messages_> [--takeout]",
|
||||
help_text="Backfill messages from Telegram history.")
|
||||
async def backfill(evt: CommandEvent) -> None:
|
||||
portal = po.Portal.get_by_mxid(evt.room_id)
|
||||
try:
|
||||
await portal.backfill(evt.sender)
|
||||
except TakeoutInitDelayError:
|
||||
await evt.reply("Please accept the data export request from a mobile device, "
|
||||
"then re-run the backfill command.")
|
||||
|
||||
Reference in New Issue
Block a user