Mercurial > emacs
comparison lisp/erc/erc-nickserv.el @ 68451:fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Creator: Michael Olson <mwolson@gnu.org>
Install ERC.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 29 Jan 2006 13:08:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
68450:a3ba4ef5d590 | 68451:fc745b05e928 |
---|---|
1 ;;; erc-nickserv.el --- Identify to NickServ | |
2 | |
3 ;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. | |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 2, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 ;; Boston, MA 02110-1301, USA. | |
21 | |
22 ;;; Commentary: | |
23 | |
24 ;; There are two ways to go about identifying yourself automatically to | |
25 ;; NickServ with this module. The more secure way is to listen for identify | |
26 ;; requests from the user NickServ. Another way is to identify yourself to | |
27 ;; NickServ directly after a successful connection and every time you change | |
28 ;; your nickname. This method is rather insecure, though, because no checks | |
29 ;; are made to test if NickServ is the real NickServ for a given network or | |
30 ;; server. | |
31 | |
32 ;; As a default, ERC has the data for the official nickname services on the | |
33 ;; networks Austnet, BrasNET, Dalnet, freenode, GalaxyNet, and Slashnet. | |
34 ;; You can add more by using M-x customize-variable RET erc-nickserv-alist. | |
35 | |
36 ;; Usage: | |
37 ;; | |
38 ;; Put into your .emacs: | |
39 ;; | |
40 ;; (require 'erc-nickserv) | |
41 ;; (erc-services-mode 1) | |
42 ;; | |
43 ;; Add your nickname and NickServ password to `erc-nickserv-passwords'. | |
44 ;; Using the freenode network as an example: | |
45 ;; | |
46 ;; (setq erc-nickserv-passwords '((freenode (("nickname" "password"))))) | |
47 ;; | |
48 ;; The default automatic identification mode is autodetection of NickServ | |
49 ;; identify requests. Set the variable `erc-nickserv-identify-mode' if | |
50 ;; you'd like to change this behavior. You can also change the way | |
51 ;; automatic identification is handled by using: | |
52 ;; | |
53 ;; M-x erc-nickserv-identify-mode | |
54 ;; | |
55 ;; If you'd rather not identify yourself automatically but would like access | |
56 ;; to the functions contained in this file, just load this file without | |
57 ;; enabling `erc-services-mode'. | |
58 ;; | |
59 | |
60 ;;; Code: | |
61 | |
62 (require 'erc) | |
63 (require 'erc-nets) | |
64 (eval-when-compile (require 'cl)) | |
65 | |
66 ;; Customization: | |
67 | |
68 (defgroup erc-services nil | |
69 "Configuration for IRC services. | |
70 | |
71 On some networks, there exists a special type of automated irc bot, | |
72 called Services. Those usually allow you to register your nickname, | |
73 post/read memos to other registered users who are currently offline, | |
74 and do various other things. | |
75 | |
76 This group allows you to set variables to somewhat automate | |
77 communication with those Services." | |
78 :group 'erc) | |
79 | |
80 ;;;###autoload (autoload 'erc-services-mode "erc-nickserv" nil t) | |
81 (define-erc-module services nickserv | |
82 "This mode automates communication with services." | |
83 ((erc-nickserv-identify-mode erc-nickserv-identify-mode)) | |
84 ((remove-hook 'erc-server-NOTICE-functions | |
85 'erc-nickserv-identify-autodetect) | |
86 (remove-hook 'erc-after-connect | |
87 'erc-nickserv-identify-on-connect) | |
88 (remove-hook 'erc-nick-changed-functions | |
89 'erc-nickserv-identify-on-nick-change))) | |
90 | |
91 ;;;###autoload | |
92 (defun erc-nickserv-identify-mode (mode) | |
93 "Set up hooks according to which MODE the user has chosen." | |
94 (interactive | |
95 (list (intern (completing-read | |
96 "Choose Nickserv identify mode (RET to disable): " | |
97 '(("autodetect") ("nick-change")) nil t)))) | |
98 (cond ((eq mode 'autodetect) | |
99 (setq erc-nickserv-identify-mode 'autodetect) | |
100 (add-hook 'erc-server-NOTICE-functions | |
101 'erc-nickserv-identify-autodetect) | |
102 (remove-hook 'erc-nick-changed-functions | |
103 'erc-nickserv-identify-on-nick-change) | |
104 (remove-hook 'erc-after-connect | |
105 'erc-nickserv-identify-on-connect)) | |
106 ((eq mode 'nick-change) | |
107 (setq erc-nickserv-identify-mode 'nick-change) | |
108 (add-hook 'erc-after-connect | |
109 'erc-nickserv-identify-on-connect) | |
110 (add-hook 'erc-nick-changed-functions | |
111 'erc-nickserv-identify-on-nick-change) | |
112 (remove-hook 'erc-server-NOTICE-functions | |
113 'erc-nickserv-identify-autodetect)) | |
114 (t | |
115 (setq erc-nickserv-identify-mode nil) | |
116 (remove-hook 'erc-server-NOTICE-functions | |
117 'erc-nickserv-identify-autodetect) | |
118 (remove-hook 'erc-after-connect | |
119 'erc-nickserv-identify-on-connect) | |
120 (remove-hook 'erc-nick-changed-functions | |
121 'erc-nickserv-identify-on-nick-change)))) | |
122 | |
123 (defcustom erc-nickserv-identify-mode 'autodetect | |
124 "The mode which is used when identifying to Nickserv. | |
125 | |
126 Possible settings are:. | |
127 | |
128 'autodetect - Identify when the real Nickserv sends an identify request. | |
129 'nick-change - Identify when you change your nickname. | |
130 nil - Disables automatic Nickserv identification. | |
131 | |
132 You can also use M-x erc-nickserv-identify-mode to change modes." | |
133 :group 'erc-services | |
134 :type '(choice (const autodetect) | |
135 (const nick-change) | |
136 (const nil)) | |
137 :set (lambda (sym val) | |
138 (set-default sym val) | |
139 (erc-nickserv-identify-mode val))) | |
140 | |
141 (defcustom erc-prompt-for-nickserv-password t | |
142 "Ask for the password when identifying to NickServ." | |
143 :group 'erc-services | |
144 :type 'boolean) | |
145 | |
146 (defcustom erc-nickserv-passwords nil | |
147 "Passwords used when identifying to NickServ automatically. | |
148 | |
149 Example of use: | |
150 (setq erc-nickserv-passwords | |
151 '((freenode ((\"nick-one\" . \"password\") | |
152 (\"nick-two\" . \"password\"))) | |
153 (DALnet ((\"nick\" . \"password\")))))" | |
154 :group 'erc-services | |
155 :type '(repeat | |
156 (list :tag "Network" | |
157 (choice :tag "Network name" | |
158 (const freenode) | |
159 (const DALnet) | |
160 (const GalaxyNet) | |
161 (const SlashNET) | |
162 (const BRASnet) | |
163 (const iip) | |
164 (const Austnet) | |
165 (symbol :tag "Network name")) | |
166 (repeat :tag "Nickname and password" | |
167 (cons :tag "Identity" | |
168 (string :tag "Nick") | |
169 (string :tag "Password")))))) | |
170 | |
171 ;; Variables: | |
172 | |
173 (defcustom erc-nickserv-alist | |
174 '((DALnet | |
175 "NickServ!service@dal.net" | |
176 "/msg\\s-NickServ@services.dal.net\\s-IDENTIFY\\s-<password>" | |
177 "NickServ@services.dal.net" | |
178 "IDENTIFY" | |
179 nil) | |
180 (freenode | |
181 "NickServ!NickServ@services." | |
182 "/msg\\s-NickServ\\s-IDENTIFY\\s-<password>" | |
183 "NickServ" | |
184 "IDENTIFY" | |
185 nil) | |
186 (GalaxyNet | |
187 "NS!nickserv@galaxynet.org" | |
188 "Please\\s-change\\s-nicks\\s-or\\s-authenticate." | |
189 "NS@services.galaxynet.org" | |
190 "AUTH" | |
191 t) | |
192 (SlashNET | |
193 "NickServ!services@services.slashnet.org" | |
194 "/msg\\s-NickServ\\s-IDENTIFY\\s-password" | |
195 "NickServ@services.slashnet.org" | |
196 "IDENTIFY" | |
197 nil) | |
198 (iip | |
199 "Trent@anon.iip" | |
200 "type\\s-/squery\\s-Trent\\s-identify\\s-<password>" | |
201 "Trent@anon.iip" | |
202 "IDENTIFY" | |
203 nil | |
204 "SQUERY") | |
205 (BRASnet | |
206 "NickServ!services@brasnet.org" | |
207 "/NickServ\\s-IDENTIFY\\s-senha" | |
208 "NickServ" | |
209 "IDENTIFY" | |
210 nil | |
211 "") | |
212 (Austnet | |
213 "NickOP!service@austnet.org" | |
214 "/msg\\s-NickOP@austnet.org\\s-identify\\s-<password>" | |
215 "nickop@austnet.org" | |
216 "identify" | |
217 nil) | |
218 (Azzurra | |
219 "NickServ!service@azzurra.org" | |
220 "/ns\\s-IDENTIFY\\s-password" | |
221 "NickServ" | |
222 "IDENTIFY" | |
223 nil) | |
224 (OFTC | |
225 "NickServ!services@services.oftc.net" | |
226 "/msg\\s-NickServ\\s-IDENTIFY\\s-\^_password" | |
227 "NickServ" | |
228 "IDENTIFY" | |
229 nil)) | |
230 "Alist of NickServer details, sorted by network. | |
231 Every element in the list has the form | |
232 \(SYMBOL NICKSERV REGEXP NICK KEYWORD USE-CURRENT ANSWER) | |
233 | |
234 SYMBOL is a network identifier, a symbol, as used in `erc-networks-alist'. | |
235 NICKSERV is the description of the nickserv in the form nick!user@host. | |
236 REGEXP is a regular expression matching the message from nickserv. | |
237 NICK is nickserv's nickname. Use nick@server where necessary/possible. | |
238 KEYWORD is the keyword to use in the reply message to identify yourself. | |
239 USE-CURRENT indicates whether the current nickname must be used when | |
240 identifying. | |
241 ANSWER is the command to use for the answer. The default is 'privmsg. | |
242 This last element is optional." | |
243 :group 'erc-services | |
244 :type '(repeat | |
245 (list :tag "Nickserv data" | |
246 (symbol :tag "Network name") | |
247 (string :tag "Nickserv's nick!user@host") | |
248 (regexp :tag "Identify request sent by Nickserv") | |
249 (string :tag "Identify to") | |
250 (string :tag "Identify keyword") | |
251 (boolean :tag "Use current nick in identify message?") | |
252 (choice :tag "Command to use (optional)" | |
253 (string :tag "Command") | |
254 (const :tag "No special command necessary" nil))))) | |
255 | |
256 ;; Functions: | |
257 | |
258 (defun erc-nickserv-identify-autodetect (proc parsed) | |
259 "Check for a NickServ identify request everytime a notice is received. | |
260 Make sure it is the real NickServ for this network and that it has | |
261 specifically asked the user to IDENTIFY. | |
262 If `erc-prompt-for-nickserv-password' is non-nil, prompt the user for the | |
263 password for this nickname, otherwise try to send it automatically." | |
264 (unless (and (null erc-nickserv-passwords) | |
265 (null erc-prompt-for-nickserv-password)) | |
266 (let* ((network (erc-network)) | |
267 (nickserv (nth 1 (assoc network erc-nickserv-alist))) | |
268 (identify-regex (nth 2 (assoc network erc-nickserv-alist))) | |
269 (sspec (erc-response.sender parsed)) | |
270 (nick (car (erc-response.command-args parsed))) | |
271 (msg (erc-response.contents parsed))) | |
272 ;; continue only if we're sure it's the real nickserv for this network | |
273 ;; and it's asked us to identify | |
274 (when (and nickserv (equal sspec nickserv) | |
275 (string-match identify-regex msg)) | |
276 (erc-log "NickServ IDENTIFY request detected") | |
277 (erc-nickserv-call-identify-function nick) | |
278 nil)))) | |
279 | |
280 (defun erc-nickserv-identify-on-connect (server nick) | |
281 "Identify to Nickserv after the connection to the server is established." | |
282 (unless (and (null erc-nickserv-passwords) | |
283 (null erc-prompt-for-nickserv-password)) | |
284 (erc-nickserv-call-identify-function nick))) | |
285 | |
286 (defun erc-nickserv-identify-on-nick-change (nick old-nick) | |
287 "Identify to Nickserv whenever your nick changes." | |
288 (unless (and (null erc-nickserv-passwords) | |
289 (null erc-prompt-for-nickserv-password)) | |
290 (erc-nickserv-call-identify-function nick))) | |
291 | |
292 (defun erc-nickserv-call-identify-function (nickname) | |
293 "Call `erc-nickserv-identify' interactively or run it with NICKNAME's | |
294 password. | |
295 The action is determined by the value of `erc-prompt-for-nickserv-password'." | |
296 (if erc-prompt-for-nickserv-password | |
297 (call-interactively 'erc-nickserv-identify) | |
298 (when erc-nickserv-passwords | |
299 (erc-nickserv-identify | |
300 (cdr (assoc nickname | |
301 (nth 1 (assoc (erc-network) | |
302 erc-nickserv-passwords)))))))) | |
303 | |
304 ;;;###autoload | |
305 (defun erc-nickserv-identify (password) | |
306 "Send an \"identify <PASSWORD>\" message to NickServ. | |
307 When called interactively, read the password using `read-passwd'." | |
308 (interactive | |
309 (list (read-passwd | |
310 (format "NickServ password for %s on %s (RET to cancel): " | |
311 (erc-current-nick) | |
312 (or (and (erc-network) | |
313 (symbol-name (erc-network))) | |
314 "Unknown network"))))) | |
315 (when (and password (not (string= "" password))) | |
316 (let* ((erc-auto-discard-away nil) | |
317 (network (erc-network)) | |
318 (nickserv-info (assoc network erc-nickserv-alist)) | |
319 (nickserv (or (nth 3 nickserv-info) "NickServ")) | |
320 (identify-word (or (nth 4 nickserv-info) "IDENTIFY")) | |
321 (nick (if (nth 5 nickserv-info) | |
322 (concat (erc-current-nick) " ") | |
323 "")) | |
324 (msgtype (or (nth 6 nickserv-info) "PRIVMSG"))) | |
325 (erc-message msgtype | |
326 (concat nickserv " " identify-word " " nick password))))) | |
327 | |
328 (provide 'erc-nickserv) | |
329 | |
330 ;;; erc-nickserv.el ends here | |
331 ;; | |
332 ;; Local Variables: | |
333 ;; indent-tabs-mode: t | |
334 ;; tab-width: 8 | |
335 ;; End: | |
336 | |
337 ;; arch-tag: d401c8aa-d938-4255-96a9-3efb64c47e58 |