maps are weird
This commit is contained in:
parent
c948455307
commit
5e68b8f565
54
bot.go
Normal file → Executable file
54
bot.go
Normal file → Executable file
@ -7,19 +7,18 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
server = "localhost"
|
server = "irc.iotek.org"
|
||||||
port = 6667
|
port = 6667
|
||||||
channel = "#bot"
|
channel = "#d20"
|
||||||
nickname = "bot"
|
nickname = "bot"
|
||||||
|
|
||||||
gabens = []string{"vypr"}
|
admins = []string{"vypr"}
|
||||||
dunmas = ""
|
dunmas = ""
|
||||||
|
|
||||||
charmap = make(map[string]string)
|
charmap = make(map[string]map[string]map[string]string)
|
||||||
monsmap = make(map[string]string)
|
monsmap = make(map[string]string)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,22 +30,29 @@ func stringInSlice(a string, list []string) bool {
|
|||||||
return false
|
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) {
|
func processMsg(nick string, msg string, conn *irc.Connection) {
|
||||||
if strings.HasPrefix(msg, ".set") && len(strings.Split(msg, " ")) == 4 {
|
// At some point, this will probably need refactoring.
|
||||||
var arg1 = strings.Split(msg, " ")[1]
|
if strings.HasPrefix(msg, ".set") && len(strings.Split(msg, " ")) == 5 {
|
||||||
var arg2 = strings.Split(msg, " ")[2]
|
var arg1 = strings.Split(msg, " ")[1] // nick
|
||||||
var arg3 = strings.Split(msg, " ")[3]
|
var arg2 = strings.Split(msg, " ")[2] // category
|
||||||
fillCharmap(arg1, arg2, arg3)
|
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 {
|
} else if strings.HasPrefix(msg, ".dm") && len(strings.Split(msg, " ")) == 2 {
|
||||||
if len(dunmas) == 0 && len(strings.Split(msg, " ")[1]) > 0 {
|
if len(dunmas) == 0 && len(strings.Split(msg, " ")[1]) > 0 {
|
||||||
dunmas = strings.Split(msg, " ")[1]
|
dunmas = strings.Split(msg, " ")[1]
|
||||||
@ -55,12 +61,12 @@ func processMsg(nick string, msg string, conn *irc.Connection) {
|
|||||||
} else {
|
} else {
|
||||||
conn.Privmsg(channel, "dm has already been set, the current DM is " + dunmas)
|
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 = ""
|
dunmas = ""
|
||||||
fmt.Println("[cmd] resetdm")
|
fmt.Println("[cmd] resetdm")
|
||||||
conn.Privmsg(channel, "dm has been reset")
|
conn.Privmsg(channel, "dm has been reset")
|
||||||
} else if msg == ".quit" && stringInSlice(nick, gabens) {
|
} else if msg == ".quit" && stringInSlice(nick, admins) {
|
||||||
fmt.Println("[cmd] lord " + nick + " has requested a shutdown")
|
fmt.Println("[cmd] shutdown from " + nick)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +80,7 @@ func main() {
|
|||||||
fmt.Println(err)
|
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) {
|
conn.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
processMsg(e.Nick, e.Message(), conn)
|
processMsg(e.Nick, e.Message(), conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user