You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

retain_counts.py 462B

123456789101112131415161718192021
  1. import re
  2. from typing import List
  3. from million.model.message import Message
  4. def is_count(message: Message) -> bool:
  5. """
  6. Check if the message is a count
  7. """
  8. return message.content is not None and bool(re.search('(\d{2,}|^\d$)', message.content))
  9. def retain_counts(messages: List[Message]) -> List[Message]:
  10. """
  11. Retain only the messages that have a content
  12. """
  13. return [
  14. m for m in messages
  15. if is_count(m)
  16. ]