stormbot/modules/rps/rps.sh

36 lines
1.1 KiB
Bash
Raw Normal View History

2016-09-03 02:24:14 -04:00
[ -f functions.sh ] && source functions.sh
cpu="$(shuf -n 1 -e PAPER ROCK SCISSORS)"
player="$3"
2016-09-03 02:24:14 -04:00
case "${player^^}" in
R|RO|ROC|ROCK)
player="ROCK"
;;
2016-09-03 02:24:14 -04:00
P|PA|PAP|PAPE|PAPER)
player="PAPER"
;;
2016-09-03 02:24:14 -04:00
S|SC|SCI|SCIS|SCISS|SCISSO|SCISSOR|SCISSORS)
player="SCISSORS"
;;
2016-09-03 02:24:14 -04:00
*)
player="INVALID"
esac
2016-09-03 10:25:55 -04:00
if [[ "$player" = "INVALID" ]]; then
2016-09-03 02:24:14 -04:00
msg "$2" "$1: Please select PAPER, ROCK, or SCISSORS."
2016-09-03 10:25:55 -04:00
elif [[ "$cpu" = "$player" ]]; then
2016-09-03 02:24:14 -04:00
msg "$2" "$1: You and I both selected $player, so we tied."
2016-09-03 10:25:55 -04:00
elif [[ "$cpu" = "PAPER" && "$player" != "SCISSORS" ]]; then
msg "$2" "$1: my $cpu beats your $player!"
elif [[ "$cpu" = "ROCK" && "$player" != "PAPER" ]]; then
msg "$2" "$1: my $cpu beats your $player!"
elif [[ "$cpu" = "SCISSORS" && "$player" != "ROCK" ]]; then
msg "$2" "$1: my $cpu beats your $player!"
elif [[ "$player" = "PAPER" && "$cpu" != "SCISSORS" ]]; then
2016-09-03 02:24:14 -04:00
msg "$2" "$1: your $player beats my $cpu!"
2016-09-03 10:25:55 -04:00
elif [[ "$player" = "ROCK" && "$cpu" != "PAPER" ]]; then
2016-09-03 02:24:14 -04:00
msg "$2" "$1: your $player beats my $cpu!"
else
2016-09-03 02:24:14 -04:00
msg "$2" "$1: your $player beats my $cpu!"
fi