Skip to content

Commit

Permalink
Merge pull request #298 from NoxRare/master
Browse files Browse the repository at this point in the history
Added Pushover as a notification alternative!
  • Loading branch information
rdavydov authored Aug 8, 2023
2 parents 8124724 + 4a0c2a2 commit 133de5d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
30 changes: 30 additions & 0 deletions TwitchChannelPointsMiner/classes/Pushover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from textwrap import dedent

import requests

from TwitchChannelPointsMiner.classes.Settings import Events


class Pushover(object):
__slots__ = ["userkey", "token", "priority", "sound", "events"]

def __init__(self, userkey: str, token: str, priority, sound, events: list):
self.userkey = userkey
self.token = token
self. priority = priority
self.sound = sound
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="https://api.pushover.net/1/messages.json",
data={
"user": self.userkey,
"token": self.token,
"message": dedent(message),
"title": "Twitch Channel Points Miner",
"priority": self.priority,
"sound": self.sound,
},
)
18 changes: 15 additions & 3 deletions TwitchChannelPointsMiner/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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.utils import remove_emoji


Expand Down Expand Up @@ -74,7 +75,8 @@ class LoggerSettings:
"auto_clear",
"telegram",
"discord",
"matrix"
"matrix",
"pushover"
]

def __init__(
Expand All @@ -91,7 +93,8 @@ def __init__(
auto_clear: bool = True,
telegram: Telegram or None = None,
discord: Discord or None = None,
matrix: Matrix or None = None
matrix: Matrix or None = None,
pushover: Pushover or None = None
):
self.save = save
self.less = less
Expand All @@ -106,6 +109,7 @@ def __init__(
self.telegram = telegram
self.discord = discord
self.matrix = matrix
self.pushover = pushover


class FileFormatter(logging.Formatter):
Expand Down Expand Up @@ -177,6 +181,7 @@ def format(self, record):
self.telegram(record)
self.discord(record)
self.matrix(record)
self.pushover(record)

if self.settings.colored is True:
record.msg = (
Expand Down Expand Up @@ -219,7 +224,14 @@ def matrix(self, record):
and self.settings.matrix.access_token
):
self.settings.matrix.send(record.msg, record.event)


def pushover(self, record):
skip_pushover = False if hasattr(
record, "skip_pushover") is False else True

if (self.settings.pushover is not None
and skip_pushover is False):
self.settings.pushover.send(record.msg, record.event)

def configure_loggers(username, settings):
if settings.colored is True:
Expand Down
7 changes: 7 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
homeserver="matrix.org", # Matrix homeserver
room_id="...", # Room ID
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat
),
pushover=Pushover(
userkey="YOUR-ACCOUNT-TOKEN", # Login to https://pushover.net/, the user token is on the main page.
token="YOUR-APPLICATION-TOKEN", # Create a application on the website, and use the token shown in your application.
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.
)
),
streamer_settings=StreamerSettings(
Expand Down

0 comments on commit 133de5d

Please sign in to comment.