conn.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(
  21. needs_auth=False,
  22. management_only=True,
  23. help_section=SECTION_CONNECTION,
  24. help_text="Mark this room as your bridge notice room.",
  25. )
  26. async def set_notice_room(evt: CommandEvent) -> None:
  27. evt.sender.notice_room = evt.room_id
  28. await evt.sender.update()
  29. await evt.reply("This room has been marked as your bridge notice room")
  30. @command_handler(
  31. needs_auth=True,
  32. management_only=False,
  33. help_section=SECTION_CONNECTION,
  34. help_text="Relay messages in this room through your Signal account.",
  35. )
  36. async def set_relay(evt: CommandEvent) -> EventID:
  37. if not evt.config["bridge.relay.enabled"]:
  38. return await evt.reply("Relay mode is not enabled in this instance of the bridge.")
  39. elif not evt.is_portal:
  40. return await evt.reply("This is not a portal room.")
  41. await evt.portal.set_relay_user(evt.sender)
  42. return await evt.reply(
  43. "Messages from non-logged-in users in this room will now be bridged "
  44. "through your Signal account."
  45. )
  46. @command_handler(
  47. needs_auth=True,
  48. management_only=False,
  49. help_section=SECTION_CONNECTION,
  50. help_text="Stop relaying messages in this room.",
  51. )
  52. async def unset_relay(evt: CommandEvent) -> EventID:
  53. if not evt.config["bridge.relay.enabled"]:
  54. return await evt.reply("Relay mode is not enabled in this instance of the bridge.")
  55. elif not evt.is_portal:
  56. return await evt.reply("This is not a portal room.")
  57. elif not evt.portal.has_relay:
  58. return await evt.reply("This room does not have a relay user set.")
  59. await evt.portal.set_relay_user(None)
  60. return await evt.reply("Messages from non-logged-in users will no longer be bridged.")
  61. # @command_handler(needs_auth=False, management_only=True, help_section=SECTION_CONNECTION,
  62. # help_text="Check if you're logged into Twitter")
  63. # async def ping(evt: CommandEvent) -> None:
  64. # if evt.sender.username:
  65. # await evt.reply("")
  66. # user_info = await evt.sender.get_info()
  67. # await evt.reply(f"You're logged in as {user_info.name} "
  68. # f"([@{evt.sender.username}](https://twitter.com/{evt.sender.username}), "
  69. # f"user ID: {evt.sender.twid})")
  70. # TODO request syncs or something
  71. # @command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
  72. # help_text="Synchronize portals")
  73. # async def sync(evt: CommandEvent) -> None:
  74. # await evt.sender.sync()
  75. # await evt.reply("Synchronization complete")