now using @karlmcg's regbot codebase
This commit is contained in:
parent
9330c04ccd
commit
c83f0be538
69
bot.go
69
bot.go
@ -1,20 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"github.com/thoj/go-ircevent"
|
"github.com/thoj/go-ircevent"
|
||||||
"strings"
|
"strings"
|
||||||
"strconv"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
type Bot struct {
|
||||||
server = "irc.iotek.org"
|
Conn *irc.Connection
|
||||||
port = 6667
|
Nick string
|
||||||
channel = "#d20"
|
Server string
|
||||||
nickname = "bot"
|
Channel string
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
admins = []string{"vypr"}
|
admins = []string{"vypr"}
|
||||||
dunmas = ""
|
dunmas = ""
|
||||||
|
|
||||||
@ -40,6 +40,10 @@ var dict = map[string]string{
|
|||||||
"cls": "class",
|
"cls": "class",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bot) Say(msg string) {
|
||||||
|
b.Conn.Privmsg(b.Channel, msg)
|
||||||
|
}
|
||||||
|
|
||||||
func stringInSlice(a string, list []string) bool {
|
func stringInSlice(a string, list []string) bool {
|
||||||
// thanks stackoverflow
|
// thanks stackoverflow
|
||||||
for _, b := range list {
|
for _, b := range list {
|
||||||
@ -89,7 +93,7 @@ func fillCharmap(nick string, cat string, item string, val string) {
|
|||||||
charmap = map[string]map[string]map[string]string { nick: map[string]map[string]string{ cat: map[string]string{ item: val, }, }, }
|
charmap = map[string]map[string]map[string]string { nick: map[string]map[string]string{ cat: map[string]string{ item: val, }, }, }
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMessage(nick string, msg string, conn *irc.Connection) {
|
func (b *Bot) Command(nick string, msg string) {
|
||||||
var args = findArguments(msg)
|
var args = findArguments(msg)
|
||||||
|
|
||||||
// TODO: Check if mode is enabled and if command can be applied.
|
// TODO: Check if mode is enabled and if command can be applied.
|
||||||
@ -101,58 +105,65 @@ func handleMessage(nick string, msg string, conn *irc.Connection) {
|
|||||||
} else if stringInSlice(nick, admins) && !stringInSlice("nocharoverride", rulemod) {
|
} else if stringInSlice(nick, admins) && !stringInSlice("nocharoverride", rulemod) {
|
||||||
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] + ".")
|
||||||
conn.Privmsg(channel, 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[1] + " in " + args[3] + ".")
|
fmt.Println("[cmd] print - " + args[0] + "'s " + args[1] + " in " + args[3] + ".")
|
||||||
conn.Privmsg(channel, args[0] + "'s " + args[0] + " is set to " + charmap[args[0]][args[1]][args[2]] + ".")
|
b.Say(args[0] + "'s " + args[0] + " 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")
|
||||||
conn.Privmsg(channel, args[0] + " is already set to true.")
|
b.Say(args[0] + " is already set to true.")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("[cmd] mode - " + args[0])
|
fmt.Println("[cmd] mode - " + args[0])
|
||||||
conn.Privmsg(channel, 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])
|
||||||
conn.Privmsg(channel, args[0] + " has been removed from the list of modes.")
|
b.Say(args[0] + " has been removed from the list of modes.")
|
||||||
} else {
|
} else {
|
||||||
conn.Privmsg(channel, 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)
|
||||||
conn.Privmsg(channel, "dm is now set to " + dunmas)
|
b.Say("dm is now set to " + dunmas)
|
||||||
} else {
|
} else {
|
||||||
conn.Privmsg(channel, "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")
|
||||||
conn.Privmsg(channel, "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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func (b *Bot) Listen() {
|
||||||
conn := irc.IRC(nickname, nickname)
|
err := b.Conn.Connect(b.Server)
|
||||||
|
|
||||||
err := conn.Connect(server + ":" + strconv.Itoa(port))
|
if err != nil { panic(err) }
|
||||||
if err != nil {
|
|
||||||
fmt.Print("[err] connection failed - ")
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
conn.AddCallback("001", func(e *irc.Event) { conn.Join(channel) })
|
b.Conn.AddCallback("001", func(e *irc.Event) {
|
||||||
|
b.Conn.Join(b.Channel)
|
||||||
conn.AddCallback("PRIVMSG", func(e *irc.Event) {
|
|
||||||
handleMessage(e.Nick, e.Message(), conn)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
conn.Loop()
|
b.Conn.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
|
b.Command(e.Nick, e.Message())
|
||||||
|
})
|
||||||
|
|
||||||
|
b.Conn.Loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBot(server string, channel string, nick string) *Bot {
|
||||||
|
return &Bot{Conn: irc.IRC(nick, nick), Server: server, Channel: channel, Nick: nick}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
b := NewBot("irc.iotek.org:6667", "#d20", "bot")
|
||||||
|
b.Listen()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user