initial commit
This commit is contained in:
commit
ac9dfa999f
48
sudobot
Executable file
48
sudobot
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/sh
|
||||
# Toots a sudo insult
|
||||
# Author: tastytea <tastytea@tastytea.de>
|
||||
# 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()
|
||||
{
|
||||
local token="${1}"
|
||||
local db="${2}"
|
||||
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
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
local cfg=~/.config/sudobot.cfg
|
||||
local dir_db=~/.local/share/sudobot
|
||||
local token=""
|
||||
|
||||
if [[ -f "${cfg}" ]]; then
|
||||
read token < "${cfg}"
|
||||
token=$(echo $token | sed 's/^.*=//')
|
||||
else
|
||||
echo "ERROR: no config file found in ${cfg}" >&2
|
||||
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
|
||||
|
||||
send "${token}" "${dir_db}/insults.db"
|
||||
}
|
||||
|
||||
main
|
Loading…
Reference in New Issue
Block a user