from math import floor import re from typing import Dict from million.model.message import Message memoization: Dict[Message, int] = {} # TODO WIP # - DNS to resolve audio, gif, pictures with counts def __compute__(msg: Message) -> int: value = __computeContent(msg) memoization[msg] = value return value def __computeContent(msg: Message) -> int: # TODO parse potential math expressions in content match = re.search(r"\d+", msg.content) if match: value = int(match[0]) else: value = None return value def reset(msg: Message) -> None: if msg in memoization: memoization.pop(msg) def reset() -> None: memoization.clear() def get(msg: Message) -> int: """ Returns the estimated value counted in this message """ return memoization.get(msg, __compute__(msg))