summaryrefslogtreecommitdiffstats
path: root/wat
diff options
context:
space:
mode:
authorPratyush Desai2024-09-28 19:43:10 +0200
committerPratyush Desai2024-09-28 19:43:10 +0200
commita475bc2f428c6fb6905f3f2896b5477a6e361f32 (patch)
tree3ba1171b3795f90ecabea7d217b56643dff2b3b9 /wat
parentf4a9607770cc4f84431332ab4cdb7e292d037275 (diff)
parent0a90b6e483bcf6d57030cc7f26f2a3b1a819b37e (diff)
downloadwatbot-a475bc2f428c6fb6905f3f2896b5477a6e361f32.tar.gz
watbot-a475bc2f428c6fb6905f3f2896b5477a6e361f32.tar.bz2
watbot-a475bc2f428c6fb6905f3f2896b5477a6e361f32.zip
Merge pull request 'Implement configuration file + automatic channel joining' (#14) from config into master
Reviewed-on: https://git.com.de/LibertaCasa/watbot/pulls/14
Diffstat (limited to 'wat')
-rw-r--r--wat/bot.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/wat/bot.go b/wat/bot.go
index 48559d4..a555de4 100644
--- a/wat/bot.go
+++ b/wat/bot.go
@@ -18,8 +18,10 @@ type WatBot struct {
}
type WatConfig struct {
- PermittedChannels []string
+ AdminHosts []string
IgnoredHosts []string
+ AutoJoinChannels []string
+ PermittedChannels []string
}
func NewWatBot(config *irc.ClientConfig, watConfig *WatConfig, serverConn *tls.Conn) *WatBot {
@@ -35,23 +37,29 @@ 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))
+ }
}
}
func (w *WatBot) Admin(m *irc.Message) bool {
- admins := [2]string{"mph.monster", "cranberry.juice"}
- 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 {
@@ -73,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