-
Notifications
You must be signed in to change notification settings - Fork 95
/
erc-alert.el
121 lines (99 loc) · 3.95 KB
/
erc-alert.el
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
112
113
114
115
116
117
118
119
120
121
;;; erc-alert --- Alert me using alert.el for important ERC messages
;; Copyright (C) 2011 John Wiegley
;; Author: John Wiegley <jwiegley@gmail.com>
;; Created: 20 Sep 2011
;; Version: 1.0
;; Keywords: erc alert irc
;; X-URL: https://github.com/jwiegley/dot-emacs
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Notify me using alert.el when people talk to me in ERC.
(require 'erc)
(require 'alert)
(defgroup erc-alert nil
"Alert me using alert.el for important ERC messages"
:group 'erc)
(defcustom erc-priority-people-regexp ".*"
"Regexp that matches BitlBee users you want active notification for."
:type 'regexp
:group 'erc-alert)
(defcustom erc-growl-noise-regexp
(concat "\\(Logging in:\\|Signing off\\|You're now away"
"\\|Welcome back\\|Setting automatically away\\)")
"This regexp matches unwanted noise."
:type 'regexp
:group 'erc-alert)
(defun erc-alert-important-p (info)
(let ((message (plist-get info :message))
(erc-message (plist-get info :data)))
(and erc-message
(not (or (string-match "^\\** *Users on #" message)
(string-match erc-growl-noise-regexp
message))))))
(defun my-erc-hook (&optional match-type nick message)
"Shows a growl notification, when user's nick was mentioned.
If the buffer is currently not visible, makes it sticky."
(if (or (null match-type) (not (eq match-type 'fool)))
(let (alert-log-messages)
(alert (or message (buffer-string)) :severity 'high
:title (concat "ERC: " (or nick (buffer-name)))
:data message))))
(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)))
(or (string-match "johnw:" (plist-get info :message))
(string-match (concat "\\`[^&]" erc-priority-people-regexp
"@BitlBee\\'")
(erc-format-target-and/or-network)))))
: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 'fringe
:continue t)
;; If the ERC buffer is not visible, tell the user through Growl
(alert-add-rule
:status 'buried
:mode 'erc-mode
:predicate #'erc-alert-important-p
:style (if (file-executable-p alert-notifier-command)
'notifier
'growl)
: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)
(provide 'erc-alert)
;;; erc-alert.el ends here