Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

message_evaluation.py 801B

123456789101112131415161718192021222324252627
  1. from math import floor
  2. from typing import Dict
  3. from million.model.message import Message
  4. memoization: Dict[Message, int] = {}
  5. # TODO WIP
  6. # - DNS to resolve audio, gif, pictures with counts
  7. def __compute__(msg: Message) -> int:
  8. value = None
  9. # Remove any number that is not a digit
  10. # TODO parse potential math expressions in content
  11. cleaned_content = ''.join([c for c in msg.content if c.isdigit()])
  12. try:
  13. value = floor(float(cleaned_content))
  14. except Exception as e:
  15. raise ValueError(
  16. f"Message {cleaned_content} does not contain a number ({e})")
  17. memoization[msg] = value
  18. return value
  19. def get(msg: Message) -> int:
  20. """
  21. Returns the estimated value counted in this message
  22. """
  23. return memoization.get(msg, __compute__(msg))