wrongmove/crawler/notifications.py

27 lines
783 B
Python

from abc import abstractmethod
from enum import StrEnum
import apprise
from functools import lru_cache
class Surface:
@abstractmethod
def connection_string(self) -> str | None:
...
class Slack(Surface):
def connection_string(self) -> str | None:
return "https://hooks.slack.com/services/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"
@lru_cache(maxsize=None)
def get_notifier(surfaces: list[Surface] | None = None) -> apprise.Apprise:
surfaces = surfaces or [Slack()]
obj = apprise.Apprise()
for surface in surfaces:
obj.add(surface.connection_string())
return obj
async def send_notification( body: str, title: str='') -> bool:
notifier = get_notifier()
return await notifier.async_notify(body=body, title=title)