Fix sync-full command
This commit is contained in:
@@ -13,8 +13,10 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
from telethon.tl.functions.channels import GetFullChannelRequest
|
||||||
|
from telethon.tl.functions.messages import GetFullChatRequest
|
||||||
from telethon.errors import (ChatAdminRequiredError, UsernameInvalidError,
|
from telethon.errors import (ChatAdminRequiredError, UsernameInvalidError,
|
||||||
UsernameNotModifiedError, UsernameOccupiedError)
|
UsernameNotModifiedError, UsernameOccupiedError, RPCError)
|
||||||
|
|
||||||
from mautrix.types import EventID
|
from mautrix.types import EventID
|
||||||
|
|
||||||
@@ -44,17 +46,22 @@ async def sync_full(evt: CommandEvent) -> EventID:
|
|||||||
if not portal:
|
if not portal:
|
||||||
return await evt.reply("This is not a portal room.")
|
return await evt.reply("This is not a portal room.")
|
||||||
|
|
||||||
if evt.args[0] == "--usebot" and evt.sender.is_admin:
|
if len(evt.args) > 0 and evt.args[0] == "--usebot" and evt.sender.is_admin:
|
||||||
src = evt.tgbot
|
src = evt.tgbot
|
||||||
else:
|
else:
|
||||||
src = evt.tgbot if await evt.sender.needs_relaybot(portal) else evt.sender
|
src = evt.tgbot if await evt.sender.needs_relaybot(portal) else evt.sender
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entity = await src.client.get_entity(portal.peer)
|
if portal.peer_type == "channel":
|
||||||
except ValueError:
|
res = await src.client(GetFullChannelRequest(portal.peer))
|
||||||
|
elif portal.peer_type == "chat":
|
||||||
|
res = await src.client(GetFullChatRequest(portal.tgid))
|
||||||
|
else:
|
||||||
|
return await evt.reply("This is not a channel or chat portal.")
|
||||||
|
except (ValueError, RPCError):
|
||||||
return await evt.reply("Failed to get portal info from Telegram.")
|
return await evt.reply("Failed to get portal info from Telegram.")
|
||||||
|
|
||||||
await portal.update_matrix_room(src, entity)
|
await portal.update_matrix_room(src, res.full_chat)
|
||||||
return await evt.reply("Portal synced successfully.")
|
return await evt.reply("Portal synced successfully.")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user