From c1451bcc375254e5e8c3ae687da9c39dfc67fd0e Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Thu, 10 Aug 2023 13:07:00 -0500 Subject: [PATCH] feat: Notifications should work --- Cleanup.py | 1 + Notifications.py | 13 ++++++++----- ReVancedBuilder.py | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cleanup.py b/Cleanup.py index e0d406d..94f8aaf 100644 --- a/Cleanup.py +++ b/Cleanup.py @@ -23,6 +23,7 @@ def move_apps(appstate): pass # sys.exit('There was an error moving the final apk files!') + # Do some cleanup, keep only the last 3 build's worth of files and a week worth of logs files = [] dir = os.scandir('archive') for f in dir: diff --git a/Notifications.py b/Notifications.py index d11cce1..5d1c7d7 100644 --- a/Notifications.py +++ b/Notifications.py @@ -1,6 +1,7 @@ import json import re import requests as req +import subprocess def send_notif(appstate, error=False): timestamp = appstate['timestamp'] @@ -21,6 +22,8 @@ def send_notif(appstate, error=False): msg = msg.replace(build_config[app]['apk'], build_config[app]['pretty_name']) msg += '\nTimestamp: ' + timestamp + if appstate['microg_updated']: + msg += '\nVanced microG was updated.' config = appstate['notification_config'] for entry in config: @@ -30,7 +33,7 @@ def send_notif(appstate, error=False): match entry: case 'ntfy': - print('Sending notification through nfty.sh') + print('Sending notification through ntfy.sh...') try: url = config[entry]['url'] topic = config[entry]['topic'] @@ -45,7 +48,7 @@ def send_notif(appstate, error=False): print('Failed!' + str(e)) case 'gotify': - print('Sending notification through nfty.sh') + print('Sending notification through Gotify...') try: url = config[entry]['url'] token = config[entry]['token'] @@ -60,16 +63,16 @@ def send_notif(appstate, error=False): case 'telegram': # TODO: Finish this! - print('Sending notification through telegram') + print('Sending notification through Telegram...') try: chat = config[entry]['chat'] token = config[entry]['token'] except: print('CHAT or TOKEN not provided!') continue - data = {'Title': encoded_title, 'message': msg, 'priority': '5'} + cmd = f"./telegram.sh -t {token} -c {chat} -T {encoded_title} -M \"{msg}\"" try: - req.post(f"{url}/message?token={token}", data) + subprocess.run(cmd, shell=True) except Exception as e: print('Failed!' + str(e)) diff --git a/ReVancedBuilder.py b/ReVancedBuilder.py index 6450231..c3ad1f9 100755 --- a/ReVancedBuilder.py +++ b/ReVancedBuilder.py @@ -17,6 +17,7 @@ from Cleanup import * # TODO: Run post_script (preferably in any language) # TODO: README # TODO: PATCHES_GUIDE.md (maybe delete it?) +# TODO: Make it PIP installable # Update the ReVanced tools, if needed def update_tools(appstate): @@ -70,6 +71,7 @@ def update_microg(appstate): f.write(chunk) appstate['present_vers'].update({'VancedMicroG': str(latest_ver)}) print("Done!") + appstate['microg_updated'] = True return appstate @@ -100,6 +102,7 @@ except: flag = None appstate['flag'] = flag +appstate['microg_updated'] = False try: appstate['build_config']=cp.ConfigParser()