bot_pm.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # ©️ Dan Gazizullin, 2021-2022
  2. # This file is a part of Hikka Userbot
  3. # 🌐 https://github.com/hikariatama/Hikka
  4. # You can redistribute it and/or modify it under the terms of the GNU AGPLv3
  5. # 🔑 https://www.gnu.org/licenses/agpl-3.0.html
  6. import logging
  7. import typing
  8. from .types import InlineUnit
  9. logger = logging.getLogger(__name__)
  10. class BotPM(InlineUnit):
  11. def set_fsm_state(
  12. self,
  13. user: typing.Union[str, int],
  14. state: typing.Union[str, bool],
  15. ) -> bool:
  16. if not isinstance(user, (str, int)):
  17. logger.error(
  18. "Invalid type for `user` in `set_fsm_state`. Expected `str` or `int`,"
  19. " got %s",
  20. type(user),
  21. )
  22. return False
  23. if not isinstance(state, (str, bool)):
  24. logger.error(
  25. "Invalid type for `state` in `set_fsm_state`. Expected `str` or `bool`,"
  26. " got %s",
  27. type(state),
  28. )
  29. return False
  30. if state:
  31. self.fsm[str(user)] = state
  32. elif str(user) in self.fsm:
  33. del self.fsm[str(user)]
  34. return True
  35. ss = set_fsm_state
  36. def get_fsm_state(self, user: typing.Union[str, int]) -> typing.Union[bool, str]:
  37. if not isinstance(user, (str, int)):
  38. logger.error(
  39. "Invalid type for `user` in `get_fsm_state`. Expected `str` or `int`,"
  40. " got %s",
  41. type(user),
  42. )
  43. return False
  44. return self.fsm.get(str(user), False)
  45. gs = get_fsm_state