選択できるのは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