2023-08-09 19:12:04 -05:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import requests as req
|
2023-08-10 13:07:00 -05:00
|
|
|
import subprocess
|
2023-08-09 19:12:04 -05:00
|
|
|
|
|
|
|
def send_notif(appstate, error=False):
|
2023-08-10 14:50:42 -05:00
|
|
|
print = appstate['logger'].info
|
2023-08-09 19:12:04 -05:00
|
|
|
timestamp = appstate['timestamp']
|
2023-08-10 14:50:42 -05:00
|
|
|
|
2023-08-09 19:12:04 -05:00
|
|
|
if error:
|
|
|
|
msg = f"There was an error during build! Please check the logs.\nTimestamp: {timestamp}"
|
|
|
|
else:
|
|
|
|
notification_config = appstate['notification_config']
|
|
|
|
build_config = appstate['build_config']
|
|
|
|
present_vers = appstate['present_vers']
|
|
|
|
flag = appstate['flag']
|
|
|
|
|
|
|
|
msg = json.dumps(present_vers, indent=0)
|
|
|
|
msg = re.sub('("|\{|\}|,)', '', msg).strip('\n')
|
|
|
|
|
|
|
|
for app in build_config:
|
|
|
|
if not build_config[app].getboolean('build'):
|
|
|
|
continue
|
|
|
|
msg = msg.replace(build_config[app]['apk'], build_config[app]['pretty_name'])
|
|
|
|
|
|
|
|
msg += '\nTimestamp: ' + timestamp
|
2023-08-10 13:07:00 -05:00
|
|
|
if appstate['microg_updated']:
|
|
|
|
msg += '\nVanced microG was updated.'
|
2023-08-09 19:12:04 -05:00
|
|
|
|
|
|
|
config = appstate['notification_config']
|
|
|
|
for entry in config:
|
|
|
|
if not config[entry].getboolean('enabled'):
|
|
|
|
continue
|
|
|
|
encoded_title = '⚙⚙⚙ ReVanced Build ⚙⚙⚙'.encode('utf-8')
|
|
|
|
|
|
|
|
match entry:
|
|
|
|
case 'ntfy':
|
2023-08-10 13:07:00 -05:00
|
|
|
print('Sending notification through ntfy.sh...')
|
2023-08-09 19:12:04 -05:00
|
|
|
try:
|
|
|
|
url = config[entry]['url']
|
|
|
|
topic = config[entry]['topic']
|
|
|
|
except:
|
|
|
|
print('URL or TOPIC not provided!')
|
|
|
|
continue
|
|
|
|
headers = {'Icon': 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Revanced-logo-round.svg/240px-Revanced-logo-round.svg.png',
|
|
|
|
'Title': encoded_title}
|
|
|
|
try:
|
|
|
|
req.post(f"{url}/{topic}", msg, headers=headers)
|
|
|
|
except Exception as e:
|
|
|
|
print('Failed!' + str(e))
|
|
|
|
|
|
|
|
case 'gotify':
|
2023-08-10 13:07:00 -05:00
|
|
|
print('Sending notification through Gotify...')
|
2023-08-09 19:12:04 -05:00
|
|
|
try:
|
|
|
|
url = config[entry]['url']
|
|
|
|
token = config[entry]['token']
|
|
|
|
except:
|
|
|
|
print('URL or TOKEN not provided!')
|
|
|
|
continue
|
|
|
|
data = {'Title': encoded_title, 'message': msg, 'priority': '5'}
|
|
|
|
try:
|
|
|
|
req.post(f"{url}/message?token={token}", data)
|
|
|
|
except Exception as e:
|
|
|
|
print('Failed!' + str(e))
|
|
|
|
|
|
|
|
case 'telegram':
|
|
|
|
# TODO: Finish this!
|
2023-08-10 13:07:00 -05:00
|
|
|
print('Sending notification through Telegram...')
|
2023-08-09 19:12:04 -05:00
|
|
|
try:
|
|
|
|
chat = config[entry]['chat']
|
|
|
|
token = config[entry]['token']
|
|
|
|
except:
|
|
|
|
print('CHAT or TOKEN not provided!')
|
|
|
|
continue
|
2023-08-10 13:07:00 -05:00
|
|
|
cmd = f"./telegram.sh -t {token} -c {chat} -T {encoded_title} -M \"{msg}\""
|
2023-08-09 19:12:04 -05:00
|
|
|
try:
|
2023-08-10 14:50:42 -05:00
|
|
|
with subprocess.Popen(cmd, shell=True, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout as output:
|
|
|
|
for line in output:
|
|
|
|
line_utf = line.decode('utf-8').strip('\n')
|
|
|
|
if line_utf:
|
|
|
|
print(line_utf)
|
2023-08-09 19:12:04 -05:00
|
|
|
except Exception as e:
|
2023-08-10 14:50:42 -05:00
|
|
|
clean_exit(f"Failed!\n{e}", appstate)
|
2023-08-09 19:12:04 -05:00
|
|
|
|
|
|
|
case _:
|
|
|
|
print('Don\'t know how to send notifications to ' + entry)
|