2014-12-09 06:32:21 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
|
|
"github.com/thoj/go-ircevent"
|
|
|
|
"strings"
|
|
|
|
"strconv"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-01-02 05:44:29 -05:00
|
|
|
server = "irc.iotek.org"
|
2014-12-09 06:32:21 -05:00
|
|
|
port = 6667
|
2015-01-02 05:44:29 -05:00
|
|
|
channel = "#d20"
|
2014-12-09 06:32:21 -05:00
|
|
|
nickname = "bot"
|
|
|
|
|
2015-01-02 05:44:29 -05:00
|
|
|
admins = []string{"vypr"}
|
2014-12-09 06:32:21 -05:00
|
|
|
dunmas = ""
|
|
|
|
|
2015-01-02 06:27:23 -05:00
|
|
|
rulemod = []string{"nocharoverride"}
|
|
|
|
|
2015-01-02 05:44:29 -05:00
|
|
|
charmap = make(map[string]map[string]map[string]string)
|
2014-12-09 06:32:21 -05:00
|
|
|
monsmap = make(map[string]string)
|
|
|
|
)
|
|
|
|
|
|
|
|
func stringInSlice(a string, list []string) bool {
|
|
|
|
// thanks stackoverflow
|
|
|
|
for _, b := range list {
|
|
|
|
if b == a { return true }
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-01-02 06:27:23 -05:00
|
|
|
func removeItemInSlice(a string, list []string) bool {
|
|
|
|
for _, b := range list {
|
|
|
|
if b == a {
|
|
|
|
b = " "
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2014-12-09 06:32:21 -05:00
|
|
|
func processMsg(nick string, msg string, conn *irc.Connection) {
|
2015-01-02 05:44:29 -05:00
|
|
|
// At some point, this will probably need refactoring.
|
|
|
|
if strings.HasPrefix(msg, ".set") && len(strings.Split(msg, " ")) == 5 {
|
2015-01-02 06:27:23 -05:00
|
|
|
|
|
|
|
// thanks to jmbi (github.com/karlmcg) for helping me think
|
2015-01-02 05:44:29 -05:00
|
|
|
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
|
|
|
|
|
2015-01-02 06:27:23 -05:00
|
|
|
if arg1 == " " || arg2 == " " || arg3 == " " || arg4 == " " {
|
|
|
|
conn.Privmsg(channel, "invalid setting")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-01-02 05:44:29 -05:00
|
|
|
if nick == dunmas {
|
2015-01-02 06:27:23 -05:00
|
|
|
charmap = map[string]map[string]map[string]string{ arg1: map[string]map[string]string{ arg2: map[string]string{ arg3: arg4, }, }, }
|
|
|
|
fmt.Println("[cmd] set - " + arg1 + "'s " + arg3 + "in " + arg2 + " is set to " + arg4 + ".")
|
|
|
|
} else if stringInSlice(nick, admins) && !stringInSlice("nocharoverride", rulemod) {
|
|
|
|
charmap = map[string]map[string]map[string]string{ arg1: map[string]map[string]string{ arg2: map[string]string{ arg3: arg4, }, }, }
|
|
|
|
fmt.Println("[cmd] set - " + arg1 + "'s " + arg3 + " in " + arg2 + " is set to " + arg4 + ".")
|
2015-01-02 05:44:29 -05:00
|
|
|
conn.Privmsg(channel, nick + " used override, it's super effective!")
|
|
|
|
}
|
2015-01-02 06:27:23 -05:00
|
|
|
} else if strings.HasPrefix(msg, ".print") && len(strings.Split(msg, " ")) == 4 {
|
2015-01-02 05:44:29 -05:00
|
|
|
var arg1 = strings.Split(msg, " ")[1] // nick
|
|
|
|
var arg2 = strings.Split(msg, " ")[2] // category
|
|
|
|
var arg3 = strings.Split(msg, " ")[3] // stat/info
|
|
|
|
|
2015-01-02 06:27:23 -05:00
|
|
|
if arg1 == " " || arg2 == " " || arg3 == " " {
|
|
|
|
conn.Privmsg(channel, "invalid setting")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("[cmd] print - " + arg1 + "'s " + arg3 + " in " + arg2 + ".")
|
2015-01-02 05:44:29 -05:00
|
|
|
conn.Privmsg(channel, arg1 + "'s " + arg3 + " is set to " + charmap[arg1][arg2][arg3] + ".")
|
2015-01-02 06:27:23 -05:00
|
|
|
} else if strings.HasPrefix(msg, ".mode") && len(strings.Split(msg, " ")) == 2 {
|
|
|
|
if len(strings.Split(msg, " ")[1]) > 0 {
|
|
|
|
if stringInSlice(strings.Split(msg, " ")[1], rulemod) {
|
|
|
|
conn.Privmsg(channel, strings.Split(msg, " ")[1] + " is already set to true.")
|
|
|
|
} else {
|
|
|
|
fmt.Println("[cmd] mode " + strings.Split(msg, " ")[1])
|
|
|
|
conn.Privmsg(channel, "set " + strings.Split(msg, " ")[1] + " to true.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if strings.HasPrefix(msg, ".rmmode") && len(strings.Split(msg, " ")) == 2 {
|
|
|
|
if len(strings.Split(msg, " ")[1]) > 0 {
|
|
|
|
if stringInSlice(strings.Split(msg, " ")[1], rulemod) {
|
|
|
|
if removeItemInSlice(strings.Split(msg, " ")[1], rulemod) {
|
|
|
|
fmt.Println("[cmd] rmmode - " + strings.Split(msg, " ")[1])
|
|
|
|
conn.Privmsg(channel, strings.Split(msg, " ")[1] + " has been removed from the list of modes.")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
conn.Privmsg(channel, strings.Split(msg, " ")[1] + " isn't in the list of modes.")
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 06:32:21 -05:00
|
|
|
} else if strings.HasPrefix(msg, ".dm") && len(strings.Split(msg, " ")) == 2 {
|
|
|
|
if len(dunmas) == 0 && len(strings.Split(msg, " ")[1]) > 0 {
|
2014-12-09 06:33:56 -05:00
|
|
|
dunmas = strings.Split(msg, " ")[1]
|
2014-12-09 06:32:21 -05:00
|
|
|
fmt.Println("[cmd] dm - " + dunmas)
|
|
|
|
conn.Privmsg(channel, "dm is now set to " + dunmas)
|
|
|
|
} else {
|
|
|
|
conn.Privmsg(channel, "dm has already been set, the current DM is " + dunmas)
|
|
|
|
}
|
2015-01-02 05:44:29 -05:00
|
|
|
} else if msg == ".resetdm" && (nick == dunmas || stringInSlice(nick, admins)) {
|
2014-12-09 06:32:21 -05:00
|
|
|
dunmas = ""
|
|
|
|
fmt.Println("[cmd] resetdm")
|
|
|
|
conn.Privmsg(channel, "dm has been reset")
|
2015-01-02 05:44:29 -05:00
|
|
|
} else if msg == ".quit" && stringInSlice(nick, admins) {
|
|
|
|
fmt.Println("[cmd] shutdown from " + nick)
|
2014-12-09 06:32:21 -05:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
conn := irc.IRC(nickname, nickname)
|
|
|
|
|
|
|
|
err := conn.Connect(server + ":" + strconv.Itoa(port))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("[err] connection failed - ")
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
2015-01-02 05:44:29 -05:00
|
|
|
conn.AddCallback("001", func(e *irc.Event) { conn.Join(channel) })
|
2014-12-09 06:32:21 -05:00
|
|
|
|
|
|
|
conn.AddCallback("PRIVMSG", func(e *irc.Event) {
|
|
|
|
processMsg(e.Nick, e.Message(), conn)
|
|
|
|
})
|
|
|
|
|
|
|
|
conn.Loop()
|
|
|
|
}
|