send multiple albums in one message
This commit is contained in:
parent
0e4fad2010
commit
6f30973cbd
1 changed files with 17 additions and 23 deletions
40
webhook
40
webhook
|
@ -1,6 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Settings
|
||||
# Discord Webhook URL (e.g. https://discord.com/api/webhooks/WEBHOOK_ID/TOKEN)
|
||||
discord_url=""
|
||||
# Message content (e.g. :newspaper: @everyone A new album has been added!"
|
||||
|
@ -10,29 +8,25 @@ embed_color=""
|
|||
# latestalbum path (for cron job, e.g. /home/amolinae/.local/bin/latestalbum)
|
||||
lapath=""
|
||||
|
||||
generate_post_data() {
|
||||
cat <<EOF
|
||||
{
|
||||
"content": "$message",
|
||||
"embeds": [{
|
||||
"title": "$albumtitle",
|
||||
"description": "$albumurl",
|
||||
"color": "$embed_color",
|
||||
"thumbnail": {
|
||||
"url": "$albumcover"
|
||||
}
|
||||
}]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
data="$($lapath)"
|
||||
|
||||
if [ -z "$data" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "$data" | paste -d '\t' - - - | while IFS=$'\t' read -r albumtitle albumurl albumcover; do
|
||||
payload=$(generate_post_data "$albumtitle" "$albumurl" "$albumcover")
|
||||
curl -H "Content-Type: application/json" -X POST -d "$payload" "$discord_url"
|
||||
done
|
||||
payload=$(echo "$data" | paste -d '\t' - - - | head -n10 | jq -Rn --arg msg "$message" --argjson color "$embed_color" '
|
||||
{
|
||||
content: $msg,
|
||||
embeds: [
|
||||
inputs
|
||||
| split("\t")
|
||||
| {
|
||||
title: .[0],
|
||||
description: .[1],
|
||||
color: $color,
|
||||
thumbnail: { url: .[2] }
|
||||
}
|
||||
]
|
||||
}
|
||||
')
|
||||
|
||||
curl -H "Content-Type: application/json" -X POST -d "$payload" "$discord_url"
|
Loading…
Add table
Reference in a new issue