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
|
|
|
|
|
|
|
|
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,
|
2022-04-01 05:07:05 -04:00
|
|
|
help_text="Disconnect from KakaoTalk chats, but remain logged into profile-management commands",
|
|
|
|
)
|
|
|
|
async def disconnect(evt: CommandEvent) -> None:
|
|
|
|
if not evt.sender.is_connected:
|
|
|
|
await evt.reply("You are already disconnected from KakaoTalk chats")
|
|
|
|
return
|
2022-05-04 02:50:59 -04:00
|
|
|
if not evt.sender.config["bridge.remain_logged_in_on_disconnect"]:
|
|
|
|
await evt.reply(
|
|
|
|
"This instance of the KakaoTalk bridge does not allow being disconnected from KakaoTalk chats while logged in. "
|
|
|
|
"So, to disconnect, you must log out entirely with the `logout` command."
|
|
|
|
)
|
|
|
|
return
|
2022-04-01 05:07:05 -04:00
|
|
|
await evt.mark_read()
|
|
|
|
await evt.sender.client.disconnect()
|
|
|
|
await evt.reply("Successfully disconnected from KakaoTalk chats. To reconnect, use the `sync` command.")
|
|
|
|
|
|
|
|
|
|
|
|
@command_handler(
|
2022-05-06 02:46:52 -04:00
|
|
|
needs_auth=False,
|
2022-04-01 05:07:05 -04:00
|
|
|
management_only=True,
|
|
|
|
help_section=SECTION_CONNECTION,
|
2022-05-06 02:46:52 -04:00
|
|
|
help_text="Check if you're logged in to KakaoTalk and connected to chats",
|
2022-02-25 02:22:50 -05:00
|
|
|
)
|
2022-05-06 02:46:52 -04:00
|
|
|
async def ping(evt: CommandEvent) -> None:
|
|
|
|
if not await evt.sender.is_logged_in():
|
|
|
|
await evt.reply("You are **logged out** of KakaoTalk.")
|
2022-04-28 01:50:47 -04:00
|
|
|
else:
|
2022-05-06 02:46:52 -04:00
|
|
|
is_connected = evt.sender.is_connected and await evt.sender.client.is_connected()
|
2022-04-10 22:56:51 -04:00
|
|
|
await evt.reply(
|
2022-05-06 02:46:52 -04:00
|
|
|
"You are logged into KakaoTalk.\n\n"
|
|
|
|
f"You are {'connected to' if is_connected else '**disconnected** from'} KakaoTalk chats."
|
2022-04-01 05:07:05 -04:00
|
|
|
)
|
2022-03-09 02:25:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
@command_handler(
|
|
|
|
needs_auth=True,
|
|
|
|
management_only=True,
|
|
|
|
help_section=SECTION_CONNECTION,
|
2022-04-01 05:07:05 -04:00
|
|
|
help_text="(Re)connect to KakaoTalk chats & sync any missed chat updates",
|
2022-05-02 03:13:18 -04:00
|
|
|
help_args="[_number of channels to sync_]",
|
2022-05-09 03:25:15 -04:00
|
|
|
aliases=["connect"],
|
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:
|
2022-05-02 03:13:18 -04:00
|
|
|
await evt.reply("The number of channels to sync must either be an integer, or be left unspecified.")
|
2022-03-18 03:52:55 -04:00
|
|
|
return
|
|
|
|
|
2022-03-09 02:25:28 -05:00
|
|
|
await evt.mark_read()
|
2022-05-05 03:28:44 -04:00
|
|
|
if await evt.sender.connect_and_sync(sync_count, force_sync=True):
|
2022-03-11 03:40:20 -05:00
|
|
|
await evt.reply("Sync complete")
|
|
|
|
else:
|
|
|
|
await evt.reply("Sync failed")
|