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

message_evaluation.py 797B

1234567891011121314151617181920212223242526
  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. """ Returns the estimated value counted in this message
  9. """
  10. value = None
  11. # Remove any number that is not a digit
  12. # TODO parse potential math expressions in content
  13. cleaned_content = ''.join([c for c in msg.content if c.isdigit()])
  14. try:
  15. value = floor(float(cleaned_content))
  16. except Exception as e:
  17. raise ValueError(
  18. f"Message {cleaned_content} does not contain a number ({e})")
  19. memoization[msg] = value
  20. return value
  21. def get(msg: Message) -> int:
  22. return memoization.get(msg, __compute__(msg))