Files
stormbot/modules/bash/bash.sh
2025-10-24 17:14:52 -04:00

26 lines
762 B
Bash
Executable File

#!/usr/bin/env bash
[ -f functions.sh ] && source functions.sh
# Dependencies required by this module
dependencies=("curl" "w3m" "grep" "sed" "iconv")
set -f
quote="$(curl -s --connect-timeout 5 --max-time 10 http://bash.org/?random)"
if [[ -z "$quote" ]]; then
msg "$2" "$1: Sorry, couldn't fetch a bash.org quote right now."
set +f
exit 1
fi
quote="$(echo "$quote" | grep -m 1 -A 10 '"Permanent link to this quote."')"
quote="${quote#*class=\"qt\">}"
quote="${quote//&lt;/ <}"
quote="${quote//&gt;/> }"
quote="${quote%%<p class*}"
quote="$(echo "$quote" | w3m -dump -T text/html)"
if [[ ${#quote} -lt 5 ]]; then
msg "$2" "$1: Sorry, couldn't parse the bash.org quote."
else
msg "$2" "$(echo "$quote" | iconv -f utf-8 -t ascii)"
fi
set +f