sudobot/sudobot

59 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2018-06-15 02:26:03 +02:00
#!/bin/sh
# Toots a sudo insult
# Author: tastytea <tastytea@tastytea.de>
2018-06-15 11:36:46 +02:00
# Version: 2018-06-15_2
2018-06-15 02:26:03 +02:00
# Licence: CC-0 / Public Domain
download()
{
local files="https://www.sudo.ws/repos/sudo/raw-file/tip/plugins/sudoers/ins_{2001,classic,csops,goons,python}.h"
curl -s ${files} | grep -Eho '^ +".*"' | sed -r 's/^ +"(.*)"/\1/' > "${1}"
}
send()
{
2018-06-15 03:10:33 +02:00
local instance="${1}"
local token="${2}"
local db="${3}"
2018-06-15 02:26:03 +02:00
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 \
2018-06-15 11:36:46 +02:00
--data "spoiler_text=insult&status=${text}"$'\n\n#bot' https://${instance}/api/v1/statuses
2018-06-15 02:26:03 +02:00
}
main()
{
local cfg=~/.config/sudobot.cfg
local dir_db=~/.local/share/sudobot
local token=""
2018-06-15 03:10:33 +02:00
local instance=""
2018-06-15 02:26:03 +02:00
if [[ -f "${cfg}" ]]; then
2018-06-15 03:10:33 +02:00
exec 3<&0
exec 0< "${cfg}"
read token
2018-06-15 02:26:03 +02:00
token=$(echo $token | sed 's/^.*=//')
2018-06-15 03:10:33 +02:00
read instance
instance=$(echo $instance | sed 's/^.*=//')
exec 0<&3
2018-06-15 02:26:03 +02:00
else
echo "ERROR: no config file found in ${cfg}" >&2
2018-06-15 02:44:10 +02:00
echo "Create it with the contents: token=<your token>" >&2
2018-06-15 03:12:02 +02:00
echo " instance=<your instance>" >&2
2018-06-15 02:26:03 +02:00
exit 1
fi
if [[ ! -d "${dir_db}" ]]; then
mkdir -p "${dir_db}"
fi
if [[ ! -f "${dir_db}/insults.db" ]]; then
download "${dir_db}/insults.db"
fi
2018-06-15 03:10:33 +02:00
send "${instance}" "${token}" "${dir_db}/insults.db"
2018-06-15 02:26:03 +02:00
}
main