conn.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # mautrix-signal - A Matrix-Signal puppeting bridge
  2. # Copyright (C) 2021 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from mautrix.types import EventID
  17. from mautrix.bridge.commands import HelpSection, command_handler
  18. from .typehint import CommandEvent
  19. SECTION_CONNECTION = HelpSection("Connection management", 15, "")
  20. @command_handler(needs_auth=False, management_only=True, help_section=SECTION_CONNECTION,
  21. help_text="Mark this room as your bridge notice room.")
  22. async def set_notice_room(evt: CommandEvent) -> None:
  23. evt.sender.notice_room = evt.room_id
  24. await evt.sender.update()
  25. await evt.reply("This room has been marked as your bridge notice room")
  26. @command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
  27. help_text="Relay messages in this room through your Signal account.")
  28. async def set_relay(evt: CommandEvent) -> EventID:
  29. if not evt.config["bridge.relay.enabled"]:
  30. return await evt.reply("Relay mode is not enabled in this instance of the bridge.")
  31. elif not evt.is_portal:
  32. return await evt.reply("This is not a portal room.")
  33. await evt.portal.set_relay_user(evt.sender)
  34. return await evt.reply("Messages from non-logged-in users in this room will now be bridged "
  35. "through your Signal account.")
  36. @command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
  37. help_text="Stop relaying messages in this room.")
  38. async def unset_relay(evt: CommandEvent) -> EventID:
  39. if not evt.config["bridge.relay.enabled"]:
  40. return await evt.reply("Relay mode is not enabled in this instance of the bridge.")
  41. elif not evt.is_portal:
  42. return await evt.reply("This is not a portal room.")
  43. elif not evt.portal.has_relay:
  44. return await evt.reply("This room does not have a relay user set.")
  45. await evt.portal.set_relay_user(None)
  46. return await evt.reply("Messages from non-logged-in users will no longer be bridged.")
  47. # @command_handler(needs_auth=False, management_only=True, help_section=SECTION_CONNECTION,
  48. # help_text="Check if you're logged into Twitter")
  49. # async def ping(evt: CommandEvent) -> None:
  50. # if evt.sender.username:
  51. # await evt.reply("")
  52. # user_info = await evt.sender.get_info()
  53. # await evt.reply(f"You're logged in as {user_info.name} "
  54. # f"([@{evt.sender.username}](https://twitter.com/{evt.sender.username}), "
  55. # f"user ID: {evt.sender.twid})")
  56. # TODO request syncs or something
  57. # @command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
  58. # help_text="Synchronize portals")
  59. # async def sync(evt: CommandEvent) -> None:
  60. # await evt.sender.sync()
  61. # await evt.reply("Synchronization complete")