moved config around somewhat

This commit is contained in:
alex 2019-01-04 09:55:40 +00:00
parent d4c4e38ba8
commit 3b9233307a
2 changed files with 38 additions and 12 deletions

13
main.go
View File

@ -18,6 +18,17 @@ func main() {
User: "wat/tripsit", User: "wat/tripsit",
Name: "wat", Name: "wat",
} }
watConfig := wat.WatConfig{
PermittedChannels: []string{
"##wat",
//"##test",
"##sweden",
"##freedom",
},
IgnoredHosts: []string{
"tripsit/user/creatonez",
},
}
tcpConf := &tls.Config{ tcpConf := &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
} }
@ -26,6 +37,6 @@ func main() {
fmt.Println("err " + err.Error()) fmt.Println("err " + err.Error())
return return
} }
wwat := wat.NewWatBot(&config, conn) wwat := wat.NewWatBot(&config, &watConfig, conn)
wwat.Run() wwat.Run()
} }

View File

@ -11,20 +11,19 @@ import (
type WatBot struct { type WatBot struct {
client *irc.Client client *irc.Client
conn *tls.Conn conn *tls.Conn
c *WatConfig
game *WatGame game *WatGame
Db *WatDb Db *WatDb
Nick string Nick string
} }
var allowedChannels = []string{ type WatConfig struct {
"##wat", PermittedChannels []string
"##test", IgnoredHosts []string
"##sweden",
"##freedom",
} }
func NewWatBot(config *irc.ClientConfig, serverConn *tls.Conn) *WatBot { func NewWatBot(config *irc.ClientConfig, watConfig *WatConfig, serverConn *tls.Conn) *WatBot {
wat := WatBot{conn: serverConn, Nick: config.Nick} wat := WatBot{conn: serverConn, Nick: config.Nick, c: watConfig}
wat.Db = NewWatDb() wat.Db = NewWatDb()
wat.game = NewWatGame(&wat, wat.Db) wat.game = NewWatGame(&wat, wat.Db)
config.Handler = irc.HandlerFunc(wat.HandleIrcMsg) config.Handler = irc.HandlerFunc(wat.HandleIrcMsg)
@ -49,8 +48,8 @@ func (w *WatBot) Admin(m *irc.Message) bool {
return m.Prefix.Host == "tripsit/operator/hibs" return m.Prefix.Host == "tripsit/operator/hibs"
} }
func (w *WatBot) AllowedChannel(c string) bool { func (w *WatBot) Allowed(c string, r []string) bool {
for _, allowed := range allowedChannels { for _, allowed := range r {
if c == allowed { if c == allowed {
return true return true
} }
@ -58,10 +57,26 @@ func (w *WatBot) AllowedChannel(c string) bool {
return false return false
} }
func (w *WatBot) CanRespond(m *irc.Message) bool {
if w.Admin(m) {
return true
}
if w.Allowed(m.Prefix.Host, w.c.IgnoredHosts) {
return false
}
if !strings.Contains(m.Prefix.Host, "tripsit") {
return false
}
if !w.Allowed(m.Params[0], w.c.PermittedChannels) {
return false
}
return true
}
func (w *WatBot) Msg(m *irc.Message) { func (w *WatBot) Msg(m *irc.Message) {
// bail out if you're not yves, if you're not tripsit or if you're not in an allowed channel // bail out if you're not yves, if you're not tripsit or if you're not in an allowed channel
// but if you're an admin you can do whatever // but if you're an admin you can do whatever
if m.Prefix.Host == "tripsit/user/creatonez" || !strings.Contains(m.Prefix.Host, "tripsit") || (!w.AllowedChannel(m.Params[0]) && !w.Admin(m)) { if !w.CanRespond(m) {
return return
} }