From ab5ce7cc5fe34d6c1fd671c53ce2441f6f708bdc Mon Sep 17 00:00:00 2001 From: kageru Date: Tue, 5 Jun 2018 11:50:40 +0200 Subject: [PATCH] added switch to make commands case-insensitive --- command.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/command.go b/command.go index 0f7e9f3..9a97f24 100644 --- a/command.go +++ b/command.go @@ -27,6 +27,7 @@ type Command struct { DeleteInput bool // defaults to false DMOnly bool // defaults to false AdminOnly bool // defaults to false + IgnoreCase bool // defaults to false // for custom commands that go beyond prints and deletions Function func(*discordgo.Session, *discordgo.MessageCreate) } @@ -37,6 +38,9 @@ func registerCommand(command Command) { fmt.Println("Cannot register a command with no trigger. Skipping.") return } + if command.IgnoreCase { + command.Trigger = strings.ToLower(command.Trigger) + } commands = append(commands, command) } @@ -47,28 +51,32 @@ func evaluateMessage(s *discordgo.Session, m *discordgo.MessageCreate) { } fmt.Println(m.Content) for _, command := range commands { + content := m.Content + if command.IgnoreCase { + content = strings.ToLower(content) + } if command.RequiresMention { command.Trigger = fmt.Sprintf(command.Trigger, s.State.User.ID) } switch command.Type { case CommandTypePrefix: - if strings.HasPrefix(m.Content, command.Trigger) { + if strings.HasPrefix(content, command.Trigger) { executeCommand(s, m, command) return } case CommandTypeFullMatch: - if m.Content == command.Trigger { + if content == command.Trigger { executeCommand(s, m, command) return } case CommandTypeRegex: - match, _ := regexp.MatchString(command.Trigger, m.Content) + match, _ := regexp.MatchString(command.Trigger, content) if match { executeCommand(s, m, command) return } case CommandTypeContains: - if strings.Contains(m.Content, command.Trigger) { + if strings.Contains(content, command.Trigger) { executeCommand(s, m, command) return } @@ -118,3 +126,6 @@ func redirectComplaint(s *discordgo.Session, m *discordgo.MessageCreate) { s.ChannelMessageSendEmbed(config.ModChannel, embed) } +func echoMessage(s *discordgo.Session, m *discordgo.MessageCreate) { + s.ChannelMessageSend(m.ChannelID, m.Content) +}