#!/bin/sh # Toots a sudo insult # Author: tastytea # Version: 2018-06-15_2 # 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 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}"$'\n\n#bot' https://${instance}/api/v1/statuses } main() { local cfg=~/.config/sudobot.cfg local dir_db=~/.local/share/sudobot local token="" local instance="" if [[ -f "${cfg}" ]]; then 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 echo " instance=" >&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 "${instance}" "${token}" "${dir_db}/insults.db" } main