summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.example.yaml2
-rw-r--r--main.go2
-rw-r--r--wat/bot.go15
3 files changed, 18 insertions, 1 deletions
diff --git a/config.example.yaml b/config.example.yaml
index ce0a6e3..5d3fbac 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -13,6 +13,8 @@ watbot:
hosts:
- annoying.example.com
channels: # optional, no default
+ join:
+ - crantest # channels without a prefix character will be prefixed with "#"
permitted:
- '#lucy'
diff --git a/main.go b/main.go
index 2ae52d0..c242571 100644
--- a/main.go
+++ b/main.go
@@ -28,6 +28,7 @@ type watConfig struct {
Hosts []string `yaml:"hosts"`
} `yaml:"admins"`
Channels struct {
+ Join []string `yaml:"join"`
Permitted []string `yaml:"permitted"`
} `yaml:"channels"`
Ignores struct {
@@ -94,6 +95,7 @@ func main() {
Name: config.Name,
}
watConfig := wat.WatConfig{
+ AutoJoinChannels: config.Channels.Join,
PermittedChannels: config.Channels.Permitted,
IgnoredHosts: config.Ignores.Hosts,
AdminHosts: config.Admins.Hosts,
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