Skip to content
1 change: 0 additions & 1 deletion reactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func reactions(message model.Message) (string, bool) {
reactionContent = decisions(message.From, message.Content)
case "!dadjoke":
reactionContent = jokeTrigger()

}

return reactionContent, reactionContent != ""
Expand Down
55 changes: 55 additions & 0 deletions trollLauncher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"math/rand"
"strings"
)

func troll(nick, msg string) string {
const TROLL_USAGE = "Usage: !troll <nick>"

msg = strings.Trim(msg, "!troll ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not strings.Split(msg, " ") and then check length to get the target for the troll launcher?

if len(msg) > 1 || len(msg) < 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is equivalent to len(msg) != 1

return TROLL_USAGE
}

target := string(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend against casting this here. If you want to treat a slice of length 1 as a string, just make it a string when you create it initially.

numTrolls, dmg, dmgType := launchTrolls()

switch dmg {
case "":
return "The troll launcher has malfunctioned."
case "miss":
return "Wha?! The trolls missed! That, like, never happens!"
}

return nick + " fires " + numTrolls + " at " + target + ", dealing " + dmg + " points of " + dmgType + " damage!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many concatenations here. Why not use a format string to make this simpler to read?

}

func launchTrolls() (numTrolls, dmg, dmgType string) {
damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a slice, not an array of fixed length.

Suggested change
damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison",
damage_type := []string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison",

"psychic", "necrotic", "radiant", "lightning", "thunder", "force"}

trolls := rand.Intn(10)
if trolls == 0 {
return string(trolls), "", ""
}

dmg = trollDamage(trolls)

return string(trolls), dmg, damage_type[rand.Intn(12)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating a []string with len 1 like a string. Fix the type at initialization so you can use it properly.

}
Comment on lines +33 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a zero case to trollDamage? Doing so would allow you to do something like

Suggested change
trolls := rand.Intn(10)
if trolls == 0 {
return string(trolls), "", ""
}
dmg = trollDamage(trolls)
return string(trolls), dmg, damage_type[rand.Intn(12)]
}
return string(trolls), trollDamage(rand.Intn[10]), damage_type[rand.Intn(12)]
}


func trollDamage(trolls int) string {
i := 0
trollDmg := 0
for i < trolls {
trollDmg += rand.Intn(20)
}

if trollDmg == 0 {
return "miss"
}

return string(trollDmg)
}
Comment on lines +43 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this function a little less surprising. We expect we are dealing with integers, so let's stay dealing with integers and only cast if we need to

Suggested change
func trollDamage(trolls int) string {
i := 0
trollDmg := 0
for i < trolls {
trollDmg += rand.Intn(20)
}
if trollDmg == 0 {
return "miss"
}
return string(trollDmg)
}
func trollDamage(trolls int) int {
dmg := 0
for i, _ range trolls {
dmg += rand.Intn(20)
}
return dmg
}