making Command() less ugly

This commit is contained in:
Elliott Pardee 2015-01-12 18:48:59 -05:00
parent 0944dbf0ff
commit 8d26e2b35d

14
bot.go
View File

@ -56,6 +56,7 @@ func (b *Bot) Command(nick string, msg string) {
// TODO: Check if mode is enabled and if command can be applied. // TODO: Check if mode is enabled and if command can be applied.
if strings.HasPrefix(msg, ".set") && len(args) == 4 { if strings.HasPrefix(msg, ".set") && len(args) == 4 {
if nick == dunmas { if nick == dunmas {
fillCharmap(args[0], args[1], args[2], args[3]) fillCharmap(args[0], args[1], args[2], args[3])
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + "in " + args[1] + " is set to " + args[3] + ".") fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + "in " + args[1] + " is set to " + args[3] + ".")
@ -64,10 +65,14 @@ func (b *Bot) Command(nick string, msg string) {
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + " in " + args[1] + " is set to " + args[3] + ".") fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + " in " + args[1] + " is set to " + args[3] + ".")
b.Say(nick + " used override, it's super effective!") b.Say(nick + " used override, it's super effective!")
} }
} else if strings.HasPrefix(msg, ".print") && len(args) == 3 { } else if strings.HasPrefix(msg, ".print") && len(args) == 3 {
fmt.Println("[cmd] print - " + args[0] + "'s " + args[2] + " in " + args[1] + ".") fmt.Println("[cmd] print - " + args[0] + "'s " + args[2] + " in " + args[1] + ".")
b.Say(args[0] + "'s " + args[2] + " is set to " + charmap[args[0]][args[1]][args[2]] + ".") b.Say(args[0] + "'s " + args[2] + " is set to " + charmap[args[0]][args[1]][args[2]] + ".")
} else if strings.HasPrefix(msg, ".mode") && len(args) == 1 { } else if strings.HasPrefix(msg, ".mode") && len(args) == 1 {
if stringInSlice(args[0], rulemod) { if stringInSlice(args[0], rulemod) {
fmt.Println("[cmd] mode - change to " + args[0] + " failed, already set to true") fmt.Println("[cmd] mode - change to " + args[0] + " failed, already set to true")
b.Say(args[0] + " is already set to true.") b.Say(args[0] + " is already set to true.")
@ -75,14 +80,18 @@ func (b *Bot) Command(nick string, msg string) {
fmt.Println("[cmd] mode - " + args[0]) fmt.Println("[cmd] mode - " + args[0])
b.Say(args[0] + " is now enabled.") b.Say(args[0] + " is now enabled.")
} }
} else if strings.HasPrefix(msg, ".rmmode") && len(args) == 1 { } else if strings.HasPrefix(msg, ".rmmode") && len(args) == 1 {
if removeItemInSlice(args[0], rulemod) { if removeItemInSlice(args[0], rulemod) {
fmt.Println("[cmd] rmmode - " + args[0]) fmt.Println("[cmd] rmmode - " + args[0])
b.Say(args[0] + " has been removed from the list of modes.") b.Say(args[0] + " has been removed from the list of modes.")
} else { } else {
b.Say(args[0] + " isn't in the list of modes.") b.Say(args[0] + " isn't in the list of modes.")
} }
} else if strings.HasPrefix(msg, ".dm") && len(args) == 1 { } else if strings.HasPrefix(msg, ".dm") && len(args) == 1 {
if len(dunmas) == 0 { if len(dunmas) == 0 {
dunmas = args[0] dunmas = args[0]
fmt.Println("[cmd] dm - " + dunmas) fmt.Println("[cmd] dm - " + dunmas)
@ -90,13 +99,18 @@ func (b *Bot) Command(nick string, msg string) {
} else { } else {
b.Say("dm has already been set, the current DM is " + dunmas) b.Say("dm has already been set, the current DM is " + dunmas)
} }
} else if msg == ".resetdm" && (nick == dunmas || stringInSlice(nick, admins)) { } else if msg == ".resetdm" && (nick == dunmas || stringInSlice(nick, admins)) {
dunmas = "" dunmas = ""
fmt.Println("[cmd] resetdm") fmt.Println("[cmd] resetdm")
b.Say("dm has been reset") b.Say("dm has been reset")
} else if msg == ".quit" && stringInSlice(nick, admins) { } else if msg == ".quit" && stringInSlice(nick, admins) {
fmt.Println("[cmd] shutdown from " + nick) fmt.Println("[cmd] shutdown from " + nick)
os.Exit(1) os.Exit(1)
} }
} }