Skip to content

Instantly share code, notes, and snippets.

@daisyUniverse
Created May 8, 2024 01:41
Show Gist options
  • Save daisyUniverse/0961eedf88663ea0b980ad84e0344b55 to your computer and use it in GitHub Desktop.
Save daisyUniverse/0961eedf88663ea0b980ad84e0344b55 to your computer and use it in GitHub Desktop.
Bash script that automatically uploads fresh minecraft screenshots to discord using webhooks
#!/bin/bash
# REQUIRES: inotify-tools, bash, curl
# Automatic Image Webhook Poster
# Detects when an image is created in a specific folder, uploads it to a filehost, and then posts the link in an Embed to a Discord webhook
# Essentially made just to allow for automatic minecraft screenshot uploads as soon as I press F2
# Daisy Universe [D]
# 05 . 07 . 24
webhook_url="WEBHOOK"
# You will need to get a discord Webhook URL to paste here
filehost_url="https://basedbin.fly.dev"
# You should point this to a trusted filehost. this script is set up to use https://github.com/wantguns/bin
watch_path="/home/daisy/.local/share/PrismLauncher/instances/1.20.6/.minecraft/screenshots/"
# Pont this to your screenshots folder
generate_payload() {
cat <<EOF
{
"embeds": [{
"image": {
"url": "$1"
}
}]
}
EOF
}
upload () {
filepath="$1"
filename=$(basename -- "$filepath")
extension="${filename##*.}"
response=$(curl --silent --data-binary @${filepath:-/dev/stdin} --url $filehost_url)
echo "$filehost_url$response"".""$extension"
}
fire_webhook() {
link="$1"
echo "$(generate_payload $link)"
curl --silent -H "Content-Type: application/json" -X POST -d "$(generate_payload $link)" $webhook_url
}
fuckitup() {
# Sleep so the file has time to write before we try to upload it
sleep 2
file="$1"
echo "uploading '$file' to $filehost_url"
link="$(upload $watch_path$file)"
fire_webhook $link
}
inotifywait -r -m $watch_path |
while read a b file; do
[[ $b == *CREATE* ]] && fuckitup $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment