From e2858e45608b14723624658b3dbbd54464deef66 Mon Sep 17 00:00:00 2001
From: Drew DeVault <sir@cmpwn.com>
Date: Mon, 6 Jan 2020 10:38:31 -0500
Subject: [PATCH] Add option to use PRIVMSG instead of NOTICE
This is desirable in some situations.
---
config.go | 2 ++
irc.go | 9 ++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/config.go b/config.go
index f0897e1..6bffa81 100644
--- a/config.go
+++ b/config.go
@@ -41,6 +41,7 @@ type Config struct {
IRCChannels []IRCChannel `yaml:"irc_channels"`
NoticeTemplate string `yaml:"notice_template"`
NoticeOnce bool `yaml:"notice_once_per_alert_group"`
+ UsePrivmsg bool `yaml:"use_privmsg"`
}
func LoadConfig(configFile string) (*Config, error) {
@@ -55,6 +56,7 @@ func LoadConfig(configFile string) (*Config, error) {
IRCUseSSL: true,
IRCChannels: []IRCChannel{IRCChannel{Name: "#airtest"}},
NoticeOnce: false,
+ UsePrivmsg: false,
}
if configFile != "" {
diff --git a/irc.go b/irc.go
index ee27006..ea395a4 100644
--- a/irc.go
+++ b/irc.go
@@ -64,6 +64,8 @@ type IRCNotifier struct {
NickservDelayWait time.Duration
BackoffCounter Delayer
+
+ usePrivmsg bool
}
func NewIRCNotifier(config *Config, alertNotices chan AlertNotice) (*IRCNotifier, error) {
@@ -96,6 +98,7 @@ func NewIRCNotifier(config *Config, alertNotices chan AlertNotice) (*IRCNotifier
JoinedChannels: make(map[string]ChannelState),
NickservDelayWait: nickservWaitSecs * time.Second,
BackoffCounter: backoffCounter,
+ usePrivmsg: config.UsePrivmsg,
}
notifier.Client.HandleFunc(irc.CONNECTED,
@@ -196,7 +199,11 @@ func (notifier *IRCNotifier) MaybeSendAlertNotice(alertNotice *AlertNotice) {
return
}
notifier.JoinChannel(&IRCChannel{Name: alertNotice.Channel})
- notifier.Client.Notice(alertNotice.Channel, alertNotice.Alert)
+ if notifier.usePrivmsg {
+ notifier.Client.Privmsg(alertNotice.Channel, alertNotice.Alert)
+ } else {
+ notifier.Client.Notice(alertNotice.Channel, alertNotice.Alert)
+ }
}
func (notifier *IRCNotifier) Run() {
--
2.24.1