From 2fc6f9e66c17adfb4d2546ac5f47388f3f8e0f80 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 25 Oct 2018 13:40:29 -0500 Subject: [PATCH] Add function for ceelo to roll until it gets a hand --- lorebot/lorebot.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index 3ad27a6..292a676 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -355,9 +355,33 @@ func dicerollhandler(rtm *slack.RTM, ev *slack.MessageEvent) { } func ceelorollhandler(rtm *slack.RTM, ev *slack.MessageEvent) { - //fmt.Print(rand.Intn(100)) rand.Seed(time.Now().UnixNano()) - rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d, %d, %d", (rand.Intn(6)+1), (rand.Intn(6)+1), (rand.Intn(6)+1)), ev.Channel)) + + // set condition + hand := false + + for !hand { + roll0 := rand.Intn(6) + 1 + roll1 := rand.Intn(6) + 1 + roll2 := rand.Intn(6) + 1 + + rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d, %d, %d", roll0, roll1, roll2), ev.Channel)) + + // check for pair + if (roll0 == roll1) || (roll0 == roll2) || (roll1 == roll2) { + hand = true + } + a := fmt.Sprintf("%d%d%d", roll0, roll1, roll2) + // check for instant win + if strings.Contains(a, "4") && strings.Contains(a, "5") && strings.Contains(a, "6") { + hand = true + } + // check for instant loss + if strings.Contains(a, "1") && strings.Contains(a, "2") && strings.Contains(a, "3") { + hand = true + } + time.Sleep(1000 * time.Millisecond) + } } func rrhandler(rtm *slack.RTM, ev *slack.MessageEvent) {