From 5e68b8f565d835969b93b05711fe54f838097bca Mon Sep 17 00:00:00 2001 From: Elliott Pardee Date: Fri, 2 Jan 2015 05:44:29 -0500 Subject: [PATCH] maps are weird --- bot.go | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) mode change 100644 => 100755 bot.go diff --git a/bot.go b/bot.go old mode 100644 new mode 100755 index b21d2a1..871149b --- a/bot.go +++ b/bot.go @@ -7,19 +7,18 @@ import ( "strconv" "fmt" "os" - ) var ( - server = "localhost" + server = "irc.iotek.org" port = 6667 - channel = "#bot" + channel = "#d20" nickname = "bot" - gabens = []string{"vypr"} + admins = []string{"vypr"} dunmas = "" - charmap = make(map[string]string) + charmap = make(map[string]map[string]map[string]string) monsmap = make(map[string]string) ) @@ -31,22 +30,29 @@ func stringInSlice(a string, list []string) bool { return false } -func fillCharmap(nick string, sect string, val string) { - // TODO: Command that creates a map of maps for a nick. - // vypr["stat"]["armor"] = 9001 - // vypr["stat"]["health"] = 100 - // vypr["info"]["name"] = "Peapod" - // make(map[string]map[string]string) - var isDungeonMaster = false - if nick == dunmas { isDungeonMaster = true } -} - func processMsg(nick string, msg string, conn *irc.Connection) { - if strings.HasPrefix(msg, ".set") && len(strings.Split(msg, " ")) == 4 { - var arg1 = strings.Split(msg, " ")[1] - var arg2 = strings.Split(msg, " ")[2] - var arg3 = strings.Split(msg, " ")[3] - fillCharmap(arg1, arg2, arg3) + // At some point, this will probably need refactoring. + if strings.HasPrefix(msg, ".set") && len(strings.Split(msg, " ")) == 5 { + var arg1 = strings.Split(msg, " ")[1] // nick + var arg2 = strings.Split(msg, " ")[2] // category + var arg3 = strings.Split(msg, " ")[3] // stat/info + var arg4 = strings.Split(msg, " ")[4] // value + + if nick == dunmas { + var charmap { arg1 { arg2 { arg3: arg4, }, }, } + fmt.Println("[cmd] set " + arg1 + "'s " + arg3 + "in " + arg2 + " is set to " + arg4 + ".") + } else if stringInSlice(nick, admins) { + var charmap = { arg1 = { arg2 = { arg3: arg4, }, }, } + fmt.Println("[cmd] set " + arg1 + "'s " + arg3 + " in " + arg2 + " is set to " + arg4 + ".") + conn.Privmsg(channel, nick + " used override, it's super effective!") + } + } else if msg == ".print" && len(strings.Split(msg, " ")) == 4 { + var arg1 = strings.Split(msg, " ")[1] // nick + var arg2 = strings.Split(msg, " ")[2] // category + var arg3 = strings.Split(msg, " ")[3] // stat/info + + fmt.Println("[cmd] print " + arg1 + "'s " + arg3 + "in " + arg2 + ".") + conn.Privmsg(channel, arg1 + "'s " + arg3 + " is set to " + charmap[arg1][arg2][arg3] + ".") } else if strings.HasPrefix(msg, ".dm") && len(strings.Split(msg, " ")) == 2 { if len(dunmas) == 0 && len(strings.Split(msg, " ")[1]) > 0 { dunmas = strings.Split(msg, " ")[1] @@ -55,12 +61,12 @@ func processMsg(nick string, msg string, conn *irc.Connection) { } else { conn.Privmsg(channel, "dm has already been set, the current DM is " + dunmas) } - } else if msg == ".resetdm" && (nick == dunmas || stringInSlice(nick, gabens)) { + } else if msg == ".resetdm" && (nick == dunmas || stringInSlice(nick, admins)) { dunmas = "" fmt.Println("[cmd] resetdm") conn.Privmsg(channel, "dm has been reset") - } else if msg == ".quit" && stringInSlice(nick, gabens) { - fmt.Println("[cmd] lord " + nick + " has requested a shutdown") + } else if msg == ".quit" && stringInSlice(nick, admins) { + fmt.Println("[cmd] shutdown from " + nick) os.Exit(1) } } @@ -74,7 +80,7 @@ func main() { fmt.Println(err) } - conn.AddCallback("001", func(e *irc.Event) { conn.Join("#bot") }) + conn.AddCallback("001", func(e *irc.Event) { conn.Join(channel) }) conn.AddCallback("PRIVMSG", func(e *irc.Event) { processMsg(e.Nick, e.Message(), conn)