Added instance selection

This commit is contained in:
tastytea 2018-06-15 03:10:33 +02:00
parent 850df5e6f8
commit 5adaef9bec
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
2 changed files with 14 additions and 5 deletions

View File

@ -6,6 +6,7 @@
wget https://schlomp.space/tastytea/sudobot/raw/branch/master/sudobot wget https://schlomp.space/tastytea/sudobot/raw/branch/master/sudobot
chmod +x sudobot chmod +x sudobot
echo "token=<your token here>" > ~/.config/sudobot.cfg echo "token=<your token here>" > ~/.config/sudobot.cfg
echo "instance=social.example.com" >> ~/.config/sudobot.cfg
./sudobot ./sudobot
``` ```

18
sudobot
View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# Toots a sudo insult # Toots a sudo insult
# Author: tastytea <tastytea@tastytea.de> # Author: tastytea <tastytea@tastytea.de>
# Version: 2018-06-15_1
# Licence: CC-0 / Public Domain # Licence: CC-0 / Public Domain
download() download()
@ -11,14 +12,15 @@ download()
send() send()
{ {
local token="${1}" local instance="${1}"
local db="${2}" local token="${2}"
local db="${3}"
local lines=$(wc -l ${db} | cut -d' ' -f1) local lines=$(wc -l ${db} | cut -d' ' -f1)
local random=$(( ( RANDOM % ${lines} ) + 1 )) local random=$(( ( RANDOM % ${lines} ) + 1 ))
local text="$(sed ${random}\!d ${db})" local text="$(sed ${random}\!d ${db})"
curl -sS --header "Authorization: Bearer ${token}" -X POST \ curl -sS --header "Authorization: Bearer ${token}" -X POST \
--data "spoiler_text=insult&status=${text}" https://botsin.space/api/v1/statuses --data "spoiler_text=insult&status=${text}" https://${instance}/api/v1/statuses
} }
main() main()
@ -26,10 +28,16 @@ main()
local cfg=~/.config/sudobot.cfg local cfg=~/.config/sudobot.cfg
local dir_db=~/.local/share/sudobot local dir_db=~/.local/share/sudobot
local token="" local token=""
local instance=""
if [[ -f "${cfg}" ]]; then if [[ -f "${cfg}" ]]; then
read token < "${cfg}" exec 3<&0
exec 0< "${cfg}"
read token
token=$(echo $token | sed 's/^.*=//') token=$(echo $token | sed 's/^.*=//')
read instance
instance=$(echo $instance | sed 's/^.*=//')
exec 0<&3
else else
echo "ERROR: no config file found in ${cfg}" >&2 echo "ERROR: no config file found in ${cfg}" >&2
echo "Create it with the contents: token=<your token>" >&2 echo "Create it with the contents: token=<your token>" >&2
@ -43,7 +51,7 @@ main()
download "${dir_db}/insults.db" download "${dir_db}/insults.db"
fi fi
send "${token}" "${dir_db}/insults.db" send "${instance}" "${token}" "${dir_db}/insults.db"
} }
main main