2020-08-11 19:35:45 -04:00
|
|
|
[ -f functions.sh ] && source functions.sh
|
|
|
|
|
|
|
|
roll_dice() {
|
|
|
|
local count=${1%[dD]*}
|
|
|
|
local sides=${1#*[dD]}
|
|
|
|
local i
|
|
|
|
local total=0
|
|
|
|
for i in $(seq $count) ; do
|
|
|
|
total=$((total + $RANDOM % $sides + 1))
|
|
|
|
done
|
|
|
|
echo $total
|
|
|
|
}
|
|
|
|
|
|
|
|
rollString="${3##* }"
|
2020-08-11 19:40:30 -04:00
|
|
|
if ! [[ "$rollString" =~ ^[1-9][0-9]*[dD][1-9][0-9]*$ ]]; then
|
2020-08-11 19:35:45 -04:00
|
|
|
msg "$2" "${1}: Usage is roll #d# where # is greater than 0."
|
|
|
|
else
|
|
|
|
msg "$2" "$1:: I rolled ${rollString} and got a total of $(roll_dice ${rollString})."
|
|
|
|
fi
|