您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

message_evaluation.py 852B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from math import floor
  2. import re
  3. from typing import Dict
  4. from million.model.message import Message
  5. memoization: Dict[Message, int] = {}
  6. # TODO WIP
  7. # - DNS to resolve audio, gif, pictures with counts
  8. def __compute__(msg: Message) -> int:
  9. value = __computeContent(msg)
  10. memoization[msg] = value
  11. return value
  12. def __computeContent(msg: Message) -> int:
  13. # TODO parse potential math expressions in content
  14. match = re.search(r"\d+", msg.content)
  15. if match:
  16. value = int(match[0])
  17. else:
  18. value = None
  19. return value
  20. def reset(msg: Message) -> None:
  21. if msg in memoization:
  22. memoization.pop(msg)
  23. def reset() -> None:
  24. memoization.clear()
  25. def get(msg: Message) -> int:
  26. """
  27. Returns the estimated value counted in this message
  28. """
  29. return memoization.get(msg, __compute__(msg))