blob: 8ff48e994efb4b6664cd1e81291ea9737701e668 (
plain) (
blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
;;; ~/.doom.d/irc.el
(require 'erc)
(require 'alert)
(defun irc-connect ()
(interactive)
(let ((pw (s-trim (shell-command-to-string "pass irccloud/freenode")))
(gnutls-verify-error nil))
(erc-tls :server "bnc.irccloud.com"
:port 6697
:nick "grfn"
:password (concat "bnc@"
(s-trim (shell-command-to-string "hostname"))
":"
pw))))
(defgroup erc-alert nil
"Alert me using alert.el for important ERC messages"
:group 'erc)
(defcustom erc-noise-regexp
"\\(Logging in:\\|Signing off\\|You're now away\\|Welcome back\\)"
"This regexp matches unwanted noise."
:type 'regexp
:group 'erc)
(setq tvl-enabled? t)
(defun erc-alert-important-p (info)
(let ((message (plist-get info :message))
(erc-message (-> info (plist-get :data) (plist-get :message)))
(erc-channel (-> info (plist-get :data) (plist-get :channel))))
(and erc-message
(not (or (string-match "^\\** *Users on #" message)
(string-match erc-noise-regexp
message)))
(or (and tvl-enabled?
(string-equal erc-channel "##tvl"))
(string-match "glittershark" message)))))
(comment
last-info
erc-noise-regexp
(setq tvl-enabled? nil)
)
(defun my-erc-hook (&optional match-type nick message)
"Shows a notification, when user's nick was mentioned.
If the buffer is currently not visible, makes it sticky."
(setq last-message message)
(if (or (null match-type) (not (eq match-type 'fool)))
(let (alert-log-messages)
(alert (or message (buffer-string))
:severity (if (string-match "glittershark" (or message ""))
'high 'low)
:title (or nick (buffer-name))
:data `(:message ,(or message (buffer-string))
:channel ,(or nick (buffer-name)))))))
(add-hook 'erc-text-matched-hook 'my-erc-hook)
(add-hook 'erc-insert-modify-hook 'my-erc-hook)
(defun my-erc-define-alerts (&rest ignore)
;; Unless the user has recently typed in the ERC buffer, highlight the fringe
(alert-add-rule
:status '(buried visible idle)
:severity '(moderate high urgent)
:mode 'erc-mode
:predicate
#'(lambda (info)
(and (not (eq (current-buffer) (plist-get info :buffer)))
(string-match "glittershark:" (plist-get info :message))))
:persistent
#'(lambda (info)
;; If the buffer is buried, or the user has been idle for
;; `alert-reveal-idle-time' seconds, make this alert
;; persistent. Normally, alerts become persistent after
;; `alert-persist-idle-time' seconds.
(memq (plist-get info :status) '(buried idle)))
:style 'message
:continue t)
(alert-add-rule
:status 'buried
:mode 'erc-mode
:predicate #'erc-alert-important-p
:style 'libnotify
:append t)
(alert-add-rule
:status 'buried
:mode 'erc-mode
:predicate #'erc-alert-important-p
:style 'message
:append t)
(alert-add-rule
:mode 'erc-mode
:predicate #'erc-alert-important-p
:style 'log
:append t)
(alert-add-rule :mode 'erc-mode :style 'ignore :append t))
(add-hook 'erc-connect-pre-hook 'my-erc-define-alerts)
(comment
(my-erc-define-alerts)
)
|