2022-09-09 15:23:03 +00:00
|
|
|
package bot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2022-09-15 14:32:37 +00:00
|
|
|
"git.kill0.net/chill9/beepboop/lib/rps"
|
2022-09-09 15:23:03 +00:00
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (b *Bot) RpsCommand() CommandFunc {
|
|
|
|
return func(args []string, m *discordgo.MessageCreate) error {
|
|
|
|
if len(args) != 1 {
|
2022-09-14 13:34:51 +00:00
|
|
|
b.Session.ChannelMessageSend(
|
|
|
|
m.ChannelID, "help: `!rps (rock | paper | scissors)`",
|
|
|
|
)
|
2022-09-09 15:23:03 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-18 19:57:15 +00:00
|
|
|
pc := strings.ToLower(args[0]) // player's choice
|
|
|
|
|
|
|
|
g := rps.NewGame(rps.RulesRps, rps.EmojiMapRps)
|
2022-09-09 15:23:03 +00:00
|
|
|
|
2022-09-18 19:57:15 +00:00
|
|
|
bc := g.Rand() // bot's choice
|
|
|
|
|
|
|
|
s, err := g.Play(bc, pc)
|
|
|
|
if _, ok := err.(rps.InvalidChoiceError); ok {
|
2022-09-14 13:34:51 +00:00
|
|
|
b.Session.ChannelMessageSend(
|
|
|
|
m.ChannelID, "help: `!rps (rock | paper | scissors)`",
|
|
|
|
)
|
2022-09-09 15:23:03 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 19:57:15 +00:00
|
|
|
b.Session.ChannelMessageSend(m.ChannelID, s)
|
2022-09-15 14:32:37 +00:00
|
|
|
|
2022-09-09 15:23:03 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|