diff options
-rw-r--r-- | data.sh | 31 | ||||
-rwxr-xr-x | forgebot_proper.sh | 76 | ||||
-rw-r--r-- | forgebotdata/d3cb85e2307548a1b213a9bfb62360c1 | 2 |
3 files changed, 93 insertions, 16 deletions
@@ -0,0 +1,31 @@ +export FORGEBOT_DATA_DIR="forgebotdata" +mkdir -p "$FORGEBOT_DATA_DIR" + +list_watchers() { + # Usage: list_watchers <minecraft uuid> + cat "$FORGEBOT_DATA_DIR/$1" +} + +find_watched_accounts() { + # Usage: find_watched_accounts <discord uuid> + grep -lr "$1" "$FORGEBOT_DATA_DIR" | sed 's|.*/||' +} + +add_watched_account() { + # Usage: add_watched_account <discord uuid> <minecraft uuid> + echo "$1" >> "$FORGEBOT_DATA_DIR/$2" +} + +remove_watched_account() { + # Usage: remove_watched_account <discord uuid> <minecraft uuid> + sed -i "/$1/d" "$FORGEBOT_DATA_DIR/$2" +} + +has_watched_account() { + # Usage: has_watched_account <discord uuid> <minecraft uuid> + grep "$1" "$FORGEBOT_DATA_DIR/$2" >/dev/null + return $? +} + + + diff --git a/forgebot_proper.sh b/forgebot_proper.sh index 676803d..efb2835 100755 --- a/forgebot_proper.sh +++ b/forgebot_proper.sh @@ -10,12 +10,15 @@ if [[ x"$HYPIXEL_KEY" == x ]]; then fi source "$(dirname -- "$0")"/atrocity/load.sh source "$(dirname -- "$0")"/hypixel_api.sh +source "$(dirname -- "$0")"/data.sh find_option() { # Usage: find_option <data> <name> printf '%s' "$1" | jq -r '.data.options[] | select(.name == "'"$2"'")| .value' } +disallow_mentions='"allowed_mentions": {"parse":[]}' + atrocity_on_INTERACTION_CREATE() { local type type="$(printf '%s' "$1" | jq -r .type)" @@ -26,37 +29,78 @@ atrocity_on_INTERACTION_CREATE() { #MODAL_SUBMIT 5 id=$(printf '%s' "$1" | jq -r .id) token=$(printf '%s' "$1" | jq -r .token) - atrocity_debug Processing interaction with id $id and token $token of type $type + user=$(printf '%s' "$1" | jq -r .member.user.id) + atrocity_debug Processing interaction with id $id and token $token of type $type from $user if [[ $type == 2 ]]; then command_name=$(printf '%s' "$1" | jq -r .data.name) atrocity_debug Executing command $command_name if [[ $command_name == register ]]; then username="$(find_option "$1" username)" atrocity_debug "Registering user with name $username" - # TODO first acc then edit + # TODO first ack then edit minecraft_uuid="$(curl "https://mowojang.matdoes.dev/$username" 2>/dev/null | jq -r .id)" atrocity_debug "Got uuid: $minecraft_uuid" - hypixel_profiles="$(get_profiles_by_uuid "$minecraft_uuid")" - components="$(printf '%s' "$hypixel_profiles" | jq -r '[[.profiles[] | ({"type": 2, "label": .cute_name, "style": 1, "custom_id": (.profile_id + " '"$minecraft_uuid"'")})]|_nwise(3)|{"type": 1, "components": .}]')" # Frucht emoji pro profile - atrocity_rest POST "interactions/$id/$token/callback" "$(cat << EOF + if has_watched_account $user $minecraft_uuid; then + atrocity_rest POST "interactions/$id/$token/callback" "$(cat << EOF +{ + "type": 4, + "data": { + "content": "You have already registered the account with name \`$username\` and uuid \`$minecraft_uuid\`.", + $disallow_mentions + } +} +EOF + )" + else + add_watched_account $user $minecraft_uuid + atrocity_rest POST "interactions/$id/$token/callback" "$(cat << EOF { "type": 4, "data": { - "content": "Trying to register with name \`$username\` and uuid \`$minecraft_uuid\`", - "components": $components + "content": "Trying to register with name \`$username\` and uuid \`$minecraft_uuid\`.", + $disallow_mentions } } EOF - )" + )" + fi + fi + if [[ $command_name == unregister ]]; then + atrocity_debug "listing" + # TODO first ack then edit + list_watchers "$user" + fi + if [[ $command_name == unregister ]]; then + username="$(find_option "$1" username)" + atrocity_debug "Unregistering user with name $username" + # TODO first ack then edit + minecraft_uuid="$(curl "https://mowojang.matdoes.dev/$username" 2>/dev/null | jq -r .id)" + atrocity_debug "Got uuid: $minecraft_uuid" + if ! has_watched_account $user $minecraft_uuid; then + atrocity_rest POST "interactions/$id/$token/callback" "$(cat << EOF +{ + "type": 4, + "data": { + "content": "You are not watching the account with name \`$username\` and uuid \`$minecraft_uuid\`.", + $disallow_mentions + } +} +EOF + )" + else + remove_watched_account $user $minecraft_uuid + atrocity_rest POST "interactions/$id/$token/callback" "$(cat << EOF +{ + "type": 4, + "data": { + "content": "Unregister the name \`$username\` and uuid \`$minecraft_uuid\`.", + $disallow_mentions + } +} +EOF + )" + fi fi - fi - if [[ $type == 3 ]]; then - atrocity_debug "$1" - custom_id=($(printf '%s' "$1" | jq -r .data.custom_id)) - profile_id=${custom_id[0]} - minecraft_id=${custom_id[1]} - user_id="$(printf '%s' "$1" | jq -r .member.user.id)" - atrocity_debug "Profile: $profile_id, Minecraft: $minecraft_id, User: $user_id" fi } atrocity_on_unknown() { diff --git a/forgebotdata/d3cb85e2307548a1b213a9bfb62360c1 b/forgebotdata/d3cb85e2307548a1b213a9bfb62360c1 new file mode 100644 index 0000000..a748aa9 --- /dev/null +++ b/forgebotdata/d3cb85e2307548a1b213a9bfb62360c1 @@ -0,0 +1,2 @@ +310702108997320705 +310702108997320705 |