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

message_evaluation.py 616B

123456789101112131415161718
  1. from math import floor
  2. from million.model.message import Message
  3. # TODO WIP
  4. # - DNS to resolve audio, gif, pictures with counts
  5. def compute(msg: Message) -> int:
  6. """ Returns the estimated value counted in this message
  7. """
  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. return value