From 0ff2b742398abbbdc5aaa44d02cafb5e6d9bac1a Mon Sep 17 00:00:00 2001 From: lyx0 Date: Fri, 15 Oct 2021 18:21:17 +0200 Subject: [PATCH] add pyramid command --- pkg/commands/pyramid.go | 49 +++++++++++++++++++++++++++++++++++++++++ pkg/handlers/command.go | 11 +++++++++ 2 files changed, 60 insertions(+) create mode 100644 pkg/commands/pyramid.go diff --git a/pkg/commands/pyramid.go b/pkg/commands/pyramid.go new file mode 100644 index 0000000..aa2e7e7 --- /dev/null +++ b/pkg/commands/pyramid.go @@ -0,0 +1,49 @@ +package commands + +import ( + "fmt" + "strconv" + "strings" + + "github.com/gempir/go-twitch-irc/v2" +) + +func Pyramid(channel string, size string, emote string, client *twitch.Client) { + if size[0] == '.' || size[0] == '/' { + client.Say(channel, ":tf:") + return + } + + if emote[0] == '.' || emote[0] == '/' { + client.Say(channel, ":tf:") + return + } + + pyramidSize, err := strconv.Atoi(size) + pyramidEmote := fmt.Sprint(emote + " ") + + if err != nil { + client.Say(channel, "Something went wrong") + } + + if pyramidSize == 1 { + client.Say(channel, fmt.Sprint(pyramidEmote+"...")) + return + } + + if pyramidSize > 20 { + client.Say(channel, "Max pyramid size is 20") + return + } + + for i := 0; i <= pyramidSize; i++ { + pyramidMessageAsc := strings.Repeat(pyramidEmote, i) + // fmt.Println(pyramidMessageAsc) + client.Say(channel, pyramidMessageAsc) + } + for j := pyramidSize - 1; j >= 0; j-- { + pyramidMessageDesc := strings.Repeat(pyramidEmote, j) + // fmt.Println(pyramidMessageDesc) + client.Say(channel, pyramidMessageDesc) + } +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index f1b66d3..152de61 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -108,5 +108,16 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient) } + case "pyramid": + if msgLen != 3 { + twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]") + return + } else if utils.ElevatedPrivsMessage(message) { + commands.Pyramid(message.Channel, cmdParams[1], cmdParams[2], twitchClient) + return + } else { + twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan") + } + } }