From 0e68c29b95732324fc90bd02dd3372ab05167004 Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Wed, 29 Jan 2020 00:48:07 +0800 Subject: [PATCH] commands: Become case-insensitive on commands --- modules/commands/listener.go | 7 ++++--- modules/config/config.go | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/commands/listener.go b/modules/commands/listener.go index efd03b3..2010336 100644 --- a/modules/commands/listener.go +++ b/modules/commands/listener.go @@ -13,14 +13,15 @@ func Parse(s *discordgo.Session, m *discordgo.MessageCreate) { return } - if !strings.HasPrefix(m.Content, config.CommandPrefix) { + if !strings.HasPrefix(strings.ToLower(m.Content), config.CommandPrefix) { return } - commands := strings.Split(strings.TrimPrefix(m.Content, config.CommandPrefix), " ") + commands := strings.Split(m.Content[len(config.CommandPrefix):], " ") + first := strings.ToLower(commands[0]) for _, v := range list { - if v.Name == commands[0] { + if v.Name == first { v.Handler(s, commands, m) return } diff --git a/modules/config/config.go b/modules/config/config.go index fb18152..8690171 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -3,6 +3,7 @@ package config import ( "encoding/json" "io/ioutil" + "strings" ) type config struct { @@ -44,7 +45,7 @@ func init() { GeneralChannelID = output.ActiveNerf.GeneralChannelID NotInGeneralNerf = output.ActiveNerf.NotInGeneralNerf Admins = output.Admins - CommandPrefix = output.CommandPrefix + CommandPrefix = strings.ToLower(output.CommandPrefix) GuildID = output.GuildID PrestigeRequirement = output.PrestigeRequirement StarChannel = output.StarChannel