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