~dricottone/huttese-apk

ref: 278a8e4d08fda32a3126f9d81283bf2f7a4822d7 huttese-apk/sr.ht/alertmanager-irc-relay/0001-Add-option-to-use-PRIVMSG-instead-of-NOTICE.patch -rw-r--r-- 2.1 KiB
278a8e4d — Drew DeVault Force name of new abuild key 4 years ago
                                                                                
44ba1a81 Drew DeVault
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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