Merge pull request #585 from lekoOwO/master

Support Gotify Logger
This commit is contained in:
Roman Davydov
2024-10-06 13:04:09 +03:00
committed by GitHub
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.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(

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_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(

View File

@@ -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:

View File

@@ -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(