diff --git a/README.md b/README.md index 8923712..4c05d3b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ wget https://schlomp.space/tastytea/sudobot/raw/branch/master/sudobot chmod +x sudobot echo "token=" > ~/.config/sudobot.cfg +echo "instance=social.example.com" >> ~/.config/sudobot.cfg ./sudobot ``` diff --git a/sudobot b/sudobot index 86f4423..c8aa478 100755 --- a/sudobot +++ b/sudobot @@ -1,6 +1,7 @@ #!/bin/sh # Toots a sudo insult # Author: tastytea +# Version: 2018-06-15_1 # Licence: CC-0 / Public Domain download() @@ -11,14 +12,15 @@ download() send() { - local token="${1}" - local db="${2}" + local instance="${1}" + local token="${2}" + local db="${3}" local lines=$(wc -l ${db} | cut -d' ' -f1) local random=$(( ( RANDOM % ${lines} ) + 1 )) local text="$(sed ${random}\!d ${db})" 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() @@ -26,10 +28,16 @@ main() local cfg=~/.config/sudobot.cfg local dir_db=~/.local/share/sudobot local token="" + local instance="" if [[ -f "${cfg}" ]]; then - read token < "${cfg}" + exec 3<&0 + exec 0< "${cfg}" + read token token=$(echo $token | sed 's/^.*=//') + read instance + instance=$(echo $instance | sed 's/^.*=//') + exec 0<&3 else echo "ERROR: no config file found in ${cfg}" >&2 echo "Create it with the contents: token=" >&2 @@ -43,7 +51,7 @@ main() download "${dir_db}/insults.db" fi - send "${token}" "${dir_db}/insults.db" + send "${instance}" "${token}" "${dir_db}/insults.db" } main