commands: Become case-insensitive on commands

master
Luther Wen Xu 2020-01-29 00:48:07 +07:00
parent e21aba4e60
commit 0e68c29b95
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
2 changed files with 6 additions and 4 deletions

@ -13,14 +13,15 @@ func Parse(s *discordgo.Session, m *discordgo.MessageCreate) {
return return
} }
if !strings.HasPrefix(m.Content, config.CommandPrefix) { if !strings.HasPrefix(strings.ToLower(m.Content), config.CommandPrefix) {
return 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 { for _, v := range list {
if v.Name == commands[0] { if v.Name == first {
v.Handler(s, commands, m) v.Handler(s, commands, m)
return return
} }

@ -3,6 +3,7 @@ package config
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"strings"
) )
type config struct { type config struct {
@ -44,7 +45,7 @@ func init() {
GeneralChannelID = output.ActiveNerf.GeneralChannelID GeneralChannelID = output.ActiveNerf.GeneralChannelID
NotInGeneralNerf = output.ActiveNerf.NotInGeneralNerf NotInGeneralNerf = output.ActiveNerf.NotInGeneralNerf
Admins = output.Admins Admins = output.Admins
CommandPrefix = output.CommandPrefix CommandPrefix = strings.ToLower(output.CommandPrefix)
GuildID = output.GuildID GuildID = output.GuildID
PrestigeRequirement = output.PrestigeRequirement PrestigeRequirement = output.PrestigeRequirement
StarChannel = output.StarChannel StarChannel = output.StarChannel