summaryrefslogtreecommitdiffstats
path: root/wat/bot.go
diff options
context:
space:
mode:
authorGeorg Pfuetzenreuter2024-09-21 18:40:29 +0200
committerGeorg Pfuetzenreuter2024-09-28 19:33:18 +0200
commit0a90b6e483bcf6d57030cc7f26f2a3b1a819b37e (patch)
tree3ba1171b3795f90ecabea7d217b56643dff2b3b9 /wat/bot.go
parentcc322e87e62fa19dabfbddd937da477feb9f2516 (diff)
downloadwatbot-0a90b6e483bcf6d57030cc7f26f2a3b1a819b37e.tar.gz
watbot-0a90b6e483bcf6d57030cc7f26f2a3b1a819b37e.tar.bz2
watbot-0a90b6e483bcf6d57030cc7f26f2a3b1a819b37e.zip
Implement automatic channel joining
Avoid the need for an administrator to join the bot to channels by implementing a configuration option allowing the passing of channels the bot should always join to by itself upon startup. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'wat/bot.go')
-rw-r--r--wat/bot.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/wat/bot.go b/wat/bot.go
index 2e889b7..a555de4 100644
--- a/wat/bot.go
+++ b/wat/bot.go
@@ -20,6 +20,7 @@ type WatBot struct {
type WatConfig struct {
AdminHosts []string
IgnoredHosts []string
+ AutoJoinChannels []string
PermittedChannels []string
}
@@ -36,12 +37,24 @@ func CleanNick(nick string) string {
return string(nick[0]) + "\u200c" + nick[1:]
}
+func PrefixChannel(channel string) string {
+ // there could theoretically be other channel prefixes ..
+ if channel[0] != '#' && channel[0] != '!' {
+ channel = "#" + channel
+ }
+ return channel
+}
+
func (w *WatBot) HandleIrcMsg(c *irc.Client, m *irc.Message) {
switch cmd := m.Command; cmd {
case "PING":
w.write("PONG", m.Params[0])
case "PRIVMSG":
w.Msg(m)
+ case "001":
+ for _, channel := range w.c.AutoJoinChannels {
+ w.write("JOIN", PrefixChannel(channel))
+ }
}
}
@@ -68,7 +81,7 @@ func (w *WatBot) CanRespond(m *irc.Message) bool {
// if !strings.Contains(m.Prefix.Host, "") {
// return false
// }
- if !w.Allowed(m.Params[0], w.c.PermittedChannels) {
+ if !w.Allowed(PrefixChannel(m.Params[0]), w.c.PermittedChannels) {
return false
}
return true