added ability to have custom coinflips

This commit is contained in:
2020-09-12 02:31:39 -05:00
parent 17d9128577
commit 52b4bb6a1a
2 changed files with 18 additions and 4 deletions

View File

@@ -8,18 +8,32 @@ import (
"math"
"math/rand"
"strconv"
"strings"
)
// flip a coin
func coinflip(author string) string{
func coinflip(author string, content string) string{
// get a random 1 or 0
num := math.Mod(float64(rand.Intn(100)), 2) // modulo of random number between 0 and 100
// default heads/tails text in case nothing was set from the user
heads := "heads"
tails := "tails"
// try to split to see if heads/tails were set by user
message := strings.Fields(content)
// if the custom heads/tails was requested, set it
if(len(message) > 2) {
heads = message[1]
tails = message[2]
}
// return string based on number
if int(num) == 0 { // heads
return "<@" + author + "> flipped a coin, it landed on **heads!**"
return "<@" + author + "> flipped a coin, it landed on **" + heads + "!**"
} else { // tails
return "<@" + author + "> flipped a coin, it landed on **tails!**"
return "<@" + author + "> flipped a coin, it landed on **" + tails + "!**"
}
}