diff --git a/mautrix_telegram/commands/matrix_auth.py b/mautrix_telegram/commands/matrix_auth.py index 5cc00f01..6fca9f6b 100644 --- a/mautrix_telegram/commands/matrix_auth.py +++ b/mautrix_telegram/commands/matrix_auth.py @@ -81,6 +81,21 @@ async def ping_matrix(evt: CommandEvent) -> EventID: return await evt.reply("Your Matrix login is working.") +@command_handler(needs_auth=True, needs_matrix_puppeting=True, help_section=SECTION_AUTH, + help_text="Clear the Matrix sync token stored for your custom puppet.") +async def clear_cache_matrix(evt: CommandEvent) -> EventID: + puppet = pu.Puppet.get(evt.sender.tgid) + if not puppet.is_real_user: + return await evt.reply("You are not logged in with your Matrix account.") + try: + puppet.stop() + puppet.next_batch = None + await puppet.start() + except InvalidAccessToken: + return await evt.reply("Your access token is invalid.") + return await evt.reply("Cleared cache successfully.") + + async def enter_matrix_token(evt: CommandEvent) -> EventID: evt.sender.command_status = None diff --git a/mautrix_telegram/commands/telegram/misc.py b/mautrix_telegram/commands/telegram/misc.py index 873de207..60b12181 100644 --- a/mautrix_telegram/commands/telegram/misc.py +++ b/mautrix_telegram/commands/telegram/misc.py @@ -14,12 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from typing import List, Optional, Tuple +import logging import codecs import base64 import re from telethon.errors import (InviteHashInvalidError, InviteHashExpiredError, OptionsTooMuchError, - UserAlreadyParticipantError) + UserAlreadyParticipantError, ChatIdInvalidError) from telethon.tl.patched import Message from telethon.tl.types import (User as TLUser, TypeUpdates, MessageMediaGame, MessageMediaPoll, TypePeer) @@ -143,7 +144,11 @@ async def join(evt: CommandEvent) -> Optional[EventID]: return await evt.reply(f"Invited you to portal of {portal.title}") else: await evt.reply(f"Creating room for {chat.title}... This might take a while.") - await portal.create_matrix_room(evt.sender, chat, [evt.sender.mxid]) + try: + await portal.create_matrix_room(evt.sender, chat, [evt.sender.mxid]) + except ChatIdInvalidError as e: + logging.getLogger("mau.commands").info(updates.stringify()) + raise e return await evt.reply(f"Created room for {portal.title}") return None diff --git a/mautrix_telegram/portal/metadata.py b/mautrix_telegram/portal/metadata.py index 6d1f0563..0b56d143 100644 --- a/mautrix_telegram/portal/metadata.py +++ b/mautrix_telegram/portal/metadata.py @@ -545,7 +545,8 @@ class PortalMetadata(BasePortal, ABC): await self.main_intent.remove_room_alias(self._get_alias_localpart()) self.username = username or None if self.username: - await self.main_intent.add_room_alias(self.mxid, self._get_alias_localpart()) + await self.main_intent.add_room_alias(self.mxid, self._get_alias_localpart(), + override=True) if self.public_portals: await self.main_intent.set_join_rule(self.mxid, "public") else: