diff --git a/.gitignore b/.gitignore index 4fe0dc9..b8dc55d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ quotes.json quotes.txt +.env +Credentials +docker-compose.yml +oauth.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a7be026 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM bash:5 +WORKDIR /usr/local/quotebot + +COPY main.sh ./ + +RUN adduser -S quotebot --disabled-password --uid 1000 && apk add curl && apk add uuidgen +USER quotebot + +ENTRYPOINT ["bash", "/usr/local/quotebot/main.sh"] diff --git a/main.sh b/main.sh index f8c7a5d..73b2225 100755 --- a/main.sh +++ b/main.sh @@ -1,12 +1,22 @@ -#!/bin/sh +#!/bin/bash +set -x +IdempotencyKey="$(uuidgen)" +. ./.env +Authorization="${UserToken}" while /bin/true; do -#if json quote list exist if [ -f "./quotes.txt" ]; then -CurrentQuote=$(shuf -n 1 ./quotes.txt) -#echo ${CurrentQuote} -kdialog --passivepopup "${CurrentQuote}" +status=$(shuf -n 1 ./quotes.txt) + +result=$(curl -X POST \ + -H "Authorization: Bearer ${Authorization}" \ + -H "Idempotency-Key: ${IdempotencyKey}" \ + -d "status=${status}" \ + "https://mastodon.giftedmc.com/api/v1/statuses") # HTTP/1.1 + +echo "${result}" + else echo "file does not exist!" fi -sleep 300 +sleep 3600 done