Files
twitch-miner/TwitchChannelPointsMiner/classes/Telegram.py
0815Cracky ff22f47b90 update
2024-02-27 11:46:37 +01:00

30 lines
1.0 KiB
Python

from textwrap import dedent
import requests
from TwitchChannelPointsMiner.classes.Settings import Events
class Telegram(object):
__slots__ = ["chat_id", "telegram_api", "events", "disable_notification"]
def __init__(
self, chat_id: int, token: str, events: list, disable_notification: bool = False
):
self.chat_id = chat_id
self.telegram_api = f"https://api.telegram.org/bot{token}/sendMessage"
self.events = [str(e) for e in events]
self.disable_notification = disable_notification
def send(self, message: str, event: Events) -> None:
if str(event) in self.events:
requests.post(
url=self.telegram_api,
data={
"chat_id": self.chat_id,
"text": dedent(message),
"disable_web_page_preview": True, # include link to twitch streamer?
"disable_notification": self.disable_notification, # no sound, notif just in tray
},
)