Added instance selection
This commit is contained in:
parent
850df5e6f8
commit
5adaef9bec
|
@ -6,6 +6,7 @@
|
|||
wget https://schlomp.space/tastytea/sudobot/raw/branch/master/sudobot
|
||||
chmod +x sudobot
|
||||
echo "token=<your token here>" > ~/.config/sudobot.cfg
|
||||
echo "instance=social.example.com" >> ~/.config/sudobot.cfg
|
||||
./sudobot
|
||||
```
|
||||
|
||||
|
|
18
sudobot
18
sudobot
|
@ -1,6 +1,7 @@
|
|||
#!/bin/sh
|
||||
# Toots a sudo insult
|
||||
# Author: tastytea <tastytea@tastytea.de>
|
||||
# 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=<your 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user