matrix-appservice-kakaotalk/matrix_appservice_kakaotalk/commands/conn.py

76 lines
2.5 KiB
Python
Raw Normal View History

2022-02-25 02:22:50 -05:00
# matrix-appservice-kakaotalk - A Matrix-KakaoTalk puppeting bridge.
# Copyright (C) 2022 Tulir Asokan, Andrew Ferrazzutti
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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/>.
from mautrix.bridge.commands import HelpSection, command_handler
from .typehint import CommandEvent
2022-03-18 03:52:55 -04:00
from ..kt.client.errors import CommandException
2022-02-25 02:22:50 -05:00
SECTION_CONNECTION = HelpSection("Connection management", 15, "")
@command_handler(
needs_auth=False,
management_only=True,
help_section=SECTION_CONNECTION,
help_text="Mark this room as your bridge notice room",
)
async def set_notice_room(evt: CommandEvent) -> None:
evt.sender.notice_room = evt.room_id
await evt.sender.save()
await evt.reply("This room has been marked as your bridge notice room")
@command_handler(
needs_auth=True,
management_only=True,
help_section=SECTION_CONNECTION,
help_text="Check if you're logged into KakaoTalk",
)
async def ping(evt: CommandEvent) -> None:
if not await evt.sender.is_logged_in():
await evt.reply("You're not logged into KakaoTalk")
return
2022-03-09 02:26:17 -05:00
await evt.mark_read()
2022-03-18 03:52:55 -04:00
try:
own_info = await evt.sender.get_own_info()
await evt.reply(f"You're logged in as {own_info.nickname} (user ID {evt.sender.ktid})")
except CommandException as e:
await evt.reply(f"Error from KakaoTalk: {e}")
2022-03-09 02:25:28 -05:00
@command_handler(
needs_auth=True,
management_only=True,
help_section=SECTION_CONNECTION,
help_text="Resync chats",
2022-03-18 03:52:55 -04:00
help_args="[count]",
2022-03-09 02:25:28 -05:00
)
async def sync(evt: CommandEvent) -> None:
2022-03-18 03:52:55 -04:00
try:
sync_count = int(evt.args[0])
except IndexError:
sync_count = None
except ValueError:
await evt.reply("**Usage:** `$cmdprefix+sp logout [--reset-device]`")
return
2022-03-09 02:25:28 -05:00
await evt.mark_read()
2022-03-18 03:52:55 -04:00
if await evt.sender.connect_and_sync(sync_count):
2022-03-11 03:40:20 -05:00
await evt.reply("Sync complete")
else:
await evt.reply("Sync failed")