From 1d5f7346ef10a3d512f1eb8ff44f5040a3ec681a Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 02:46:50 -0400 Subject: [PATCH 01/10] Created the troll launcher trigger --- reactions.go | 2 ++ trollLauncher.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 trollLauncher.go diff --git a/reactions.go b/reactions.go index 8b19399..5d8fc6b 100644 --- a/reactions.go +++ b/reactions.go @@ -28,6 +28,8 @@ func reactions(message model.Message) (string, bool) { reactionContent = ipinfo(message.Content) case "!choose": reactionContent = choose(message.From, message.Content) + case "!troll" + reactionContent = troll(message.From, message.Content) } return reactionContent, reactionContent != "" diff --git a/trollLauncher.go b/trollLauncher.go new file mode 100644 index 0000000..e10b0fe --- /dev/null +++ b/trollLauncher.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + "math/rand" + "strings" +) + +func troll(nick, msg string) string { + const TROLL_USAGE = "Usage: !troll " + + msg = strings.Trim(msg, "!troll ") + if len(msg) == nil { + return TROLL_USAGE + } + + target := string(msg) + 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!" +} + +func launchTrolls() (numTrolls, dmg, dmgType) { + damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison", + "psychic", "necrotic", "radiant", "lightning", "thunder", "force"} + + trolls := rand.Intn(10) + if trolls == 0 { + return "" + } + + dmg := trollDamage(trolls) + + return string(trolls), dmg, damage_type[rand.Intn(12)] +} + +func trollDamage (trolls) string { + i := 0 + trollDmg := 0 + for i < trolls { + trollDmg += rand.Intn(20) + } + + if trollDmg == 0 { + return "miss" + } + + return string(trollDmg) +} \ No newline at end of file From 2f7c1752cc01c210e7e8ae0345a91c38d7a2d460 Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 02:55:27 -0400 Subject: [PATCH 02/10] Fixed a stupid newline it didn't like --- trollLauncher.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trollLauncher.go b/trollLauncher.go index e10b0fe..a81313c 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -28,8 +28,7 @@ func troll(nick, msg string) string { } func launchTrolls() (numTrolls, dmg, dmgType) { - damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison", - "psychic", "necrotic", "radiant", "lightning", "thunder", "force"} + damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison", "psychic", "necrotic", "radiant", "lightning", "thunder", "force"} trolls := rand.Intn(10) if trolls == 0 { From e2f70a004e9e41cc4ea89138aa2b686261920635 Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 02:57:51 -0400 Subject: [PATCH 03/10] I fixed the wrong thing. Like an idiot. Fixed the reactions.go file now --- reactions.go | 2 +- trollLauncher.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/reactions.go b/reactions.go index 5d8fc6b..287b6fc 100644 --- a/reactions.go +++ b/reactions.go @@ -28,7 +28,7 @@ func reactions(message model.Message) (string, bool) { reactionContent = ipinfo(message.Content) case "!choose": reactionContent = choose(message.From, message.Content) - case "!troll" + case "!troll": reactionContent = troll(message.From, message.Content) } diff --git a/trollLauncher.go b/trollLauncher.go index a81313c..e10b0fe 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -28,7 +28,8 @@ func troll(nick, msg string) string { } func launchTrolls() (numTrolls, dmg, dmgType) { - damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison", "psychic", "necrotic", "radiant", "lightning", "thunder", "force"} + damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison", + "psychic", "necrotic", "radiant", "lightning", "thunder", "force"} trolls := rand.Intn(10) if trolls == 0 { From f79d5d2993d0e54b489f96484be39d1c9c006e5d Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 03:01:52 -0400 Subject: [PATCH 04/10] I think I don't know how type declarations in functions work --- trollLauncher.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/trollLauncher.go b/trollLauncher.go index e10b0fe..ff5833e 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "math/rand" "strings" ) @@ -10,7 +9,7 @@ func troll(nick, msg string) string { const TROLL_USAGE = "Usage: !troll " msg = strings.Trim(msg, "!troll ") - if len(msg) == nil { + if len(msg) > 1 || < 1 { return TROLL_USAGE } @@ -27,7 +26,7 @@ func troll(nick, msg string) string { return nick + " fires " + numTrolls + " at " + target + ", dealing " + dmg + " points of " + dmgType + " damage!" } -func launchTrolls() (numTrolls, dmg, dmgType) { +func launchTrolls() (numTrolls, dmg, dmgType string) { damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison", "psychic", "necrotic", "radiant", "lightning", "thunder", "force"} @@ -41,7 +40,7 @@ func launchTrolls() (numTrolls, dmg, dmgType) { return string(trolls), dmg, damage_type[rand.Intn(12)] } -func trollDamage (trolls) string { +func trollDamage (trolls int) string { i := 0 trollDmg := 0 for i < trolls { From 9753336db5d26baa4ad0a2ea33af647273d857dd Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 03:04:19 -0400 Subject: [PATCH 05/10] Ugh. Logical operators. --- trollLauncher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trollLauncher.go b/trollLauncher.go index ff5833e..f66bfc5 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -9,7 +9,7 @@ func troll(nick, msg string) string { const TROLL_USAGE = "Usage: !troll " msg = strings.Trim(msg, "!troll ") - if len(msg) > 1 || < 1 { + if (len(msg) > 1 || < 1) { return TROLL_USAGE } From 9d21a8008988ceaa48ff2efc2364540436efba1d Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 03:06:46 -0400 Subject: [PATCH 06/10] More logical operator problems. More pain. More suffering. --- trollLauncher.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trollLauncher.go b/trollLauncher.go index f66bfc5..c468413 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -9,7 +9,7 @@ func troll(nick, msg string) string { const TROLL_USAGE = "Usage: !troll " msg = strings.Trim(msg, "!troll ") - if (len(msg) > 1 || < 1) { + if (len(msg) > 1 || len(msg) < 1) { return TROLL_USAGE } @@ -35,7 +35,7 @@ func launchTrolls() (numTrolls, dmg, dmgType string) { return "" } - dmg := trollDamage(trolls) + dmg = trollDamage(trolls) return string(trolls), dmg, damage_type[rand.Intn(12)] } From 7fce744c99292e13728cf63597848c683d7400d6 Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 03:09:14 -0400 Subject: [PATCH 07/10] Fixed my return statements. I think. --- trollLauncher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trollLauncher.go b/trollLauncher.go index c468413..bb9bb30 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -32,7 +32,7 @@ func launchTrolls() (numTrolls, dmg, dmgType string) { trolls := rand.Intn(10) if trolls == 0 { - return "" + return _, "", _ } dmg = trollDamage(trolls) From 32617bace2e7b7cf0069364d21deada16bd29448 Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 03:11:12 -0400 Subject: [PATCH 08/10] Okay, fine. I can't return _ as a value. Fuck you too, golang --- trollLauncher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trollLauncher.go b/trollLauncher.go index bb9bb30..5eba779 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -32,7 +32,7 @@ func launchTrolls() (numTrolls, dmg, dmgType string) { trolls := rand.Intn(10) if trolls == 0 { - return _, "", _ + return trolls, "", "" } dmg = trollDamage(trolls) From 754296c078908de3cc94809e437d31572073c8a3 Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 03:13:05 -0400 Subject: [PATCH 09/10] Yeah yeah, incompatible types. Cyka. --- trollLauncher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trollLauncher.go b/trollLauncher.go index 5eba779..760498f 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -32,7 +32,7 @@ func launchTrolls() (numTrolls, dmg, dmgType string) { trolls := rand.Intn(10) if trolls == 0 { - return trolls, "", "" + return string(trolls), "", "" } dmg = trollDamage(trolls) From e1fea430b0abf3a2c3afe9dbf1cf1aaee4f353f1 Mon Sep 17 00:00:00 2001 From: parsec Date: Thu, 8 Jul 2021 13:31:22 -0400 Subject: [PATCH 10/10] go fmt --- decisions.go | 30 ++++++------- trollLauncher.go | 110 +++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/decisions.go b/decisions.go index ac526fe..ab5d460 100644 --- a/decisions.go +++ b/decisions.go @@ -1,15 +1,15 @@ -package main - -import ( - "math/rand" - "strings" -) - -func choose(nick, msg string) string { - - choices := strings.Split(msg, "or") // declaring the choices array and splitting the msg content into parts - - choice := choices[rand.Intn(len(choices)-1)] // using rand to select a random choice - - return nick + ": The Powers that Be have chosen: " + choice // returning the choice -} +package main + +import ( + "math/rand" + "strings" +) + +func choose(nick, msg string) string { + + choices := strings.Split(msg, "or") // declaring the choices array and splitting the msg content into parts + + choice := choices[rand.Intn(len(choices)-1)] // using rand to select a random choice + + return nick + ": The Powers that Be have chosen: " + choice // returning the choice +} diff --git a/trollLauncher.go b/trollLauncher.go index 760498f..47f67e9 100644 --- a/trollLauncher.go +++ b/trollLauncher.go @@ -1,55 +1,55 @@ -package main - -import ( - "math/rand" - "strings" -) - -func troll(nick, msg string) string { - const TROLL_USAGE = "Usage: !troll " - - msg = strings.Trim(msg, "!troll ") - if (len(msg) > 1 || len(msg) < 1) { - return TROLL_USAGE - } - - target := string(msg) - 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!" -} - -func launchTrolls() (numTrolls, dmg, dmgType string) { - damage_type := [13]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)] -} - -func trollDamage (trolls int) string { - i := 0 - trollDmg := 0 - for i < trolls { - trollDmg += rand.Intn(20) - } - - if trollDmg == 0 { - return "miss" - } - - return string(trollDmg) -} \ No newline at end of file +package main + +import ( + "math/rand" + "strings" +) + +func troll(nick, msg string) string { + const TROLL_USAGE = "Usage: !troll " + + msg = strings.Trim(msg, "!troll ") + if len(msg) > 1 || len(msg) < 1 { + return TROLL_USAGE + } + + target := string(msg) + 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!" +} + +func launchTrolls() (numTrolls, dmg, dmgType string) { + damage_type := [13]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)] +} + +func trollDamage(trolls int) string { + i := 0 + trollDmg := 0 + for i < trolls { + trollDmg += rand.Intn(20) + } + + if trollDmg == 0 { + return "miss" + } + + return string(trollDmg) +}