From bde9a8defb73399e5174794d7bb20907f8716832 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sat, 21 Sep 2024 16:06:04 +0200 Subject: Implement configuration file Abstract settings which commonly differ between instances to a YAML based configuration file to allow for easy administration without the need for modifying the source code. Signed-off-by: Georg Pfuetzenreuter --- wat/bot.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'wat') diff --git a/wat/bot.go b/wat/bot.go index 48559d4..dae4e89 100644 --- a/wat/bot.go +++ b/wat/bot.go @@ -18,8 +18,9 @@ type WatBot struct { } type WatConfig struct { - PermittedChannels []string + AdminHosts []string IgnoredHosts []string + PermittedChannels []string } func NewWatBot(config *irc.ClientConfig, watConfig *WatConfig, serverConn *tls.Conn) *WatBot { @@ -45,7 +46,7 @@ func (w *WatBot) HandleIrcMsg(c *irc.Client, m *irc.Message) { } func (w *WatBot) Admin(m *irc.Message) bool { - admins := [2]string{"mph.monster", "cranberry.juice"} + admins := w.c.AdminHosts for _, admin := range admins { if m.Prefix.Host == admin { return true -- cgit v1.2.3 From cc322e87e62fa19dabfbddd937da477feb9f2516 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sat, 21 Sep 2024 17:49:39 +0200 Subject: Replace redundant logic in Admin() The Allowed() function already implements this loop, use it to reduce redundant code. Signed-off-by: Georg Pfuetzenreuter --- wat/bot.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'wat') diff --git a/wat/bot.go b/wat/bot.go index dae4e89..2e889b7 100644 --- a/wat/bot.go +++ b/wat/bot.go @@ -46,13 +46,7 @@ func (w *WatBot) HandleIrcMsg(c *irc.Client, m *irc.Message) { } func (w *WatBot) Admin(m *irc.Message) bool { - admins := w.c.AdminHosts - for _, admin := range admins { - if m.Prefix.Host == admin { - return true - } - } - return false + return w.Allowed(m.Prefix.Host, w.c.AdminHosts) } func (w *WatBot) Allowed(c string, r []string) bool { -- cgit v1.2.3 From 0a90b6e483bcf6d57030cc7f26f2a3b1a819b37e Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sat, 21 Sep 2024 18:40:29 +0200 Subject: 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 --- wat/bot.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'wat') 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 -- cgit v1.2.3