switch from generic notifications to apprise
This commit is contained in:
parent
a284ae3963
commit
8f1e388e2f
110
setup.sh
110
setup.sh
|
@ -103,14 +103,14 @@ jinja2<3.1.0
|
|||
itsdangerous
|
||||
sqlalchemy
|
||||
apscheduler
|
||||
matrix-client
|
||||
reportlab
|
||||
requests
|
||||
pillow
|
||||
gunicorn
|
||||
apprise
|
||||
EOL
|
||||
|
||||
# 3. .env Datei in Parent-VFolder
|
||||
# 3. .env Datei in Parent-Folder
|
||||
cd ..
|
||||
SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_hex(24))')
|
||||
REDEEM_SECRET=$(python3 -c 'import secrets; print(secrets.token_hex(16))')
|
||||
|
@ -139,18 +139,13 @@ REGISTRATION_ENABLED="True"
|
|||
# checking interval if keys have to be redeemed before a specific date
|
||||
CHECK_EXPIRING_KEYS_INTERVAL_HOURS=6
|
||||
|
||||
# Pushover
|
||||
PUSHOVER_APP_TOKEN=""
|
||||
PUSHOVER_USER_KEY=""
|
||||
# Apprise URLs (separate several with a line break, comma or space)
|
||||
APPRISE_URLS=""
|
||||
|
||||
# Gotify
|
||||
GOTIFY_URL=""
|
||||
GOTIFY_TOKEN=""
|
||||
|
||||
# Matrix
|
||||
MATRIX_HOMESERVER=""
|
||||
MATRIX_ACCESS_TOKEN=""
|
||||
MATRIX_ROOM_ID=""
|
||||
### example for multiple notifications
|
||||
#APPRISE_URLS="pover://USER_KEY@APP_TOKEN
|
||||
#gotify://gotify.example.com/TOKEN
|
||||
#matrixs://TOKEN@matrix.org/!ROOM_ID"
|
||||
EOL
|
||||
|
||||
cd $PROJECT_DIR
|
||||
|
@ -739,81 +734,29 @@ def debug_session():
|
|||
'config_locales': app.config['BABEL_SUPPORTED_LOCALES']
|
||||
})
|
||||
|
||||
# Benachrichtigungsfunktionen
|
||||
def send_pushover_notification(user, game):
|
||||
"""Sendet Pushover-Benachrichtigung für ablaufenden Key"""
|
||||
if not app.config['PUSHOVER_APP_TOKEN'] or not app.config['PUSHOVER_USER_KEY']:
|
||||
return False
|
||||
|
||||
payload = {
|
||||
"token": os.getenv('PUSHOVER_APP_TOKEN'),
|
||||
"user": os.getenv('PUSHOVER_USER_KEY'),
|
||||
"title": "Steam-Key läuft ab!",
|
||||
"message": f"Dein Key für '{game.name}' läuft in weniger als 48 Stunden ab!",
|
||||
"url": url_for('edit_game', game_id=game.id, _external=True),
|
||||
"url_title": "Zum Spiel",
|
||||
"priority": 1
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
'https://api.pushover.net/1/messages.json',
|
||||
data=payload
|
||||
)
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
app.logger.error(f"Pushover error: {str(e)}")
|
||||
# Apprise Notifications
|
||||
import apprise
|
||||
|
||||
def send_apprise_notification(user, game):
|
||||
apprise_urls = os.getenv('APPRISE_URLS', '').strip()
|
||||
if not apprise_urls:
|
||||
app.logger.error("No APPRISE_URLS configured")
|
||||
return False
|
||||
|
||||
def send_gotify_notification(user, game):
|
||||
"""Sendet Gotify-Benachrichtigung für ablaufenden Key"""
|
||||
if not GOTIFY_URL or not GOTIFY_TOKEN:
|
||||
return False
|
||||
|
||||
payload = {
|
||||
"title": "Steam-Key läuft ab!",
|
||||
"message": f"Dein Key für '{game.name}' läuft in weniger als 48 Stunden ab!",
|
||||
"priority": 5
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{GOTIFY_URL}/message?token={GOTIFY_TOKEN}",
|
||||
json=payload
|
||||
)
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
app.logger.error(f"Gotify error: {str(e)}")
|
||||
return False
|
||||
apobj = apprise.Apprise()
|
||||
for url in apprise_urls.replace(',', '\n').splitlines():
|
||||
if url.strip():
|
||||
apobj.add(url.strip())
|
||||
|
||||
def send_matrix_notification(user, game):
|
||||
"""Sendet Matrix-Benachrichtigung für ablaufenden Key"""
|
||||
if not MATRIX_HOMESERVER or not MATRIX_ACCESS_TOKEN or not MATRIX_ROOM_ID:
|
||||
return False
|
||||
|
||||
try:
|
||||
from matrix_client.client import MatrixClient
|
||||
|
||||
client = MatrixClient(MATRIX_HOMESERVER, token=MATRIX_ACCESS_TOKEN)
|
||||
room = client.join_room(MATRIX_ROOM_ID)
|
||||
|
||||
message = f"🎮 Dein Key für '{game.name}' läuft in weniger als 48 Stunden ab!"
|
||||
room.send_text(message)
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
app.logger.error(f"Matrix error: {str(e)}")
|
||||
return False
|
||||
edit_url = url_for('edit_game', game_id=game.id, _external=True)
|
||||
result = apobj.notify(
|
||||
title="Steam-Key läuft ab!",
|
||||
body=f"Dein Key für '{game.name}' läuft in weniger als 48 Stunden ab!\n\nLink: {edit_url}",
|
||||
)
|
||||
return result
|
||||
|
||||
def send_notification(user, game):
|
||||
"""Sendet Benachrichtigung über den bevorzugten Dienst des Benutzers"""
|
||||
if user.notification_service == 'pushover':
|
||||
return send_pushover_notification(user, game)
|
||||
elif user.notification_service == 'gotify':
|
||||
return send_gotify_notification(user, game)
|
||||
elif user.notification_service == 'matrix':
|
||||
return send_matrix_notification(user, game)
|
||||
return False
|
||||
return send_apprise_notification(user, game)
|
||||
|
||||
def check_expiring_keys():
|
||||
with app.app_context():
|
||||
|
@ -1610,6 +1553,7 @@ echo -e "cd steam-gift-manager"
|
|||
echo -e "docker-compose build --no-cache && docker-compose up -d"
|
||||
echo -e "\nGenerate translations: ./translate.sh"
|
||||
echo -e "You can edit them in translations/en/LC_MESSAGES/messages.po"
|
||||
echo -e "Enter your Apprise URLs in .env at APPRISE_URLS (e.g. for Pushover, Gotify, Matrix etc.)"
|
||||
echo -e "\nAfter any change in you configuration, .env or even translations:"
|
||||
echo -e "cd steam-gift-manager"
|
||||
echo -e "docker-compose down && docker-compose up -d --build"
|
||||
|
|
Loading…
Reference in New Issue