maps are weird

This commit is contained in:
Elliott Pardee 2015-01-02 05:44:29 -05:00
parent c948455307
commit 5e68b8f565

54
bot.go Normal file → Executable file
View File

@ -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)