bot_pm.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
  2. # █▀█ █ █ █ █▀█ █▀▄ █
  3. # © Copyright 2022
  4. # https://t.me/hikariatama
  5. #
  6. # 🔒 Licensed under the GNU AGPLv3
  7. # 🌐 https://www.gnu.org/licenses/agpl-3.0.html
  8. import logging
  9. from typing import Union
  10. from .types import InlineUnit
  11. logger = logging.getLogger(__name__)
  12. class BotPM(InlineUnit):
  13. def set_fsm_state(self, user: Union[str, int], state: Union[str, bool]) -> bool:
  14. if not isinstance(user, (str, int)):
  15. logger.error("Invalid type for `user` in `set_fsm_state`")
  16. return False
  17. if not isinstance(state, (str, bool)):
  18. logger.error("Invalid type for `state` in `set_fsm_state`")
  19. return False
  20. if state:
  21. self.fsm[str(user)] = state
  22. elif str(user) in self.fsm:
  23. del self.fsm[str(user)]
  24. return True
  25. ss = set_fsm_state
  26. def get_fsm_state(self, user: Union[str, int]) -> Union[bool, str]:
  27. if not isinstance(user, (str, int)):
  28. logger.error("Invalid type for `user` in `get_fsm_state`")
  29. return False
  30. return self.fsm.get(str(user), False)
  31. gs = get_fsm_state