diff options
Diffstat (limited to 'forgebot.sh')
-rwxr-xr-x[-rw-r--r--] | forgebot.sh | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/forgebot.sh b/forgebot.sh index 5c0babb..0a5b1e7 100644..100755 --- a/forgebot.sh +++ b/forgebot.sh @@ -8,50 +8,38 @@ # find -# Configuration: - -# Your hypixel api key -API_KEY="81420b47-17db-44ed-aee0-f15662d650f0" -# Your discord webhook url -WEBHOOK_URL="https://discord.com/api/webhooks/1137392560973828107/6MmpfsLcIN9S9Xp1LlmPD56EF_QRD-W4JvbUwShXdP-_A_paDoGCAlaRfIQxgsRDZzq5" - -# Now create a folder called forgebotdata. In that folder create a file for every user, with the name being their uuid without dashes, and the content being their discord id: -# -# forgebot.sh -# forgebotdata/ -# forgebotdata/4154a5602654493094d3497d2ad6849f: 281489313840103426 -# forgebotdata/d3cb85e2307548a1b213a9bfb62360c1: 310702108997320705 -# - function get_duration() { jq '.recipes[] | select(.type ="forge") | .duration * 1000' < repo/items/$1.json } +poll_forge_events() { + atrocity_debug "Forge polling started" while true; do - for uuid in $(find forgebotdata -type f); do - discordid=$(cat $uuid) - uuid=${uuid#forgebotdata/} - echo UUID: $uuid - processes="$(curl -H "Api-Key: $API_KEY" https://api.hypixel.net/skyblock/profiles\?uuid=$uuid 2>/dev/null | + for uuid in $(list_all_watched_accounts); do + if ! atrocity_is_online; then + return + fi + atrocity_debug UUID: $uuid + processes="$(curl -H "Api-Key: $HYPIXEL_KEY" https://api.hypixel.net/v2/skyblock/profiles\?uuid=$uuid 2>/dev/null | tee api_response.json| jq '[.profiles[].members["'$uuid'"] | select(.forge.forge_processes.forge_1) | {"qf": .mining_core.nodes.forge_time,"fp": [.forge.forge_processes.forge_1[]]}]')" - echo $processes + atrocity_debug $processes mkdir -p notificationdata touch notificationdata/$uuid now=$(date +%s000) rm -f messagedata - echo "$processes"| jq -r '.[] | {qf: .qf, fp: .fp[]} | (if (.qf == 20) then "0.7" elif (.qf == 0) then "1" else (1 - (.qf * .5 + 10) / 100|tostring) end) + " " + .fp.id + " " + (.fp.startTime|tostring) + " " + (.fp.slot|tostring)' | while read qf id starttime slot; do - echo ID: $id STARTTIME: $starttime SLOT: $slot + echo "$processes"| jq -r '.[] | {qf: (.qf // 0), fp: .fp[]} | (if (.qf == 20) then "0.7" elif (.qf == 0) then "1" else (1 - (.qf * .5 + 10) / 100|tostring) end) + " " + .fp.id + " " + (.fp.startTime|tostring) + " " + (.fp.slot|tostring)' | while read qf id starttime slot; do + atrocity_debug ID: $id STARTTIME: $starttime SLOT: $slot doneat=$(($starttime + $(get_duration $id))) - echo DONEAT WITHOUT QF: $doneat + atrocity_debug DONEAT WITHOUT QF: $doneat doneat=$(bc <<<"$starttime + $qf*$(get_duration $id)"|sed s'/\..*//') - echo DONE: $doneat + atrocity_debug DONE: $doneat already_notified=$(grep $starttime notificationdata/$uuid >/dev/null; echo $?) - echo NOTIFIED: $already_notified + atrocity_debug NOTIFIED: $already_notified isready=$(($now > $doneat)) - echo "$now > $doneat: $isready" + atrocity_debug "$now > $doneat: $isready" if [[ $isready -eq 1 ]]; then - echo READY + atrocity_debug READY echo $starttime > notificationdata/$uuid.new if [[ already_notified -eq 1 ]]; then echo Your $id in $slot is ready since "<t:$(($doneat / 1000)):R> (started <t:$(($starttime / 1000)):R>)" >>messagedata @@ -60,12 +48,13 @@ while true; do done if [[ -f messagedata ]]; then echo Sending messagedata: - cat messagedata - jsondata="$(jq -n --arg body "$(printf '<@%s>\n%s' $discordid "$(cat messagedata)")" '{"content": $body, "username": "Forgebot"}')" - curl -X POST "$WEBHOOK_URL" -H "Content-Type: multipart/form-data" -F "payload_json=$jsondata" + atrocity_debug "$(cat messagedata)" + jsondata="$(jq -n --arg body "$(list_watchers "$uuid"|sed -E 's|(.*)|<@\1>|';echo;cat messagedata)" '{"content": $body}')" + atrocity_rest POST "channels/$CHANNEL_ID/messages" "$jsondata" mv notificationdata/$uuid.new notificationdata/$uuid fi sleep 10 done sleep 300 done +} |