summaryrefslogtreecommitdiffstats
path: root/wat/bot.go
diff options
context:
space:
mode:
authoralex2019-01-04 09:55:40 +0000
committeralex2019-01-04 09:55:40 +0000
commit3b9233307acfc32414ec982cca2cf72471ac4d50 (patch)
tree8a136d2b158043b1dc448e1567481e78e447a46a /wat/bot.go
parentd4c4e38ba8d203a35ddf9e7ef057fee2db80d0f9 (diff)
downloadwatbot-3b9233307acfc32414ec982cca2cf72471ac4d50.tar.gz
watbot-3b9233307acfc32414ec982cca2cf72471ac4d50.tar.bz2
watbot-3b9233307acfc32414ec982cca2cf72471ac4d50.zip
moved config around somewhat
Diffstat (limited to 'wat/bot.go')
-rw-r--r--wat/bot.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/wat/bot.go b/wat/bot.go
index d9ddd69..100e4df 100644
--- a/wat/bot.go
+++ b/wat/bot.go
@@ -11,20 +11,19 @@ import (
type WatBot struct {
client *irc.Client
conn *tls.Conn
+ c *WatConfig
game *WatGame
Db *WatDb
Nick string
}
-var allowedChannels = []string{
- "##wat",
- "##test",
- "##sweden",
- "##freedom",
+type WatConfig struct {
+ PermittedChannels []string
+ IgnoredHosts []string
}
-func NewWatBot(config *irc.ClientConfig, serverConn *tls.Conn) *WatBot {
- wat := WatBot{conn: serverConn, Nick: config.Nick}
+func NewWatBot(config *irc.ClientConfig, watConfig *WatConfig, serverConn *tls.Conn) *WatBot {
+ wat := WatBot{conn: serverConn, Nick: config.Nick, c: watConfig}
wat.Db = NewWatDb()
wat.game = NewWatGame(&wat, wat.Db)
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"
}
-func (w *WatBot) AllowedChannel(c string) bool {
- for _, allowed := range allowedChannels {
+func (w *WatBot) Allowed(c string, r []string) bool {
+ for _, allowed := range r {
if c == allowed {
return true
}
@@ -58,10 +57,26 @@ func (w *WatBot) AllowedChannel(c string) bool {
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) {
// 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
- 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
}