diff --git a/bunnybot.go b/bunnybot.go index 0c94a18..e18741e 100644 --- a/bunnybot.go +++ b/bunnybot.go @@ -102,7 +102,7 @@ func message_create (s *discordgo.Session, m *discordgo.MessageCreate) { // determine our actions if message[0] == "coinflip" || message[0] == "coin" { // flip a coin - s.ChannelMessageSend(m.ChannelID, coinflip(m.Author.ID)) + s.ChannelMessageSend(m.ChannelID, coinflip(m.Author.ID, content)) } else if message[0] == "roll" { // roll a number s.ChannelMessageSend(m.ChannelID, roll(m.Author.ID)) } else if message[0] == "source" { // print source code diff --git a/commands.go b/commands.go index 461b669..18988b6 100644 --- a/commands.go +++ b/commands.go @@ -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 + "!**" } }