Skip to content

Daily Advice

Daily Advice #464

Workflow file for this run

name: Daily Advice
on:
schedule:
- cron: '0 17 * * *' # Runs every day at 17:00
workflow_dispatch:
jobs:
send_advice:
runs-on: ubuntu-latest
steps:
- name: Send daily advice
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
# Download JSON data
advices_json_url="https://raw.githubusercontent.com/DraftBot-A-Discord-Adventure/DraftBot/master/resources/text/advices.json"
advices_json=$(curl -s "$advices_json_url")
# Extract advice strings
advices_list=$(echo "$advices_json" | jq -r '.translations.fr.advices[]')
# Get a random advice
random_advice=$(echo "$advices_list" | shuf -n 1)
# Replace {command:...} with /...
random_advice=$(echo "$random_advice" | sed -E 's/\{command:([^}]+)\}/\/\1/g')
# Send advice to Discord webhook
content=":bulb: **Astuce du jour** :\n\n$random_advice\n\n<@&1136367073317113917>"
payload="{\"content\": \"$content\"}"
curl -s -X POST -H "Content-Type: application/json" -d "$payload" $DISCORD_WEBHOOK_URL