feat: Notifications should work

This commit is contained in:
Sayantan Santra 2023-08-10 13:07:00 -05:00
parent b5fc2e43d3
commit c1451bcc37
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
3 changed files with 12 additions and 5 deletions

View file

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

View file

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

View file

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