feat: Gotify module

This commit is contained in:
leko
2024-08-14 01:40:59 +08:00
committed by GitHub
parent 36647bb85b
commit 5f6920f8df
5 changed files with 60 additions and 0 deletions

View File

@@ -197,6 +197,7 @@ from TwitchChannelPointsMiner.classes.Chat import ChatPresence
from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Discord import Discord
from TwitchChannelPointsMiner.classes.Webhook import Webhook from TwitchChannelPointsMiner.classes.Webhook import Webhook
from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Telegram import Telegram
from TwitchChannelPointsMiner.classes.Gotify import Gotify
from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode
from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings 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 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 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 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( streamer_settings=StreamerSettings(

View File

@@ -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
},
)

View File

@@ -584,6 +584,7 @@ class Twitch(object):
"skip_discord": True, "skip_discord": True,
"skip_webhook": True, "skip_webhook": True,
"skip_matrix": True, "skip_matrix": True,
"skip_gotify": True
}, },
) )
@@ -603,6 +604,11 @@ class Twitch(object):
"\n".join(drop_messages), "\n".join(drop_messages),
Events.DROP_STATUS, 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: except requests.exceptions.ConnectionError as e:
logger.error( logger.error(

View File

@@ -17,6 +17,7 @@ from TwitchChannelPointsMiner.classes.Matrix import Matrix
from TwitchChannelPointsMiner.classes.Settings import Events from TwitchChannelPointsMiner.classes.Settings import Events
from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Telegram import Telegram
from TwitchChannelPointsMiner.classes.Pushover import Pushover from TwitchChannelPointsMiner.classes.Pushover import Pushover
from TwitchChannelPointsMiner.classes.Gotify import Gotify
from TwitchChannelPointsMiner.utils import remove_emoji from TwitchChannelPointsMiner.utils import remove_emoji
@@ -79,6 +80,7 @@ class LoggerSettings:
"webhook", "webhook",
"matrix", "matrix",
"pushover", "pushover",
"gotify",
"username" "username"
] ]
@@ -99,6 +101,7 @@ class LoggerSettings:
webhook: Webhook or None = None, webhook: Webhook or None = None,
matrix: Matrix or None = None, matrix: Matrix or None = None,
pushover: Pushover or None = None, pushover: Pushover or None = None,
gotify: Gotify or None = None,
username: str or None = None username: str or None = None
): ):
self.save = save self.save = save
@@ -116,6 +119,7 @@ class LoggerSettings:
self.webhook = webhook self.webhook = webhook
self.matrix = matrix self.matrix = matrix
self.pushover = pushover self.pushover = pushover
self.gotify = gotify
self.username = username self.username = username
@@ -192,6 +196,7 @@ class GlobalFormatter(logging.Formatter):
self.webhook(record) self.webhook(record)
self.matrix(record) self.matrix(record)
self.pushover(record) self.pushover(record)
self.gotify(gotify)
if self.settings.colored is True: if self.settings.colored is True:
record.msg = ( record.msg = (
@@ -259,6 +264,18 @@ class GlobalFormatter(logging.Formatter):
): ):
self.settings.pushover.send(record.msg, record.event) 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): def configure_loggers(username, settings):
if settings.colored is True: if settings.colored is True:

View File

@@ -10,6 +10,7 @@ from TwitchChannelPointsMiner.classes.Webhook import Webhook
from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Telegram import Telegram
from TwitchChannelPointsMiner.classes.Matrix import Matrix from TwitchChannelPointsMiner.classes.Matrix import Matrix
from TwitchChannelPointsMiner.classes.Pushover import Pushover from TwitchChannelPointsMiner.classes.Pushover import Pushover
from TwitchChannelPointsMiner.classes.Gotify import Gotify
from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode
from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings 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 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 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 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( streamer_settings=StreamerSettings(