conn.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # mautrix-twitter - A Matrix-Twitter DM puppeting bridge
  2. # Copyright (C) 2020 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 mauigpapi.errors import IGNotLoggedInError
  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=False, management_only=True, help_section=SECTION_CONNECTION,
  27. help_text="Check if you're logged into Instagram")
  28. async def ping(evt: CommandEvent) -> None:
  29. if not await evt.sender.is_logged_in():
  30. await evt.reply("You're not logged into Instagram")
  31. return
  32. try:
  33. user_info = await evt.sender.client.current_user()
  34. except IGNotLoggedInError:
  35. await evt.reply("You have been logged out")
  36. await evt.sender.logout()
  37. else:
  38. user = user_info.user
  39. await evt.reply(f"You're logged in as {user.full_name} ([@{user.username}]"
  40. f"(https://instagram.com/{user.username}), user ID: {user.pk})")
  41. @command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
  42. help_text="Synchronize portals")
  43. async def sync(evt: CommandEvent) -> None:
  44. await evt.sender.sync()
  45. await evt.reply("Synchronization complete")
  46. # TODO connect/disconnect MQTT commands