Dice module added under the name roll.
This commit is contained in:
parent
0b28d9c63a
commit
224426be35
19
modules/roll/roll.sh
Executable file
19
modules/roll/roll.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
[ -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##* }"
|
||||||
|
if ! [[ "$rollString" =~ ^[1-9]+[dD][1-9][0-9]*$ ]]; then
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user