From 2c262a87705530f043ffc91f11bf926800743934 Mon Sep 17 00:00:00 2001 From: haui Date: Fri, 30 Jan 2026 13:59:20 +0100 Subject: [PATCH 1/7] get working kde popup --- main.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.sh b/main.sh index 6e62af4..f8c7a5d 100755 --- a/main.sh +++ b/main.sh @@ -1,8 +1,12 @@ #!/bin/sh - +while /bin/true; do #if json quote list exist if [ -f "./quotes.txt" ]; then -shuf -n 1 ./quotes.txt +CurrentQuote=$(shuf -n 1 ./quotes.txt) +#echo ${CurrentQuote} +kdialog --passivepopup "${CurrentQuote}" else echo "file does not exist!" fi +sleep 300 +done From 45816e02395c3c5584564d7089bc9a7bff8438ca Mon Sep 17 00:00:00 2001 From: haui Date: Sun, 1 Feb 2026 20:20:26 +0100 Subject: [PATCH 2/7] make bot functional --- .gitignore | 4 ++++ Dockerfile | 9 +++++++++ main.sh | 22 ++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 Dockerfile 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 From 24f69aa520b9e9e5a5e909708f26bc631f7324df Mon Sep 17 00:00:00 2001 From: haui Date: Sun, 1 Feb 2026 20:30:08 +0100 Subject: [PATCH 3/7] add compose example --- docker-compose-example.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docker-compose-example.yml diff --git a/docker-compose-example.yml b/docker-compose-example.yml new file mode 100644 index 0000000..cda0e9f --- /dev/null +++ b/docker-compose-example.yml @@ -0,0 +1,9 @@ +services: + quotebot: + container_name: quotebot + image: haui/quotebot + build: ./ + volumes: + - ./.env:/usr/local/quotebot/.env + - ./quotes.txt:/usr/local/quotebot/quotes.txt + restart: unless-stopped From 2a2ab5ffff5e1eaad347746b05befa13e0cded60 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 2 Feb 2026 11:45:56 +0100 Subject: [PATCH 4/7] README.md aktualisiert --- README | 11 ----------- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 11 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 912656f..0000000 --- a/README +++ /dev/null @@ -1,11 +0,0 @@ -Hello World! - -This is a quote bot (shell script) which shows a random quote from a file every time it is invoked. - -Note: You need to make it executable to use it. - -The reason i use a file and not the web is hackability, at the moment. - -Please provide a quotes.txt file with one line per quote. - -Have fun! diff --git a/README.md b/README.md new file mode 100644 index 0000000..9af66ac --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +Hello World! + +This is a quote bot (shell script) which shows a random quote from a file every time it is invoked. + +Note: You need to make it executable to use it. + +```chmod u+x main.sh``` + +The reason i use a file and not the web is hackability, at the moment. + +Please provide a quotes.txt file with one line per quote. + +## REST-Version +The Rest-Version has functioning mastodon connection over REST-API. You need to run the full oauth user authentication before. I tried to use the "Development" section in Mastodon Preferences but it didnt work. What did work was the out of bounds creation of a new application and authenticating it with a user. It does not appear in the user Development section. + +Here's the documentation for the api: +https://docs.joinmastodon.org/client/intro/ + +You essentially need to run the following commands: + +``` +#test connection +curl https://mastodon.example/endpoint?q=test&n=0 + +# create app https://docs.joinmastodon.org/methods/apps/ this will return secrets, write them down! +curl -X POST -F 'client_name=Bot3' -F 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' -F 'scopes=read write push' -F 'website=https://myapp.example' https://mastodon.example.com/api/v1/apps + +#verify the app works https://docs.joinmastodon.org/methods/apps/#verify_credentials +curl -H 'Authorization: Bearer ****' https://mastodon.example.com/api/v1/accounts/verify_credentials + +#authorize a user https://docs.joinmastodon.org/methods/oauth/#authorize and https://docs.joinmastodon.org/client/authorized/#login you will have to input this in a browser then login and authorize the app, it will provide an authorization code +https://mastodon.example/oauth/authorize +?client_id=CLIENT_ID +&scope=read+write+push +&redirect_uri=urn:ietf:wg:oauth:2.0:oob +&response_type=code + +#obtain token https://docs.joinmastodon.org/methods/oauth/#token +curl -X POST -F 'grant_type=authorization_code' -F 'client_id=\*' -F 'client_secret=\*' -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -F 'code=\*' https://mastodon.example.com/oauth/token + + +#make your first post +curl -i -H 'Authorization: Bearer ***' -d 'status=Hello World!' https://mastodon.example.com/api/v1/statuses + +``` + +To find this out took me hours and hours. I'm writing it down to spare you time. + +Have fun! From b66ec3ca1fb979e5c4fad953a9ff8d77534b4819 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 2 Feb 2026 12:17:38 +0100 Subject: [PATCH 5/7] README.md aktualisiert --- README.md | 58 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9af66ac..f2ea4c4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a quote bot (shell script) which shows a random quote from a file every Note: You need to make it executable to use it. -```chmod u+x main.sh``` + chmod u+x main.sh The reason i use a file and not the web is hackability, at the moment. @@ -18,32 +18,50 @@ https://docs.joinmastodon.org/client/intro/ You essentially need to run the following commands: -``` -#test connection -curl https://mastodon.example/endpoint?q=test&n=0 -# create app https://docs.joinmastodon.org/methods/apps/ this will return secrets, write them down! -curl -X POST -F 'client_name=Bot3' -F 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' -F 'scopes=read write push' -F 'website=https://myapp.example' https://mastodon.example.com/api/v1/apps +### test connection -#verify the app works https://docs.joinmastodon.org/methods/apps/#verify_credentials -curl -H 'Authorization: Bearer ****' https://mastodon.example.com/api/v1/accounts/verify_credentials + curl https://mastodon.example/endpoint?q=test&n=0 -#authorize a user https://docs.joinmastodon.org/methods/oauth/#authorize and https://docs.joinmastodon.org/client/authorized/#login you will have to input this in a browser then login and authorize the app, it will provide an authorization code -https://mastodon.example/oauth/authorize -?client_id=CLIENT_ID -&scope=read+write+push -&redirect_uri=urn:ietf:wg:oauth:2.0:oob -&response_type=code +### create app +https://docs.joinmastodon.org/methods/apps/ +this will return secrets, write them down! -#obtain token https://docs.joinmastodon.org/methods/oauth/#token -curl -X POST -F 'grant_type=authorization_code' -F 'client_id=\*' -F 'client_secret=\*' -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -F 'code=\*' https://mastodon.example.com/oauth/token + curl -X POST -F 'client_name=Bot3' -F 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' -F 'scopes=read write push' -F 'website=https://myapp.example' https://mastodon.example.com/api/v1/apps +### verify the app works +https://docs.joinmastodon.org/methods/apps/#verify_credentials -#make your first post -curl -i -H 'Authorization: Bearer ***' -d 'status=Hello World!' https://mastodon.example.com/api/v1/statuses + curl -H 'Authorization: Bearer ****' https://mastodon.example.com/api/v1/accounts/verify_credentials -``` +### authorize a user +https://docs.joinmastodon.org/methods/oauth/#authorize and https://docs.joinmastodon.org/client/authorized/#login you will have to input this in a browser then login and authorize the app, it will provide an authorization code + + https://mastodon.example/oauth/authorize + ?client_id=CLIENT_ID + &scope=read+write+push + &redirect_uri=urn:ietf:wg:oauth:2.0:oob + &response_type=code + +### obtain token +https://docs.joinmastodon.org/methods/oauth/#token + + curl -X POST -F 'grant_type=authorization_code' -F 'client_id=\*' -F 'client_secret=\*' -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -F 'code=\*' https://mastodon.example.com/oauth/token + +### make your first post + + curl -i -H 'Authorization: Bearer ***' -d 'status=Hello World!' https://mastodon.example.com/api/v1/statuses To find this out took me hours and hours. I'm writing it down to spare you time. -Have fun! +## docker +you can use the dockerfile and docker-compose.yml i provided. I will at some point push a docker image which is ready to use. Until then you will have to build the image first. Here's how: + + git clone https://code.kraftw3rk.de/alex/quote-bot.git + git switch rest-bot + touch quotes.txt #(fill with quotes, one per line, no longer than your instance character limit!) + touch .env #(fill with "UserToken='***'" insert the token where the stars are!) + mv docker-compose-example.yml docker-compose.yml + docker compose up -d + +Have fun! \ No newline at end of file From 8797d25b56777e8ee3a88773b5b5ece1869d2e1f Mon Sep 17 00:00:00 2001 From: haui Date: Mon, 2 Feb 2026 12:22:52 +0100 Subject: [PATCH 6/7] export instance to .env and make .env-example --- .env-example | 2 ++ main.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .env-example diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..d48d0bf --- /dev/null +++ b/.env-example @@ -0,0 +1,2 @@ +UserToken='***' +TargetInstance='***' diff --git a/main.sh b/main.sh index 73b2225..689d378 100755 --- a/main.sh +++ b/main.sh @@ -11,7 +11,7 @@ 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 + "${TargetInstance}/api/v1/statuses") # HTTP/1.1 echo "${result}" From a07e5c9fd49ba3697cbc54e7117b3724077aa4c7 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 2 Feb 2026 12:26:06 +0100 Subject: [PATCH 7/7] README.md aktualisiert --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2ea4c4..d19dad5 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,16 @@ https://docs.joinmastodon.org/methods/oauth/#token To find this out took me hours and hours. I'm writing it down to spare you time. +## automation +the oauth part will me mostly automated at some point but rn it is still manual. feel free to help automate it. + ## docker you can use the dockerfile and docker-compose.yml i provided. I will at some point push a docker image which is ready to use. Until then you will have to build the image first. Here's how: git clone https://code.kraftw3rk.de/alex/quote-bot.git git switch rest-bot touch quotes.txt #(fill with quotes, one per line, no longer than your instance character limit!) - touch .env #(fill with "UserToken='***'" insert the token where the stars are!) + mv .env-example .env #(insert the user token where the stars are!) mv docker-compose-example.yml docker-compose.yml docker compose up -d