diff --git a/README.md b/README.md index 7223cfb..73429ee 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ from TwitchChannelPointsMiner.classes.Chat import ChatPresence from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Webhook import Webhook from TwitchChannelPointsMiner.classes.Telegram import Telegram +from TwitchChannelPointsMiner.classes.Gotify import Gotify from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -259,6 +260,12 @@ twitch_miner = TwitchChannelPointsMiner( priority=0, # Read more about priority here: https://pushover.net/api#priority sound="pushover", # A list of sounds can be found here: https://pushover.net/api#sounds events=[Events.CHAT_MENTION, Events.DROP_CLAIM], # Only these events will be sent + ), + gotify=Gotify( + endpoint="https://example.com/message?token=TOKEN", + priority=8, + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, + Events.BET_LOSE, Events.CHAT_MENTION], ) ), streamer_settings=StreamerSettings( diff --git a/TwitchChannelPointsMiner/classes/Gotify.py b/TwitchChannelPointsMiner/classes/Gotify.py new file mode 100644 index 0000000..0e1fbdb --- /dev/null +++ b/TwitchChannelPointsMiner/classes/Gotify.py @@ -0,0 +1,23 @@ +from textwrap import dedent + +import requests + +from TwitchChannelPointsMiner.classes.Settings import Events + +class Gotify(object): + __slots__ = ["endpoint", "priority", "events"] + + def __init__(self, endpoint: str, priority: int, events: list): + self.endpoint = endpoint + self.priority = priority + self.events = [str(e) for e in events] + + def send(self, message: str, event: Events) -> None: + if str(event) in self.events: + requests.post( + url=self.endpoint, + data={ + "message": dedent(message), + "priority": self.priority + }, + ) diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index ea12537..072e8fd 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -584,6 +584,7 @@ class Twitch(object): "skip_discord": True, "skip_webhook": True, "skip_matrix": True, + "skip_gotify": True }, ) @@ -603,6 +604,11 @@ class Twitch(object): "\n".join(drop_messages), Events.DROP_STATUS, ) + if Settings.logger.gotify is not None: + Settings.logger.gotify.send( + "\n".join(drop_messages), + Events.DROP_STATUS, + ) except requests.exceptions.ConnectionError as e: logger.error( diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 9101a20..ca988c0 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -17,6 +17,7 @@ from TwitchChannelPointsMiner.classes.Matrix import Matrix from TwitchChannelPointsMiner.classes.Settings import Events from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Pushover import Pushover +from TwitchChannelPointsMiner.classes.Gotify import Gotify from TwitchChannelPointsMiner.utils import remove_emoji @@ -79,6 +80,7 @@ class LoggerSettings: "webhook", "matrix", "pushover", + "gotify", "username" ] @@ -99,6 +101,7 @@ class LoggerSettings: webhook: Webhook or None = None, matrix: Matrix or None = None, pushover: Pushover or None = None, + gotify: Gotify or None = None, username: str or None = None ): self.save = save @@ -116,6 +119,7 @@ class LoggerSettings: self.webhook = webhook self.matrix = matrix self.pushover = pushover + self.gotify = gotify self.username = username @@ -192,6 +196,7 @@ class GlobalFormatter(logging.Formatter): self.webhook(record) self.matrix(record) self.pushover(record) + self.gotify(record) if self.settings.colored is True: record.msg = ( @@ -259,6 +264,18 @@ class GlobalFormatter(logging.Formatter): ): self.settings.pushover.send(record.msg, record.event) + def gotify(self, record): + skip_gotify = False if hasattr( + record, "skip_gotify") is False else True + + if ( + self.settings.gotify is not None + and skip_gotify is False + and self.settings.gotify.endpoint + != "https://example.com/message?token=TOKEN" + ): + self.settings.gotify.send(record.msg, record.event) + def configure_loggers(username, settings): if settings.colored is True: diff --git a/example.py b/example.py index 8d48036..7b13372 100644 --- a/example.py +++ b/example.py @@ -10,6 +10,7 @@ from TwitchChannelPointsMiner.classes.Webhook import Webhook from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Matrix import Matrix from TwitchChannelPointsMiner.classes.Pushover import Pushover +from TwitchChannelPointsMiner.classes.Gotify import Gotify from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -72,6 +73,12 @@ twitch_miner = TwitchChannelPointsMiner( priority=0, # Read more about priority here: https://pushover.net/api#priority sound="pushover", # A list of sounds can be found here: https://pushover.net/api#sounds events=[Events.CHAT_MENTION, Events.DROP_CLAIM], # Only these events will be sent + ), + gotify=Gotify( + endpoint="https://example.com/message?token=TOKEN", + priority=8, + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, + Events.BET_LOSE, Events.CHAT_MENTION], ) ), streamer_settings=StreamerSettings(