mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2024-12-26 20:58:37 -06:00
change: Refactor notification code
This commit is contained in:
parent
bde041fa17
commit
7b93c26540
1 changed files with 29 additions and 32 deletions
|
@ -233,6 +233,24 @@ build_ytm_root() {
|
||||||
mv revanced-ytm-root.apk YouTube_Music_ReVanced_root_$timestamp.apk || error=1
|
mv revanced-ytm-root.apk YouTube_Music_ReVanced_root_$timestamp.apk || error=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
telegram_send_msg() {
|
||||||
|
# telegram.sh uses bot account, but it supports formatted messages
|
||||||
|
[[ "$TELEGRAM_TOKEN" == "" || "$TELEGRAM_CHAT" == "" ]] && echo "Please provide valid channel address in the settings!"
|
||||||
|
./telegram.sh -t "$TELEGRAM_TOKEN" -c "$TELEGRAM_CHAT" -T "⚙⚙⚙ Build Details ⚙⚙⚙" -M "$1"$'\n'"Timestamp: $timestamp"$'\n'"⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
|
||||||
|
}
|
||||||
|
|
||||||
|
gotify_send_msg() {
|
||||||
|
curl -s -X POST "$GOTIFY_URL/message?token=$GOTIFY_TOKEN" \
|
||||||
|
-F "title=⚙⚙⚙ Build Details ⚙⚙⚙" -F "message=$1" -F "priority=5"
|
||||||
|
}
|
||||||
|
|
||||||
|
ntfy_send_msg() {
|
||||||
|
curl -s -H "Icon: https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Revanced-logo-round.svg/240px-Revanced-logo-round.svg.png" \
|
||||||
|
-H "Title: ⚙⚙⚙ ReVanced Build ⚙⚙⚙" \
|
||||||
|
-d "$1" \
|
||||||
|
"$NTFY_URL/$NTFY_TOPIC"
|
||||||
|
}
|
||||||
|
|
||||||
# Check the config and build accordingly
|
# Check the config and build accordingly
|
||||||
$YT_NONROOT && build_yt_nonroot
|
$YT_NONROOT && build_yt_nonroot
|
||||||
$YT_ROOT && build_yt_root
|
$YT_ROOT && build_yt_root
|
||||||
|
@ -244,19 +262,11 @@ $YTM_ROOT && build_ytm_root
|
||||||
if [ $error == 1 ]; then
|
if [ $error == 1 ]; then
|
||||||
echo "There was an error while building!"
|
echo "There was an error while building!"
|
||||||
msg="There was an error during the build process! Please take a look at the logs."$'\n'"Timestamp: $timestamp"
|
msg="There was an error during the build process! Please take a look at the logs."$'\n'"Timestamp: $timestamp"
|
||||||
if $TG_NOTIFICATIONS; then
|
|
||||||
./telegram.sh -t "$TELEGRAM_TOKEN" -c "$TELEGRAM_CHAT" -T "❗❗❗ Build Error ❗❗❗" -M "$msg"$'\n'"⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
|
$TG_NOTIFICATIONS && telegram_send_msg "$msg"
|
||||||
fi
|
$GOTIFY_NOTIFICATIONS && gotify_send_msg "$msg"
|
||||||
if $GOTIFY_NOTIFICATIONS; then
|
$NTFY_NOTIFICATIONS && ntfy_send_msg "$msg"
|
||||||
curl -sX POST "$GOTIFY_URL/message?token=$GOTIFY_TOKEN" \
|
|
||||||
-F "title=⚙⚙⚙ Build Details ⚙⚙⚙" -F "message=$msg" -F "priority=5"
|
|
||||||
fi
|
|
||||||
if $NTFY_NOTIFICATIONS; then
|
|
||||||
curl -s -H "Icon: https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Revanced-logo-round.svg/240px-Revanced-logo-round.svg.png" \
|
|
||||||
-H "Title: ⚙⚙⚙ ReVanced Build ⚙⚙⚙" \
|
|
||||||
-d "$MESSAGE" \
|
|
||||||
"$NTFY_URL/$NTFY_TOPIC"
|
|
||||||
fi
|
|
||||||
if [[ $2 != buildonly ]]; then
|
if [[ $2 != buildonly ]]; then
|
||||||
mv versions.json versions.json.fail
|
mv versions.json versions.json.fail
|
||||||
mv versions.json.old versions.json
|
mv versions.json.old versions.json
|
||||||
|
@ -278,35 +288,22 @@ msg=$(cat versions.json | tail -n+2 | head -n-1 | cut -c3- | sed "s/\"//g" | sed
|
||||||
|
|
||||||
if $TG_NOTIFICATIONS; then
|
if $TG_NOTIFICATIONS; then
|
||||||
echo "Sending messages to telegram"
|
echo "Sending messages to telegram"
|
||||||
# telegram.sh uses bot account, but it supports formatted messages
|
telegram_send_msg "$msg"
|
||||||
[[ "$TELEGRAM_TOKEN" == "" || "$TELEGRAM_CHAT" == "" ]] && echo "Please provide valid channel address in the settings!"
|
[ $microg_updated ] && telegram_send_msg "_An update of microg was published._"
|
||||||
./telegram.sh -t "$TELEGRAM_TOKEN" -c "$TELEGRAM_CHAT" -T "⚙⚙⚙ Build Details ⚙⚙⚙" -M "$msg"$'\n'"Timestamp: $timestamp"$'\n'"⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
|
|
||||||
[ $microg_updated ] && ./telegram.sh -t "$TELEGRAM_TOKEN" -c "$TELEGRAM_CHAT" -M "_An update of microg was published._"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $GOTIFY_NOTIFICATIONS; then
|
if $GOTIFY_NOTIFICATIONS; then
|
||||||
echo "Sending messages to Gotify"
|
echo "Sending messages to Gotify"
|
||||||
MESSAGE="$msg"$'\n'"Timestamp: $timestamp"
|
MESSAGE="$msg"$'\n'"Timestamp: $timestamp"
|
||||||
curl -s -X POST "$GOTIFY_URL/message?token=$GOTIFY_TOKEN" \
|
gotify_send_msg "$MESSAGE"
|
||||||
-F "title=⚙⚙⚙ Build Details ⚙⚙⚙" -F "message=$MESSAGE" -F "priority=5"
|
[ $microg_updated ] && gotify_send_msg "An update of microg was published."
|
||||||
|
|
||||||
MESSAGE="An update of microg was published."
|
|
||||||
[ $microg_updated ] && curl -s -X POST "$GOTIFY_URL/message?token=$GOTIFY_TOKEN" \
|
|
||||||
-F "title=⚙⚙⚙ Build Details ⚙⚙⚙" -F "message=$MESSAGE" -F "priority=5"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $NTFY_NOTIFICATIONS; then
|
if $NTFY_NOTIFICATIONS; then
|
||||||
echo "Sending messages to ntfy.sh"
|
echo "Sending messages to ntfy.sh"
|
||||||
MESSAGE="$msg"$'\n'"Timestamp: $timestamp"
|
MESSAGE="$msg"$'\n'"Timestamp: $timestamp"
|
||||||
curl -s -H "Icon: https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Revanced-logo-round.svg/240px-Revanced-logo-round.svg.png" \
|
ntfy_send_msg "$MESSAGE"
|
||||||
-H "Title: ⚙⚙⚙ ReVanced Build ⚙⚙⚙" \
|
[ $microg_updated ] && ntfy_send_msg "An update of microg was published."
|
||||||
-d "$MESSAGE" \
|
|
||||||
"$NTFY_URL/$NTFY_TOPIC"
|
|
||||||
MESSAGE="An update of microg was published."
|
|
||||||
[ $microg_updated ] && curl -s -H "Icon: https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Revanced-logo-round.svg/240px-Revanced-logo-round.svg.png" \
|
|
||||||
-H "Title: ⚙⚙⚙ ReVanced Build ⚙⚙⚙" \
|
|
||||||
-d "$MESSAGE" \
|
|
||||||
"$NTFY_URL/$NTFY_TOPIC"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Do some cleanup, keep only the last 3 build's worth of files and a week worth of logs
|
# Do some cleanup, keep only the last 3 build's worth of files and a week worth of logs
|
||||||
|
|
Loading…
Reference in a new issue