Mercurial > emacs
comparison lisp/erc/erc-backend.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 | 45937d0cd26d |
comparison
equal
deleted
inserted
replaced
68450:a3ba4ef5d590 | 68451:fc745b05e928 |
---|---|
1 ;;; erc-backend.el --- Backend network communication for ERC | |
2 | |
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. | |
4 | |
5 ;; Filename: erc-backend.el | |
6 ;; Author: Lawrence Mitchell <wence@gmx.li> | |
7 ;; Created: 2004-05-7 | |
8 ;; Keywords: IRC chat client internet | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
25 ;; Boston, MA 02110-1301, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This file defines backend network communication handlers for ERC. | |
30 ;; | |
31 ;; How things work: | |
32 ;; | |
33 ;; You define a new handler with `define-erc-response-handler'. This | |
34 ;; defines a function, a corresponding hook variable, and populates a | |
35 ;; global hash table `erc-server-responses' with a map from response | |
36 ;; to hook variable. See the function documentation for more | |
37 ;; information. | |
38 ;; | |
39 ;; Upon receiving a line from the server, `erc-parse-server-response' | |
40 ;; is called on it. | |
41 ;; | |
42 ;; A line generally looks like: | |
43 ;; | |
44 ;; LINE := ':' SENDER ' ' COMMAND ' ' (COMMAND-ARGS ' ')* ':' CONTENTS | |
45 ;; SENDER := Not ':' | ' ' | |
46 ;; COMMAND := Not ':' | ' ' | |
47 ;; COMMAND-ARGS := Not ':' | ' ' | |
48 ;; | |
49 ;; This gets parsed and stuffed into an `erc-response' struct. You | |
50 ;; can access the fields of the struct with: | |
51 ;; | |
52 ;; COMMAND --- `erc-response.command' | |
53 ;; COMMAND-ARGS --- `erc-response.command-args' | |
54 ;; CONTENTS --- `erc-response.contents' | |
55 ;; SENDER --- `erc-response.sender' | |
56 ;; LINE --- `erc-response.unparsed' | |
57 ;; | |
58 ;; WARNING, WARNING!! | |
59 ;; It's probably not a good idea to destructively modify the list | |
60 ;; of command-args in your handlers, since other functions down the | |
61 ;; line may well need to access the arguments too. | |
62 ;; | |
63 ;; That is, unless you're /absolutely/ sure that your handler doesn't | |
64 ;; invoke some other function that needs to use COMMAND-ARGS, don't do | |
65 ;; something like | |
66 ;; | |
67 ;; (while (erc-response.command-args parsed) | |
68 ;; (let ((a (pop (erc-response.command-args parsed)))) | |
69 ;; ...)) | |
70 ;; | |
71 ;; The parsed response is handed over to | |
72 ;; `erc-handle-parsed-server-response', which checks whether it should | |
73 ;; carry out duplicate suppression, and then runs `erc-call-hooks'. | |
74 ;; `erc-call-hooks' retrieves the relevant hook variable from | |
75 ;; `erc-server-responses' and runs it. | |
76 ;; | |
77 ;; Most handlers then destructure the parsed response in some way | |
78 ;; (depending on what the handler is, the arguments have different | |
79 ;; meanings), and generally display something, usually using | |
80 ;; `erc-display-message'. | |
81 | |
82 ;;; TODO: | |
83 | |
84 ;; o Generalise the display-line code so that we can use it to | |
85 ;; display the stuff we send, as well as the stuff we receive. | |
86 ;; Then, move all display-related code into another backend-like | |
87 ;; file, erc-display.el, say. | |
88 ;; | |
89 ;; o Clean up the handlers using new display code (has to be written | |
90 ;; first). | |
91 | |
92 ;;; History: | |
93 | |
94 ;; 2004/05/10 -- Handler bodies taken out of erc.el and ported to new | |
95 ;; interface. | |
96 | |
97 ;; 2005-08-13 -- Moved sending commands from erc.el. | |
98 | |
99 ;;; Code: | |
100 | |
101 (require 'erc-compat) | |
102 (eval-when-compile (require 'cl)) | |
103 (autoload 'erc-with-buffer "erc" nil nil 'macro) | |
104 (autoload 'erc-log "erc" nil nil 'macro) | |
105 | |
106 ;;;; Variables and options | |
107 | |
108 (defvar erc-server-responses (make-hash-table :test #'equal) | |
109 "Hashtable mapping server responses to their handler hooks.") | |
110 | |
111 (defstruct (erc-response (:conc-name erc-response.)) | |
112 (unparsed "" :type string) | |
113 (sender "" :type string) | |
114 (command "" :type string) | |
115 (command-args '() :type list) | |
116 (contents "" :type string)) | |
117 | |
118 ;;; User data | |
119 | |
120 (defvar erc-server-current-nick nil | |
121 "Nickname on the current server. | |
122 Use `erc-current-nick' to access this.") | |
123 (make-variable-buffer-local 'erc-server-current-nick) | |
124 | |
125 ;;; Server attributes | |
126 | |
127 (defvar erc-server-process nil | |
128 "The process object of the corresponding server connection.") | |
129 (make-variable-buffer-local 'erc-server-process) | |
130 | |
131 (defvar erc-session-server nil | |
132 "The server name used to connect to for this session.") | |
133 (make-variable-buffer-local 'erc-session-server) | |
134 | |
135 (defvar erc-session-port nil | |
136 "The port used to connect to.") | |
137 (make-variable-buffer-local 'erc-session-port) | |
138 | |
139 (defvar erc-server-announced-name nil | |
140 "The name the server announced to use.") | |
141 (make-variable-buffer-local 'erc-server-announced-name) | |
142 | |
143 (defvar erc-server-version nil | |
144 "The name and version of the server's ircd.") | |
145 (make-variable-buffer-local 'erc-server-version) | |
146 | |
147 (defvar erc-server-parameters nil | |
148 "Alist listing the supported server parameters. | |
149 | |
150 This is only set if the server sends 005 messages saying what is | |
151 supported on the server. | |
152 | |
153 Entries are of the form: | |
154 (PARAMETER . VALUE) | |
155 or | |
156 (PARAMETER) if no value is provided. | |
157 | |
158 Some examples of possible parameters sent by servers: | |
159 CHANMODES=b,k,l,imnpst - list of supported channel modes | |
160 CHANNELLEN=50 - maximum length of channel names | |
161 CHANTYPES=#&!+ - supported channel prefixes | |
162 CHARMAPPING=rfc1459 - character mapping used for nickname and channels | |
163 KICKLEN=160 - maximum allowed kick message length | |
164 MAXBANS=30 - maximum number of bans per channel | |
165 MAXCHANNELS=10 - maximum number of channels allowed to join | |
166 NETWORK=EFnet - the network identifier | |
167 NICKLEN=9 - maximum allowed length of nicknames | |
168 PREFIX=(ov)@+ - list of channel modes and the user prefixes if user has mode | |
169 RFC2812 - server supports RFC 2812 features | |
170 SILENCE=10 - supports the SILENCE command, maximum allowed number of entries | |
171 TOPICLEN=160 - maximum allowed topic length | |
172 WALLCHOPS - supports sending messages to all operators in a channel") | |
173 (make-variable-buffer-local 'erc-server-parameters) | |
174 | |
175 ;;; Server and connection state | |
176 | |
177 (defvar erc-server-connected nil | |
178 "Non-nil if the `current-buffer' is associated with an open IRC connection. | |
179 This variable is buffer-local.") | |
180 (make-variable-buffer-local 'erc-server-connected) | |
181 | |
182 (defvar erc-server-quitting nil | |
183 "Non-nil if the user requests a quit.") | |
184 (make-variable-buffer-local 'erc-server-quitting) | |
185 | |
186 (defvar erc-server-lines-sent nil | |
187 "Line counter.") | |
188 (make-variable-buffer-local 'erc-server-lines-sent) | |
189 | |
190 (defvar erc-server-last-peers '(nil . nil) | |
191 "Last peers used, both sender and receiver. | |
192 Those are used for /MSG destination shortcuts.") | |
193 (make-variable-buffer-local 'erc-server-last-peers) | |
194 | |
195 (defvar erc-server-last-sent-time nil | |
196 "Time the message was sent. | |
197 This is useful for flood protection.") | |
198 (make-variable-buffer-local 'erc-server-last-sent-time) | |
199 | |
200 (defvar erc-server-last-ping-time nil | |
201 "Time the last ping was sent. | |
202 This is useful for flood protection.") | |
203 (make-variable-buffer-local 'erc-server-last-ping-time) | |
204 | |
205 (defvar erc-server-lag nil | |
206 "Calculated server lag time in seconds. | |
207 This variable is only set in a server buffer.") | |
208 (make-variable-buffer-local 'erc-server-lag) | |
209 | |
210 (defvar erc-server-filter-data nil | |
211 "The data that arrived from the server | |
212 but has not been processed yet.") | |
213 (make-variable-buffer-local 'erc-server-filter-data) | |
214 | |
215 (defvar erc-server-duplicates (make-hash-table :test 'equal) | |
216 "Internal variable used to track duplicate messages.") | |
217 (make-variable-buffer-local 'erc-server-duplicates) | |
218 | |
219 ;; From Circe | |
220 (defvar erc-server-processing-p nil | |
221 "Non-nil when we're currently processing a message. | |
222 | |
223 When ERC receives a private message, it sets up a new buffer for | |
224 this query. These in turn, though, do start flyspell. This | |
225 involves starting an external process, in which case Emacs will | |
226 wait - and when it waits, it does accept other stuff from, say, | |
227 network exceptions. So, if someone sends you two messages | |
228 quickly after each other, ispell is started for the first, but | |
229 might take long enough for the second message to be processed | |
230 first.") | |
231 (make-variable-buffer-local 'erc-server-processing-p) | |
232 | |
233 (defvar erc-server-flood-last-message 0 | |
234 "When we sent the last message. | |
235 See `erc-server-flood-margin' for an explanation of the flood | |
236 protection algorithm.") | |
237 (make-variable-buffer-local 'erc-server-flood-last-message) | |
238 | |
239 (defvar erc-server-flood-queue nil | |
240 "The queue of messages waiting to be sent to the server. | |
241 See `erc-server-flood-margin' for an explanation of the flood | |
242 protection algorithm.") | |
243 (make-variable-buffer-local 'erc-server-flood-queue) | |
244 | |
245 (defvar erc-server-flood-timer nil | |
246 "The timer to resume sending.") | |
247 (make-variable-buffer-local 'erc-server-flood-timer) | |
248 | |
249 ;;; IRC protocol and misc options | |
250 | |
251 (defgroup erc-server nil | |
252 "Parameters for dealing with IRC servers." | |
253 :group 'erc) | |
254 | |
255 (defcustom erc-server-auto-reconnect t | |
256 "Non-nil means that ERC will attempt to reestablish broken connections. | |
257 | |
258 Reconnection will happen automatically for any unexpected disconnection." | |
259 :group 'erc-server | |
260 :type 'boolean) | |
261 | |
262 (defcustom erc-split-line-length 440 | |
263 "*The maximum length of a single message. | |
264 If a message exceeds this size, it is broken into multiple ones. | |
265 | |
266 IRC allows for lines up to 512 bytes. Two of them are CR LF. | |
267 And a typical message looks like this: | |
268 | |
269 :nicky!uhuser@host212223.dialin.fnordisp.net PRIVMSG #lazybastards :Hello! | |
270 | |
271 You can limit here the maximum length of the \"Hello!\" part. | |
272 Good luck." | |
273 :type 'integer | |
274 :group 'erc-server) | |
275 | |
276 (defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p) | |
277 (coding-system-p 'undecided) | |
278 (coding-system-p 'utf-8)) | |
279 '(utf-8 . undecided) | |
280 nil) | |
281 "The default coding system for incoming and outgoing text. | |
282 This is either a coding system, a cons, a function, or nil. | |
283 | |
284 If a cons, the encoding system for outgoing text is in the car | |
285 and the decoding system for incoming text is in the cdr. The most | |
286 interesting use for this is to put `undecided' in the cdr. If a | |
287 function, it is called with no arguments and should return a | |
288 coding system or a cons as described above. Note that you can use | |
289 the dynamically bound variable `target' to get the current | |
290 target. See `erc-coding-system-for-target'. | |
291 | |
292 If you need to send non-ASCII text to people not using a client that | |
293 does decoding on its own, you must tell ERC what encoding to use. | |
294 Emacs cannot guess it, since it does not know what the people on the | |
295 other end of the line are using." | |
296 :group 'erc-server | |
297 :type '(choice (const :tag "None" nil) | |
298 coding-system | |
299 (cons (coding-system :tag "encoding" :value utf-8) | |
300 (coding-system :tag "decoding" :value undecided)) | |
301 function)) | |
302 | |
303 (defcustom erc-encoding-coding-alist nil | |
304 "Alist of target regexp and coding-system pairs to use. | |
305 This overrides `erc-server-coding-system' depending on the | |
306 current target as returned by `erc-default-target'. | |
307 | |
308 Example: If you know that the channel #linux-ru uses the coding-system | |
309 `cyrillic-koi8', then add '(\"#linux-ru\" . cyrillic-koi8) to the | |
310 alist." | |
311 :group 'erc-server | |
312 :type '(repeat (cons (string :tag "Target") | |
313 coding-system))) | |
314 | |
315 (defcustom erc-server-connect-function | |
316 (if (and (fboundp 'open-network-stream-nowait) | |
317 ;; CVS Emacs claims to define open-network-stream-nowait on | |
318 ;; windows, however, it does, in fact, not work. | |
319 (not (memq system-type '(windows-nt cygwin ms-dos darwin)))) | |
320 'open-network-stream-nowait | |
321 'open-network-stream) | |
322 "Function used to initiate a connection. | |
323 It should take same arguments as `open-network-stream' does." | |
324 :group 'erc-server | |
325 :type 'function) | |
326 | |
327 (defcustom erc-server-prevent-duplicates '("301") | |
328 "*Either nil or a list of strings. | |
329 Each string is a IRC message type, like PRIVMSG or NOTICE. | |
330 All Message types in that list of subjected to duplicate prevention." | |
331 :type '(choice (const nil) (list string)) | |
332 :group 'erc-server) | |
333 | |
334 (defcustom erc-server-duplicate-timeout 60 | |
335 "*The time allowed in seconds between duplicate messages. | |
336 | |
337 If two identical messages arrive within this value of one another, the second | |
338 isn't displayed." | |
339 :type 'integer | |
340 :group 'erc-server) | |
341 | |
342 ;;; Flood-related | |
343 | |
344 ;; Most of this is courtesy of Jorgen Schaefer and Circe | |
345 ;; (http://www.nongnu.org/circe) | |
346 | |
347 (defcustom erc-server-flood-margin 10 | |
348 "*A margin on how much excess data we send. | |
349 The flood protection algorithm of ERC works like the one | |
350 detailed in RFC 2813, section 5.8 \"Flood control of clients\". | |
351 | |
352 * If `erc-server-flood-last-message' is less than the current | |
353 time, set it equal. | |
354 * While `erc-server-flood-last-message' is less than | |
355 `erc-server-flood-margin' seconds ahead of the current | |
356 time, send a message, and increase | |
357 `erc-server-flood-last-message' by | |
358 `erc-server-flood-penalty' for each message." | |
359 :type 'integer | |
360 :group 'erc-server) | |
361 | |
362 (defcustom erc-server-flood-penalty 3 | |
363 "How much we penalize a message. | |
364 See `erc-server-flood-margin' for an explanation of the flood | |
365 protection algorithm." | |
366 :type 'integer | |
367 :group 'erc-server) | |
368 | |
369 ;; Ping handling | |
370 | |
371 (defcustom erc-server-send-ping-interval 90 | |
372 "*Interval of sending pings to the server, in seconds. | |
373 If this is set to nil, pinging the server is disabled." | |
374 :group 'erc-server | |
375 :type '(choice (const nil) (integer :tag "Seconds"))) | |
376 | |
377 (defvar erc-server-ping-handler nil | |
378 "This variable holds the periodic ping timer.") | |
379 (make-variable-buffer-local 'erc-server-ping-handler) | |
380 | |
381 ;;;; Helper functions | |
382 | |
383 ;; From Circe | |
384 (defun erc-split-line (longline) | |
385 "Return a list of lines which are not too long for IRC. | |
386 The length is specified in `erc-split-line-length'. | |
387 | |
388 Currently this is called by `erc-send-input'." | |
389 (if (< (length longline) | |
390 erc-split-line-length) | |
391 (list longline) | |
392 (with-temp-buffer | |
393 (insert longline) | |
394 (let ((fill-column erc-split-line-length)) | |
395 (fill-region (point-min) (point-max) | |
396 nil t)) | |
397 (split-string (buffer-string) "\n")))) | |
398 | |
399 ;; Used by CTCP functions | |
400 (defun erc-upcase-first-word (str) | |
401 "Upcase the first word in STR." | |
402 (with-temp-buffer | |
403 (insert str) | |
404 (goto-char (point-min)) | |
405 (upcase-word 1) | |
406 (buffer-string))) | |
407 | |
408 (defun erc-server-setup-periodical-server-ping (&rest ignore) | |
409 "Set up a timer to periodically ping the current server." | |
410 (and erc-server-ping-handler (erc-cancel-timer erc-server-ping-handler)) | |
411 (when erc-server-send-ping-interval | |
412 (setq erc-server-ping-handler | |
413 (run-with-timer | |
414 4 erc-server-send-ping-interval | |
415 (lambda (buf) | |
416 (when (buffer-live-p buf) | |
417 (with-current-buffer buf | |
418 (erc-server-send | |
419 (format "PING %.0f" | |
420 (erc-current-time)))))) | |
421 (current-buffer))))) | |
422 | |
423 (defun erc-server-process-alive () | |
424 "Return non-nil when `erc-server-process' is open or running." | |
425 (and (boundp 'erc-server-process) | |
426 (processp erc-server-process) | |
427 (memq (process-status erc-server-process) '(run open)))) | |
428 | |
429 ;;;; Connecting to a server | |
430 | |
431 (defun erc-server-connect (server port) | |
432 "Perform the connection and login. | |
433 We will store server variables in the current buffer." | |
434 (let ((msg (erc-format-message 'connect ?S server ?p port))) | |
435 (message "%s" msg) | |
436 (setq erc-server-process | |
437 (funcall erc-server-connect-function | |
438 (format "erc-%s-%s" server port) | |
439 (current-buffer) server port)) | |
440 (message "%s...done" msg)) | |
441 ;; Misc server variables | |
442 (setq erc-server-quitting nil) | |
443 (setq erc-server-last-sent-time (erc-current-time)) | |
444 (setq erc-server-last-ping-time (erc-current-time)) | |
445 (setq erc-server-lines-sent 0) | |
446 ;; last peers (sender and receiver) | |
447 (setq erc-server-last-peers '(nil . nil)) | |
448 ;; process handlers | |
449 (set-process-sentinel erc-server-process 'erc-process-sentinel) | |
450 (set-process-filter erc-server-process 'erc-server-filter-function) | |
451 ;; we do our own encoding and decoding | |
452 (when (fboundp 'set-process-coding-system) | |
453 (set-process-coding-system erc-server-process 'raw-text)) | |
454 (set-marker (process-mark erc-server-process) (point)) | |
455 (erc-log "\n\n\n********************************************\n") | |
456 (message (erc-format-message 'login ?n (erc-current-nick))) | |
457 ;; wait with script loading until we receive a confirmation (first | |
458 ;; MOTD line) | |
459 (if (eq erc-server-connect-function 'open-network-stream-nowait) | |
460 ;; it's a bit unclear otherwise that it's attempting to establish a | |
461 ;; connection | |
462 (erc-display-message nil nil (current-buffer) | |
463 "Opening connection..\n") | |
464 (erc-login))) | |
465 | |
466 (defun erc-server-filter-function (process string) | |
467 "The process filter for the ERC server." | |
468 (with-current-buffer (process-buffer process) | |
469 ;; If you think this is written in a weird way - please refer to the | |
470 ;; docstring of `erc-server-processing-p' | |
471 (if erc-server-processing-p | |
472 (setq erc-server-filter-data | |
473 (if erc-server-filter-data | |
474 (concat erc-server-filter-data string) | |
475 string)) | |
476 ;; This will be true even if another process is spawned! | |
477 (let ((erc-server-processing-p t)) | |
478 (setq erc-server-filter-data (if erc-server-filter-data | |
479 (concat erc-server-filter-data | |
480 string) | |
481 string)) | |
482 (while (and erc-server-filter-data | |
483 (string-match "[\n\r]+" erc-server-filter-data)) | |
484 (let ((line (substring erc-server-filter-data | |
485 0 (match-beginning 0)))) | |
486 (setq erc-server-filter-data | |
487 (if (= (match-end 0) | |
488 (length erc-server-filter-data)) | |
489 nil | |
490 (substring erc-server-filter-data | |
491 (match-end 0)))) | |
492 (erc-parse-server-response process line))))))) | |
493 | |
494 (defun erc-process-sentinel-1 (event) | |
495 "This will be called when erc-process-sentinel has decided that we | |
496 are going to quit. Determine whether user has quit or whether erc has | |
497 been terminated. Conditionally try to reconnect and take appropriate | |
498 action." | |
499 (if erc-server-quitting | |
500 ;; normal quit | |
501 (progn | |
502 (let ((string "\n\n*** ERC finished ***\n") | |
503 (inhibit-read-only t)) | |
504 (erc-put-text-property 0 (length string) | |
505 'face 'erc-error-face string) | |
506 (insert string)) | |
507 (when erc-kill-server-buffer-on-quit | |
508 (set-buffer-modified-p nil) | |
509 (kill-buffer (current-buffer)))) | |
510 ;; unexpected disconnect | |
511 (erc-display-message nil 'error (current-buffer) | |
512 (if erc-server-auto-reconnect | |
513 'disconnected | |
514 'disconnected-noreconnect)) | |
515 (erc-update-mode-line) | |
516 (erc-set-active-buffer (current-buffer)) | |
517 (setq erc-server-last-sent-time 0) | |
518 (setq erc-server-lines-sent 0) | |
519 (if (and erc-server-auto-reconnect | |
520 (not (string-match "^deleted" event)) | |
521 ;; open-network-stream-nowait error for connection refused | |
522 (not (string-match "^failed with code 111" event))) | |
523 ;; Yuck, this should perhaps funcall | |
524 ;; erc-server-reconnect-function with no args | |
525 (erc erc-session-server erc-session-port erc-server-current-nick | |
526 erc-session-user-full-name t erc-session-password) | |
527 ;; terminate, do not reconnect | |
528 (let ((string (concat "\n\n*** ERC terminated: " event | |
529 "\n")) | |
530 (inhibit-read-only t)) | |
531 (erc-put-text-property 0 (length string) | |
532 'face 'erc-error-face string) | |
533 (insert string))))) | |
534 | |
535 (defun erc-process-sentinel (cproc event) | |
536 "Sentinel function for ERC process." | |
537 (with-current-buffer (process-buffer cproc) | |
538 (erc-log (format | |
539 "SENTINEL: proc: %S status: %S event: %S (quitting: %S)" | |
540 cproc (process-status cproc) event erc-server-quitting)) | |
541 (if (string-match "^open" event) | |
542 ;; newly opened connection (no wait) | |
543 (erc-login) | |
544 ;; assume event is 'failed | |
545 (let ((buf (process-buffer cproc))) | |
546 (erc-with-all-buffers-of-server cproc nil | |
547 (setq erc-server-connected nil)) | |
548 (when erc-server-ping-handler | |
549 (progn (erc-cancel-timer erc-server-ping-handler) | |
550 (setq erc-server-ping-handler nil))) | |
551 (run-hook-with-args 'erc-disconnected-hook | |
552 (erc-current-nick) (system-name) "") | |
553 ;; Remove the prompt | |
554 (forward-line 0) | |
555 (erc-remove-text-properties-region (point) (point-max)) | |
556 (delete-region (point) (point-max)) | |
557 ;; Decide what to do with the buffer | |
558 ;; Restart if disconnected | |
559 (erc-process-sentinel-1 event) | |
560 ;; Make sure we don't write to the buffer if it has been | |
561 ;; killed | |
562 (when (buffer-live-p buf) | |
563 (erc-update-mode-line) | |
564 (set-buffer-modified-p nil)))))) | |
565 | |
566 ;;;; Sending messages | |
567 | |
568 (defun erc-coding-system-for-target (target) | |
569 "Return the coding system or cons cell appropriate for TARGET. | |
570 This is determined via `erc-encoding-coding-alist' or | |
571 `erc-server-coding-system'." | |
572 (or (cdr (assoc target erc-encoding-coding-alist)) | |
573 (and (functionp erc-server-coding-system) | |
574 (funcall erc-server-coding-system)) | |
575 erc-server-coding-system)) | |
576 | |
577 (defun erc-decode-string-from-target (str target) | |
578 "Decode STR as appropriate for TARGET. | |
579 This is indicated by `erc-encoding-coding-alist', defaulting to the value of | |
580 `erc-server-coding-system'." | |
581 (unless (stringp str) | |
582 (setq str "")) | |
583 (let ((coding (erc-coding-system-for-target target))) | |
584 (when (consp coding) | |
585 (setq coding (cdr coding))) | |
586 (erc-decode-coding-string str coding))) | |
587 | |
588 ;; proposed name, not used by anything yet | |
589 (defun erc-send-line (text display-fn) | |
590 "Send TEXT to the current server. Wrapping and flood control apply. | |
591 Use DISPLAY-FN to show the results." | |
592 (mapc (lambda (line) | |
593 (erc-server-send line) | |
594 (funcall display-fn)) | |
595 (erc-split-line text))) | |
596 | |
597 ;; From Circe, with modifications | |
598 (defun erc-server-send (string &optional forcep target) | |
599 "Send STRING to the current server. | |
600 If FORCEP is non-nil, no flood protection is done - the string is | |
601 sent directly. This might cause the messages to arrive in a wrong | |
602 order. | |
603 | |
604 If TARGET is specified, look up encoding information for that | |
605 channel in `erc-encoding-coding-alist' or | |
606 `erc-server-coding-system'. | |
607 | |
608 See `erc-server-flood-margin' for an explanation of the flood | |
609 protection algorithm." | |
610 (erc-log (concat "erc-server-send: " string "(" (buffer-name) ")")) | |
611 (setq erc-server-last-sent-time (erc-current-time)) | |
612 (let ((buf (erc-server-buffer)) | |
613 (encoding (erc-coding-system-for-target | |
614 (or target (erc-default-target))))) | |
615 (when (consp encoding) | |
616 (setq encoding (car encoding))) | |
617 (if (and buf | |
618 (erc-server-process-alive)) | |
619 (with-current-buffer buf | |
620 (let ((str (concat string "\r\n"))) | |
621 (if forcep | |
622 (progn | |
623 (setq erc-server-flood-last-message | |
624 (+ erc-server-flood-penalty | |
625 erc-server-flood-last-message)) | |
626 (erc-log-irc-protocol str 'outbound) | |
627 (condition-case err | |
628 (progn | |
629 ;; Set encoding just before sending the string | |
630 (when (fboundp 'set-process-coding-system) | |
631 (set-process-coding-system erc-server-process | |
632 'raw-text encoding)) | |
633 (process-send-string erc-server-process str)) | |
634 ;; See `erc-server-send-queue' for full | |
635 ;; explanation of why we need this condition-case | |
636 (error nil))) | |
637 (setq erc-server-flood-queue | |
638 (append erc-server-flood-queue | |
639 (list (cons str encoding)))) | |
640 (erc-server-send-queue (current-buffer)))) | |
641 t) | |
642 (message "ERC: No process running") | |
643 nil))) | |
644 | |
645 ;; From Circe | |
646 (defun erc-server-send-queue (buffer) | |
647 "Send messages in `erc-server-flood-queue'. | |
648 See `erc-server-flood-margin' for an explanation of the flood | |
649 protection algorithm." | |
650 (with-current-buffer buffer | |
651 (let ((now (erc-current-time))) | |
652 (when erc-server-flood-timer | |
653 (erc-cancel-timer erc-server-flood-timer) | |
654 (setq erc-server-flood-timer nil)) | |
655 (when (< erc-server-flood-last-message | |
656 now) | |
657 (setq erc-server-flood-last-message now)) | |
658 (while (and erc-server-flood-queue | |
659 (< erc-server-flood-last-message | |
660 (+ now erc-server-flood-margin))) | |
661 (let ((msg (caar erc-server-flood-queue)) | |
662 (encoding (cdar erc-server-flood-queue))) | |
663 (setq erc-server-flood-queue (cdr erc-server-flood-queue) | |
664 erc-server-flood-last-message | |
665 (+ erc-server-flood-last-message | |
666 erc-server-flood-penalty)) | |
667 (erc-log-irc-protocol msg 'outbound) | |
668 (erc-log (concat "erc-server-send-queue: " | |
669 msg "(" (buffer-name buffer) ")")) | |
670 (when (erc-server-process-alive) | |
671 (condition-case err | |
672 ;; Set encoding just before sending the string | |
673 (progn | |
674 (when (fboundp 'set-process-coding-system) | |
675 (set-process-coding-system erc-server-process | |
676 'raw-text encoding)) | |
677 (process-send-string erc-server-process msg)) | |
678 ;; Sometimes the send can occur while the process is | |
679 ;; being killed, which results in a weird SIGPIPE error. | |
680 ;; Catch this and ignore it. | |
681 (error nil))))) | |
682 (when erc-server-flood-queue | |
683 (setq erc-server-flood-timer | |
684 (run-at-time 2 nil #'erc-server-send-queue buffer)))))) | |
685 | |
686 (defun erc-message (message-command line &optional force) | |
687 "Send LINE to the server as a privmsg or a notice. | |
688 MESSAGE-COMMAND should be either \"PRIVMSG\" or \"NOTICE\". | |
689 If the target is \",\", the last person you've got a message from will | |
690 be used. If the target is \".\", the last person you've sent a message | |
691 to will be used." | |
692 (cond | |
693 ((string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line) | |
694 (let ((tgt (match-string 1 line)) | |
695 (s (match-string 2 line))) | |
696 (erc-log (format "cmd: MSG(%s): [%s] %s" message-command tgt s)) | |
697 (cond | |
698 ((string= tgt ",") | |
699 (if (car erc-server-last-peers) | |
700 (setq tgt (car erc-server-last-peers)) | |
701 (setq tgt nil))) | |
702 ((string= tgt ".") | |
703 (if (cdr erc-server-last-peers) | |
704 (setq tgt (cdr erc-server-last-peers)) | |
705 (setq tgt nil)))) | |
706 (cond | |
707 (tgt | |
708 (setcdr erc-server-last-peers tgt) | |
709 (erc-server-send (format "%s %s :%s" message-command tgt s) | |
710 force)) | |
711 (t | |
712 (erc-display-message nil 'error (current-buffer) 'no-target)))) | |
713 t) | |
714 (t nil))) | |
715 | |
716 ;;; CTCP | |
717 | |
718 (defun erc-send-ctcp-message (tgt l &optional force) | |
719 "Send CTCP message L to TGT. | |
720 | |
721 If TGT is nil the message is not sent. | |
722 The command must contain neither a prefix nor a trailing `\\n'. | |
723 | |
724 See also `erc-server-send'." | |
725 (let ((l (erc-upcase-first-word l))) | |
726 (cond | |
727 (tgt | |
728 (erc-log (format "erc-send-CTCP-message: [%s] %s" tgt l)) | |
729 (erc-server-send (format "PRIVMSG %s :\C-a%s\C-a" tgt l) | |
730 force))))) | |
731 | |
732 (defun erc-send-ctcp-notice (tgt l &optional force) | |
733 "Send CTCP notice L to TGT. | |
734 | |
735 If TGT is nil the message is not sent. | |
736 The command must contain neither a prefix nor a trailing `\\n'. | |
737 | |
738 See also `erc-server-send'." | |
739 (let ((l (erc-upcase-first-word l))) | |
740 (cond | |
741 (tgt | |
742 (erc-log (format "erc-send-CTCP-notice: [%s] %s" tgt l)) | |
743 (erc-server-send (format "NOTICE %s :\C-a%s\C-a" tgt l) | |
744 force))))) | |
745 | |
746 ;;;; Handling responses | |
747 | |
748 (defun erc-parse-server-response (proc string) | |
749 "Parse and act upon a complete line from an IRC server. | |
750 PROC is the process (connection) from which STRING was received. | |
751 PROCs `process-buffer' is `current-buffer' when this function is called." | |
752 (unless (string= string "") ;; Ignore empty strings | |
753 (save-match-data | |
754 (let ((posn (if (eq (aref string 0) ?:) | |
755 (string-match " " string) | |
756 0)) | |
757 (msg (make-erc-response :unparsed string))) | |
758 | |
759 (setf (erc-response.sender msg) | |
760 (if (eq posn 0) | |
761 erc-session-server | |
762 (substring string 1 posn))) | |
763 | |
764 (setf (erc-response.command msg) | |
765 (let* ((bposn (string-match "[^ ]" string posn)) | |
766 (eposn (string-match " " string bposn))) | |
767 (setq posn (and eposn | |
768 (string-match "[^ ]" string eposn))) | |
769 (substring string bposn eposn))) | |
770 | |
771 (while (and posn | |
772 (not (eq (aref string posn) ?:))) | |
773 (push (let* ((bposn posn) | |
774 (eposn (string-match " " string bposn))) | |
775 (setq posn (and eposn | |
776 (string-match "[^ ]" string eposn))) | |
777 (substring string bposn eposn)) | |
778 (erc-response.command-args msg))) | |
779 (when posn | |
780 (let ((str (substring string (1+ posn)))) | |
781 (push str (erc-response.command-args msg)))) | |
782 | |
783 (setf (erc-response.contents msg) | |
784 (first (erc-response.command-args msg))) | |
785 | |
786 (setf (erc-response.command-args msg) | |
787 (nreverse (erc-response.command-args msg))) | |
788 | |
789 (erc-decode-parsed-server-response msg) | |
790 | |
791 (erc-handle-parsed-server-response proc msg))))) | |
792 | |
793 (defun erc-decode-parsed-server-response (parsed-response) | |
794 "Decode a pre-parsed PARSED-RESPONSE before it can be handled. | |
795 | |
796 If there is a channel name in `erc-response.command-args', decode | |
797 `erc-response' according to this channel name and | |
798 `erc-encoding-coding-alist', or use `erc-server-coding-system' | |
799 for decoding." | |
800 (let ((args (erc-response.command-args parsed-response)) | |
801 (decode-target nil) | |
802 (decoded-args ())) | |
803 (dolist (arg args nil) | |
804 (when (string-match "^[#&].*" arg) | |
805 (setq decode-target arg))) | |
806 (when (stringp decode-target) | |
807 (setq decode-target (erc-decode-string-from-target decode-target nil))) | |
808 (setf (erc-response.unparsed parsed-response) | |
809 (erc-decode-string-from-target | |
810 (erc-response.unparsed parsed-response) | |
811 decode-target)) | |
812 (setf (erc-response.sender parsed-response) | |
813 (erc-decode-string-from-target | |
814 (erc-response.sender parsed-response) | |
815 decode-target)) | |
816 (setf (erc-response.command parsed-response) | |
817 (erc-decode-string-from-target | |
818 (erc-response.command parsed-response) | |
819 decode-target)) | |
820 (dolist (arg (nreverse args) nil) | |
821 (push (erc-decode-string-from-target arg decode-target) | |
822 decoded-args)) | |
823 (setf (erc-response.command-args parsed-response) decoded-args) | |
824 (setf (erc-response.contents parsed-response) | |
825 (erc-decode-string-from-target | |
826 (erc-response.contents parsed-response) | |
827 decode-target)))) | |
828 | |
829 (defun erc-handle-parsed-server-response (process parsed-response) | |
830 "Handle a pre-parsed PARSED-RESPONSE from PROCESS. | |
831 | |
832 Hands off to helper functions via `erc-call-hooks'." | |
833 (if (member (erc-response.command parsed-response) | |
834 erc-server-prevent-duplicates) | |
835 (let ((m (erc-response.unparsed parsed-response))) | |
836 ;; duplicate supression | |
837 (if (< (or (gethash m erc-server-duplicates) 0) | |
838 (- (erc-current-time) erc-server-duplicate-timeout)) | |
839 (erc-call-hooks process parsed-response)) | |
840 (puthash m (erc-current-time) erc-server-duplicates)) | |
841 ;; Hand off to the relevant handler. | |
842 (erc-call-hooks process parsed-response))) | |
843 | |
844 (defun erc-get-hook (command) | |
845 "Return the hook variable associated with COMMAND. | |
846 | |
847 See also `erc-server-responses'." | |
848 (gethash (format (if (numberp command) "%03i" "%s") command) | |
849 erc-server-responses)) | |
850 | |
851 (defun erc-call-hooks (process message) | |
852 "Call hooks associated with MESSAGE in PROCESS. | |
853 | |
854 Finds hooks by looking in the `erc-server-responses' hashtable." | |
855 (let ((hook (or (erc-get-hook (erc-response.command message)) | |
856 'erc-default-server-functions))) | |
857 (run-hook-with-args-until-success hook process message) | |
858 (with-current-buffer (erc-server-buffer) | |
859 (run-hook-with-args 'erc-timer-hook (erc-current-time))))) | |
860 | |
861 (add-hook 'erc-default-server-functions 'erc-handle-unknown-server-response) | |
862 | |
863 (defun erc-handle-unknown-server-response (proc parsed) | |
864 "Display unknown server response's message." | |
865 (let ((line (concat (erc-response.sender parsed) | |
866 " " | |
867 (erc-response.command parsed) | |
868 " " | |
869 (mapconcat 'identity (erc-response.command-args parsed) | |
870 " ")))) | |
871 (erc-display-message parsed 'notice proc line))) | |
872 | |
873 | |
874 (put 'define-erc-response-handler 'edebug-form-spec | |
875 '(&define :name erc-response-handler | |
876 (name &rest name) | |
877 &optional sexp sexp def-body)) | |
878 | |
879 (defmacro* define-erc-response-handler ((name &rest aliases) | |
880 &optional extra-fn-doc extra-var-doc | |
881 &rest fn-body) | |
882 "Define an ERC handler hook/function pair. | |
883 NAME is the response name as sent by the server (see the IRC RFC for | |
884 meanings). | |
885 | |
886 This creates: | |
887 - a hook variable `erc-server-NAME-functions' initialised to `erc-server-NAME'. | |
888 - a function `erc-server-NAME' with body FN-BODY. | |
889 | |
890 If ALIASES is non-nil, each alias in ALIASES is `defalias'ed to | |
891 `erc-server-NAME'. | |
892 Alias hook variables are created as `erc-server-ALIAS-functions' and | |
893 initialised to the same default value as `erc-server-NAME-functions'. | |
894 | |
895 FN-BODY is the body of `erc-server-NAME' it may refer to the two | |
896 function arguments PROC and PARSED. | |
897 | |
898 If EXTRA-FN-DOC is non-nil, it is inserted at the beginning of the | |
899 defined function's docstring. | |
900 | |
901 If EXTRA-VAR-DOC is non-nil, it is inserted at the beginning of the | |
902 defined variable's docstring. | |
903 | |
904 As an example: | |
905 | |
906 (define-erc-response-handler (311 WHOIS WI) | |
907 \"Some non-generic function documentation.\" | |
908 \"Some non-generic variable documentation.\" | |
909 (do-stuff-with-whois proc parsed)) | |
910 | |
911 Would expand to: | |
912 | |
913 (prog2 | |
914 (defvar erc-server-311-functions 'erc-server-311 | |
915 \"Some non-generic variable documentation. | |
916 | |
917 Hook called upon receiving a 311 server response. | |
918 Each function is called with two arguments, the process associated | |
919 with the response and the parsed response. | |
920 See also `erc-server-311'.\") | |
921 | |
922 (defun erc-server-311 (proc parsed) | |
923 \"Some non-generic function documentation. | |
924 | |
925 Handler for a 311 server response. | |
926 PROC is the server process which returned the response. | |
927 PARSED is the actual response as an `erc-response' struct. | |
928 If you want to add responses don't modify this function, but rather | |
929 add things to `erc-server-311-functions' instead.\" | |
930 (do-stuff-with-whois proc parsed)) | |
931 | |
932 (puthash \"311\" 'erc-server-311-functions erc-server-responses) | |
933 (puthash \"WHOIS\" 'erc-server-WHOIS-functions erc-server-responses) | |
934 (puthash \"WI\" 'erc-server-WI-functions erc-server-responses) | |
935 | |
936 (defalias 'erc-server-WHOIS 'erc-server-311) | |
937 (defvar erc-server-WHOIS-functions 'erc-server-311 | |
938 \"Some non-generic variable documentation. | |
939 | |
940 Hook called upon receiving a WHOIS server response. | |
941 Each function is called with two arguments, the process associated | |
942 with the response and the parsed response. | |
943 See also `erc-server-311'.\") | |
944 | |
945 (defalias 'erc-server-WI 'erc-server-311) | |
946 (defvar erc-server-WI-functions 'erc-server-311 | |
947 \"Some non-generic variable documentation. | |
948 | |
949 Hook called upon receiving a WI server response. | |
950 Each function is called with two arguments, the process associated | |
951 with the response and the parsed response. | |
952 See also `erc-server-311'.\")) | |
953 | |
954 \(fn (NAME &rest ALIASES) &optional EXTRA-FN-DOC EXTRA-VAR-DOC &rest FN-BODY)" | |
955 (if (numberp name) (setq name (intern (format "%03i" name)))) | |
956 (setq aliases (mapcar (lambda (a) | |
957 (if (numberp a) | |
958 (format "%03i" a) | |
959 a)) | |
960 aliases)) | |
961 (let* ((hook-name (intern (format "erc-server-%s-functions" name))) | |
962 (fn-name (intern (format "erc-server-%s" name))) | |
963 (hook-doc (format "%sHook called upon receiving a %%s server response. | |
964 Each function is called with two arguments, the process associated | |
965 with the response and the parsed response. | |
966 See also `%s'." | |
967 (if extra-var-doc | |
968 (concat extra-var-doc "\n\n") | |
969 "") | |
970 fn-name)) | |
971 (fn-doc (format "%sHandler for a %s server response. | |
972 PROC is the server process which returned the response. | |
973 PARSED is the actual response as an `erc-response' struct. | |
974 If you want to add responses don't modify this function, but rather | |
975 add things to `%s' instead." | |
976 (if extra-fn-doc | |
977 (concat extra-fn-doc "\n\n") | |
978 "") | |
979 name hook-name)) | |
980 (fn-alternates | |
981 (loop for alias in aliases | |
982 collect (intern (format "erc-server-%s" alias)))) | |
983 (var-alternates | |
984 (loop for alias in aliases | |
985 collect (intern (format "erc-server-%s-functions" alias))))) | |
986 `(prog2 | |
987 ;; Normal hook variable. | |
988 (defvar ,hook-name ',fn-name ,(format hook-doc name)) | |
989 ;; Handler function | |
990 (defun ,fn-name (proc parsed) | |
991 ,fn-doc | |
992 ,@fn-body) | |
993 | |
994 ;; Make find-function and find-variable find them | |
995 (put ',fn-name 'definition-name ',name) | |
996 (put ',hook-name 'definition-name ',name) | |
997 | |
998 ;; Hashtable map of responses to hook variables | |
999 ,@(loop for response in (cons name aliases) | |
1000 for var in (cons hook-name var-alternates) | |
1001 collect `(puthash ,(format "%s" response) ',var | |
1002 erc-server-responses)) | |
1003 ;; Alternates. | |
1004 ;; Functions are defaliased, hook variables are defvared so we | |
1005 ;; can add hooks to one alias, but not another. | |
1006 ,@(loop for fn in fn-alternates | |
1007 for var in var-alternates | |
1008 for a in aliases | |
1009 nconc (list `(defalias ',fn ',fn-name) | |
1010 `(defvar ,var ',fn-name ,(format hook-doc a)) | |
1011 `(put ',var 'definition-name ',hook-name)))))) | |
1012 | |
1013 (define-erc-response-handler (ERROR) | |
1014 "Handle an ERROR command from the server." nil | |
1015 (erc-display-message | |
1016 parsed 'error nil 'ERROR | |
1017 ?s (erc-response.sender parsed) ?c (erc-response.contents parsed))) | |
1018 | |
1019 (define-erc-response-handler (INVITE) | |
1020 "Handle invitation messages." | |
1021 nil | |
1022 (let ((target (first (erc-response.command-args parsed))) | |
1023 (chnl (erc-response.contents parsed))) | |
1024 (multiple-value-bind (nick login host) | |
1025 (erc-parse-user (erc-response.sender parsed)) | |
1026 (setq erc-invitation chnl) | |
1027 (when (string= target (erc-current-nick)) | |
1028 (erc-display-message | |
1029 parsed 'notice 'active | |
1030 'INVITE ?n nick ?u login ?h host ?c chnl))))) | |
1031 | |
1032 | |
1033 (define-erc-response-handler (JOIN) | |
1034 "Handle join messages." | |
1035 nil | |
1036 (let ((chnl (erc-response.contents parsed)) | |
1037 (buffer nil)) | |
1038 (multiple-value-bind (nick login host) | |
1039 (erc-parse-user (erc-response.sender parsed)) | |
1040 ;; strip the stupid combined JOIN facility (IRC 2.9) | |
1041 (if (string-match "^\\(.*\\)?\^g.*$" chnl) | |
1042 (setq chnl (match-string 1 chnl))) | |
1043 (save-excursion | |
1044 (let* ((str (cond | |
1045 ;; If I have joined a channel | |
1046 ((erc-current-nick-p nick) | |
1047 (setq buffer (erc erc-session-server erc-session-port | |
1048 nick erc-session-user-full-name | |
1049 nil nil | |
1050 erc-default-recipients chnl | |
1051 erc-server-process)) | |
1052 (when buffer | |
1053 (set-buffer buffer) | |
1054 (erc-add-default-channel chnl) | |
1055 (erc-server-send (format "MODE %s" chnl))) | |
1056 (erc-with-buffer (chnl proc) | |
1057 (erc-channel-begin-receiving-names)) | |
1058 (erc-update-mode-line) | |
1059 (run-hooks 'erc-join-hook) | |
1060 (erc-make-notice | |
1061 (erc-format-message 'JOIN-you ?c chnl))) | |
1062 (t | |
1063 (setq buffer (erc-get-buffer chnl proc)) | |
1064 (erc-make-notice | |
1065 (erc-format-message | |
1066 'JOIN ?n nick ?u login ?h host ?c chnl)))))) | |
1067 (when buffer (set-buffer buffer)) | |
1068 (erc-update-channel-member chnl nick nick t nil nil host login) | |
1069 ;; on join, we want to stay in the new channel buffer | |
1070 ;;(set-buffer ob) | |
1071 (erc-display-message parsed nil buffer str)))))) | |
1072 | |
1073 (define-erc-response-handler (KICK) | |
1074 "Handle kick messages received from the server." nil | |
1075 (let* ((ch (first (erc-response.command-args parsed))) | |
1076 (tgt (second (erc-response.command-args parsed))) | |
1077 (reason (erc-trim-string (erc-response.contents parsed))) | |
1078 (buffer (erc-get-buffer ch proc))) | |
1079 (multiple-value-bind (nick login host) | |
1080 (erc-parse-user (erc-response.sender parsed)) | |
1081 (erc-remove-channel-member buffer tgt) | |
1082 (cond | |
1083 ((string= tgt (erc-current-nick)) | |
1084 (erc-display-message | |
1085 parsed 'notice buffer | |
1086 'KICK-you ?n nick ?u login ?h host ?c ch ?r reason) | |
1087 (run-hook-with-args 'erc-kick-hook buffer) | |
1088 (erc-with-buffer | |
1089 (buffer) | |
1090 (erc-remove-channel-users)) | |
1091 (erc-delete-default-channel ch buffer) | |
1092 (erc-update-mode-line buffer)) | |
1093 ((string= nick (erc-current-nick)) | |
1094 (erc-display-message | |
1095 parsed 'notice buffer | |
1096 'KICK-by-you ?k tgt ?c ch ?r reason)) | |
1097 (t (erc-display-message | |
1098 parsed 'notice buffer | |
1099 'KICK ?k tgt ?n nick ?u login ?h host ?c ch ?r reason)))))) | |
1100 | |
1101 (define-erc-response-handler (MODE) | |
1102 "Handle server mode changes." nil | |
1103 (let ((tgt (first (erc-response.command-args parsed))) | |
1104 (mode (mapconcat 'identity (cdr (erc-response.command-args parsed)) | |
1105 " "))) | |
1106 (multiple-value-bind (nick login host) | |
1107 (erc-parse-user (erc-response.sender parsed)) | |
1108 (erc-log (format "MODE: %s -> %s: %s" nick tgt mode)) | |
1109 ;; dirty hack | |
1110 (let ((buf (cond ((erc-channel-p tgt) | |
1111 (erc-get-buffer tgt proc)) | |
1112 ((string= tgt (erc-current-nick)) nil) | |
1113 ((erc-active-buffer) (erc-active-buffer)) | |
1114 (t (erc-get-buffer tgt))))) | |
1115 (with-current-buffer (or buf | |
1116 (current-buffer)) | |
1117 (erc-update-modes tgt mode nick host login)) | |
1118 (if (or (string= login "") (string= host "")) | |
1119 (erc-display-message parsed 'notice buf | |
1120 'MODE-nick ?n nick | |
1121 ?t tgt ?m mode) | |
1122 (erc-display-message parsed 'notice buf | |
1123 'MODE ?n nick ?u login | |
1124 ?h host ?t tgt ?m mode))) | |
1125 (erc-banlist-update proc parsed)))) | |
1126 | |
1127 (define-erc-response-handler (NICK) | |
1128 "Handle nick change messages." nil | |
1129 (let ((nn (erc-response.contents parsed)) | |
1130 bufs) | |
1131 (multiple-value-bind (nick login host) | |
1132 (erc-parse-user (erc-response.sender parsed)) | |
1133 (setq bufs (erc-buffer-list-with-nick nick proc)) | |
1134 (erc-log (format "NICK: %s -> %s" nick nn)) | |
1135 ;; if we had a query with this user, make sure future messages will be | |
1136 ;; sent to the correct nick. also add to bufs, since the user will want | |
1137 ;; to see the nick change in the query, and if it's a newly begun query, | |
1138 ;; erc-channel-users won't contain it | |
1139 (erc-buffer-filter | |
1140 (lambda () | |
1141 (when (equal (erc-default-target) nick) | |
1142 (setq erc-default-recipients | |
1143 (cons nn (cdr erc-default-recipients))) | |
1144 (rename-buffer nn) | |
1145 (erc-update-mode-line) | |
1146 (add-to-list 'bufs (current-buffer))))) | |
1147 (erc-update-user-nick nick nn host nil nil login) | |
1148 (cond | |
1149 ((string= nick (erc-current-nick)) | |
1150 (add-to-list 'bufs (erc-server-buffer)) | |
1151 (erc-set-current-nick nn) | |
1152 (erc-update-mode-line) | |
1153 (setq erc-nick-change-attempt-count 0) | |
1154 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick))) | |
1155 (erc-display-message | |
1156 parsed 'notice bufs | |
1157 'NICK-you ?n nick ?N nn) | |
1158 (run-hook-with-args 'erc-nick-changed-functions nn nick)) | |
1159 (t | |
1160 (erc-handle-user-status-change 'nick (list nick login host) (list nn)) | |
1161 (erc-display-message parsed 'notice bufs 'NICK ?n nick | |
1162 ?u login ?h host ?N nn)))))) | |
1163 | |
1164 (define-erc-response-handler (PART) | |
1165 "Handle part messages." nil | |
1166 (let* ((chnl (first (erc-response.command-args parsed))) | |
1167 (reason (erc-trim-string (erc-response.contents parsed))) | |
1168 (buffer (erc-get-buffer chnl proc))) | |
1169 (multiple-value-bind (nick login host) | |
1170 (erc-parse-user (erc-response.sender parsed)) | |
1171 (erc-remove-channel-member buffer nick) | |
1172 (erc-display-message parsed 'notice buffer | |
1173 'PART ?n nick ?u login | |
1174 ?h host ?c chnl ?r (or reason "")) | |
1175 (when (string= nick (erc-current-nick)) | |
1176 (run-hook-with-args 'erc-part-hook buffer) | |
1177 (erc-with-buffer | |
1178 (buffer) | |
1179 (erc-remove-channel-users)) | |
1180 (erc-delete-default-channel chnl buffer) | |
1181 (erc-update-mode-line buffer) | |
1182 (when erc-kill-buffer-on-part | |
1183 (kill-buffer buffer)))))) | |
1184 | |
1185 (define-erc-response-handler (PING) | |
1186 "Handle ping messages." nil | |
1187 (let ((pinger (first (erc-response.command-args parsed)))) | |
1188 (erc-log (format "PING: %s" pinger)) | |
1189 ;; ping response to the server MUST be forced, or you can lose big | |
1190 (erc-server-send (format "PONG :%s" pinger) t) | |
1191 (when erc-verbose-server-ping | |
1192 (erc-display-message | |
1193 parsed 'error proc | |
1194 'PING ?s (erc-time-diff erc-server-last-ping-time (erc-current-time)))) | |
1195 (setq erc-server-last-ping-time (erc-current-time)))) | |
1196 | |
1197 (define-erc-response-handler (PONG) | |
1198 "Handle pong messages." nil | |
1199 (let ((time (string-to-number (erc-response.contents parsed)))) | |
1200 (when (> time 0) | |
1201 (setq erc-server-lag (erc-time-diff time (erc-current-time))) | |
1202 (when erc-verbose-server-ping | |
1203 (erc-display-message | |
1204 parsed 'notice proc 'PONG | |
1205 ?h (first (erc-response.command-args parsed)) ?i erc-server-lag | |
1206 ?s (if (/= erc-server-lag 1) "s" ""))) | |
1207 (erc-update-mode-line)))) | |
1208 | |
1209 (define-erc-response-handler (PRIVMSG NOTICE) | |
1210 nil nil | |
1211 (let ((sender-spec (erc-response.sender parsed)) | |
1212 (cmd (erc-response.command parsed)) | |
1213 (tgt (car (erc-response.command-args parsed))) | |
1214 (msg (erc-response.contents parsed))) | |
1215 (if (or (erc-ignored-user-p sender-spec) | |
1216 (erc-ignored-reply-p msg tgt proc)) | |
1217 (when erc-minibuffer-ignored | |
1218 (message "Ignored %s from %s to %s" cmd sender-spec tgt)) | |
1219 (let* ((sndr (erc-parse-user sender-spec)) | |
1220 (nick (nth 0 sndr)) | |
1221 (login (nth 1 sndr)) | |
1222 (host (nth 2 sndr)) | |
1223 (msgp (string= cmd "PRIVMSG")) | |
1224 (noticep (string= cmd "NOTICE")) | |
1225 ;; S.B. downcase *both* tgt and current nick | |
1226 (privp (erc-current-nick-p tgt)) | |
1227 s buffer | |
1228 fnick) | |
1229 (setf (erc-response.contents parsed) msg) | |
1230 (setq buffer (erc-get-buffer (if privp nick tgt) proc)) | |
1231 (when buffer | |
1232 (with-current-buffer buffer | |
1233 ;; update the chat partner info. Add to the list if private | |
1234 ;; message. We will accumulate private identities indefinitely | |
1235 ;; at this point. | |
1236 (erc-update-channel-member (if privp nick tgt) nick nick | |
1237 privp nil nil host login nil nil t) | |
1238 (let ((cdata (erc-get-channel-user nick))) | |
1239 (setq fnick (funcall erc-format-nick-function | |
1240 (car cdata) (cdr cdata)))))) | |
1241 (cond | |
1242 ((erc-is-message-ctcp-p msg) | |
1243 (setq s (if msgp | |
1244 (erc-process-ctcp-query proc parsed nick login host) | |
1245 (erc-process-ctcp-reply proc parsed nick login host | |
1246 (match-string 1 msg))))) | |
1247 (t | |
1248 (setcar erc-server-last-peers nick) | |
1249 (setq s (erc-format-privmessage | |
1250 (or fnick nick) msg | |
1251 ;; If buffer is a query buffer, | |
1252 ;; format the nick as for a channel. | |
1253 (and (not (and buffer | |
1254 (erc-query-buffer-p buffer) | |
1255 erc-format-query-as-channel-p)) | |
1256 privp) | |
1257 msgp)))) | |
1258 (when s | |
1259 (if (and noticep privp) | |
1260 (progn | |
1261 (run-hook-with-args 'erc-echo-notice-always-hook | |
1262 s parsed buffer nick) | |
1263 (run-hook-with-args-until-success | |
1264 'erc-echo-notice-hook s parsed buffer nick)) | |
1265 (erc-display-message parsed nil buffer s))) | |
1266 (when (string= cmd "PRIVMSG") | |
1267 (erc-auto-query proc parsed)))))) | |
1268 | |
1269 ;; FIXME: need clean way of specifiying extra hooks in | |
1270 ;; define-erc-response-handler. | |
1271 (add-hook 'erc-server-PRIVMSG-functions 'erc-auto-query) | |
1272 | |
1273 (define-erc-response-handler (QUIT) | |
1274 nil nil | |
1275 (let ((reason (erc-response.contents parsed)) | |
1276 bufs) | |
1277 (multiple-value-bind (nick login host) | |
1278 (erc-parse-user (erc-response.sender parsed)) | |
1279 (setq bufs (erc-buffer-list-with-nick nick proc)) | |
1280 (erc-remove-user nick) | |
1281 (setq reason (erc-wash-quit-reason reason nick login host)) | |
1282 (erc-display-message parsed 'notice bufs | |
1283 'QUIT ?n nick ?u login | |
1284 ?h host ?r reason)))) | |
1285 | |
1286 (define-erc-response-handler (TOPIC) | |
1287 nil nil | |
1288 (let* ((ch (first (erc-response.command-args parsed))) | |
1289 (topic (erc-trim-string (erc-response.contents parsed))) | |
1290 (time (format-time-string "%T %m/%d/%y" (current-time)))) | |
1291 (multiple-value-bind (nick login host) | |
1292 (erc-parse-user (erc-response.sender parsed)) | |
1293 (erc-update-channel-member ch nick nick nil nil nil host login) | |
1294 (erc-update-channel-topic ch (format "%s\C-o (%s, %s)" topic nick time)) | |
1295 (erc-display-message parsed 'notice (erc-get-buffer ch proc) | |
1296 'TOPIC ?n nick ?u login ?h host | |
1297 ?c ch ?T topic)))) | |
1298 | |
1299 (define-erc-response-handler (WALLOPS) | |
1300 nil nil | |
1301 (let ((message (erc-response.contents parsed))) | |
1302 (multiple-value-bind (nick login host) | |
1303 (erc-parse-user (erc-response.sender parsed)) | |
1304 (erc-display-message | |
1305 parsed 'notice nil | |
1306 'WALLOPS ?n nick ?m message)))) | |
1307 | |
1308 (define-erc-response-handler (001) | |
1309 "Set `erc-server-current-nick' to reflect server settings and display the welcome message." | |
1310 nil | |
1311 (erc-set-current-nick (first (erc-response.command-args parsed))) | |
1312 (erc-update-mode-line) ; needed here? | |
1313 (setq erc-nick-change-attempt-count 0) | |
1314 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick))) | |
1315 (erc-display-message | |
1316 parsed 'notice 'active (erc-response.contents parsed))) | |
1317 | |
1318 (define-erc-response-handler (MOTD 002 003 371 372 374 375) | |
1319 "Display the server's message of the day." nil | |
1320 (erc-handle-login) | |
1321 (erc-display-message | |
1322 parsed 'notice (if erc-server-connected 'active proc) | |
1323 (erc-response.contents parsed))) | |
1324 | |
1325 (define-erc-response-handler (376 422) | |
1326 nil nil | |
1327 (erc-server-MOTD proc parsed) | |
1328 (erc-connection-established proc parsed)) | |
1329 | |
1330 (define-erc-response-handler (004) | |
1331 nil nil | |
1332 (multiple-value-bind (server-name server-version) | |
1333 (cdr (erc-response.command-args parsed)) | |
1334 (setq erc-server-version server-version) | |
1335 (setq erc-server-announced-name server-name) | |
1336 (erc-update-mode-line-buffer (process-buffer proc)) | |
1337 (erc-display-message | |
1338 parsed 'notice proc | |
1339 's004 ?s server-name ?v server-version | |
1340 ?U (fourth (erc-response.command-args parsed)) | |
1341 ?C (fifth (erc-response.command-args parsed))))) | |
1342 | |
1343 (define-erc-response-handler (005) | |
1344 "Set the variable `erc-server-parameters' and display the received message. | |
1345 | |
1346 According to RFC 2812, suggests alternate servers on the network. | |
1347 Many servers, however, use this code to show which parameters they have set, | |
1348 for example, the network identifier, maximum allowed topic length, whether | |
1349 certain commands are accepted and more. See documentation for | |
1350 `erc-server-parameters' for more information on the parameters sent. | |
1351 | |
1352 A server may send more than one 005 message." | |
1353 nil | |
1354 (let ((line (mapconcat 'identity | |
1355 (setf (erc-response.command-args parsed) | |
1356 (cdr (erc-response.command-args parsed))) | |
1357 " "))) | |
1358 (while (erc-response.command-args parsed) | |
1359 (let ((section (pop (erc-response.command-args parsed)))) | |
1360 ;; fill erc-server-parameters | |
1361 (when (string-match "^\\([A-Z]+\\)\=\\(.*\\)$\\|^\\([A-Z]+\\)$" | |
1362 section) | |
1363 (add-to-list 'erc-server-parameters | |
1364 `(,(or (match-string 1 section) | |
1365 (match-string 3 section)) | |
1366 . | |
1367 ,(match-string 2 section)))))) | |
1368 (erc-display-message parsed 'notice proc line))) | |
1369 | |
1370 (define-erc-response-handler (221) | |
1371 nil nil | |
1372 (let* ((nick (first (erc-response.command-args parsed))) | |
1373 (modes (mapconcat 'identity | |
1374 (cdr (erc-response.command-args parsed)) " "))) | |
1375 (erc-set-modes nick modes) | |
1376 (erc-display-message parsed 'notice 'active 's221 ?n nick ?m modes))) | |
1377 | |
1378 (define-erc-response-handler (252) | |
1379 "Display the number of IRC operators online." nil | |
1380 (erc-display-message parsed 'notice 'active 's252 | |
1381 ?i (second (erc-response.command-args parsed)))) | |
1382 | |
1383 (define-erc-response-handler (253) | |
1384 "Display the number of unknown connections." nil | |
1385 (erc-display-message parsed 'notice 'active 's253 | |
1386 ?i (second (erc-response.command-args parsed)))) | |
1387 | |
1388 (define-erc-response-handler (254) | |
1389 "Display the number of channels formed." nil | |
1390 (erc-display-message parsed 'notice 'active 's254 | |
1391 ?i (second (erc-response.command-args parsed)))) | |
1392 | |
1393 (define-erc-response-handler (250 251 255 256 257 258 259 265 266 377 378) | |
1394 "Generic display of server messages as notices. | |
1395 | |
1396 See `erc-display-server-message'." nil | |
1397 (erc-display-server-message proc parsed)) | |
1398 | |
1399 (define-erc-response-handler (301) | |
1400 "AWAY notice." nil | |
1401 (erc-display-message parsed 'notice 'active 's301 | |
1402 ?n (second (erc-response.command-args parsed)) | |
1403 ?r (erc-response.contents parsed))) | |
1404 | |
1405 (define-erc-response-handler (303) | |
1406 "ISON reply" nil | |
1407 (erc-display-message parsed 'notice 'active 's303 | |
1408 ?n (second (erc-response.command-args parsed)))) | |
1409 | |
1410 (define-erc-response-handler (305) | |
1411 "Return from AWAYness." nil | |
1412 (erc-process-away proc nil) | |
1413 (erc-display-message parsed 'notice 'active | |
1414 's305 ?m (erc-response.contents parsed))) | |
1415 | |
1416 (define-erc-response-handler (306) | |
1417 "Set AWAYness." nil | |
1418 (erc-process-away proc t) | |
1419 (erc-display-message parsed 'notice 'active | |
1420 's306 ?m (erc-response.contents parsed))) | |
1421 | |
1422 (define-erc-response-handler (311 314) | |
1423 "WHOIS/WHOWAS notices." nil | |
1424 (let ((fname (erc-response.contents parsed)) | |
1425 (catalog-entry (intern (format "s%s" (erc-response.command parsed))))) | |
1426 (multiple-value-bind (nick user host) | |
1427 (cdr (erc-response.command-args parsed)) | |
1428 (erc-update-user-nick nick nick host nil fname user) | |
1429 (erc-display-message | |
1430 parsed 'notice 'active catalog-entry | |
1431 ?n nick ?f fname ?u user ?h host)))) | |
1432 | |
1433 (define-erc-response-handler (312) | |
1434 nil nil | |
1435 (multiple-value-bind (nick server-host) | |
1436 (cdr (erc-response.command-args parsed)) | |
1437 (erc-display-message | |
1438 parsed 'notice 'active 's312 | |
1439 ?n nick ?s server-host ?c (erc-response.contents parsed)))) | |
1440 | |
1441 (define-erc-response-handler (313) | |
1442 "IRC Operator response in WHOIS." nil | |
1443 (erc-display-message | |
1444 parsed 'notice 'active 's313 | |
1445 ?n (second (erc-response.command-args parsed)))) | |
1446 | |
1447 (define-erc-response-handler (315 318 323 369) | |
1448 ;; 315 - End of WHO | |
1449 ;; 318 - End of WHOIS list | |
1450 ;; 323 - End of channel LIST | |
1451 ;; 369 - End of WHOWAS | |
1452 nil nil | |
1453 (ignore proc parsed)) | |
1454 | |
1455 (define-erc-response-handler (317) | |
1456 "IDLE notice." nil | |
1457 (multiple-value-bind (nick seconds-idle on-since time) | |
1458 (cdr (erc-response.command-args parsed)) | |
1459 (setq time (when on-since | |
1460 (format-time-string "%T %Y/%m/%d" | |
1461 (erc-string-to-emacs-time on-since)))) | |
1462 (erc-update-user-nick nick nick nil nil nil | |
1463 (and time (format "on since %s" time))) | |
1464 (if time | |
1465 (erc-display-message | |
1466 parsed 'notice 'active 's317-on-since | |
1467 ?n nick ?i (erc-sec-to-time (string-to-number seconds-idle)) ?t time) | |
1468 (erc-display-message | |
1469 parsed 'notice 'active 's317 | |
1470 ?n nick ?i (erc-sec-to-time (string-to-number seconds-idle)))))) | |
1471 | |
1472 (define-erc-response-handler (319) | |
1473 nil nil | |
1474 (erc-display-message | |
1475 parsed 'notice 'active 's319 | |
1476 ?n (second (erc-response.command-args parsed)) | |
1477 ?c (erc-response.contents parsed))) | |
1478 | |
1479 (define-erc-response-handler (320) | |
1480 "Identified user in WHOIS." nil | |
1481 (erc-display-message | |
1482 parsed 'notice 'active 's320 | |
1483 ?n (second (erc-response.command-args parsed)))) | |
1484 | |
1485 (define-erc-response-handler (321) | |
1486 "LIST header." nil | |
1487 (setq erc-channel-list nil) | |
1488 (erc-display-message parsed 'notice 'active 's321)) | |
1489 | |
1490 (define-erc-response-handler (322) | |
1491 "LIST notice." nil | |
1492 (let ((topic (erc-response.contents parsed))) | |
1493 (multiple-value-bind (channel num-users) | |
1494 (cdr (erc-response.command-args parsed)) | |
1495 (add-to-list 'erc-channel-list (list channel)) | |
1496 (erc-update-channel-topic channel topic) | |
1497 (erc-display-message | |
1498 parsed 'notice 'active 's322 | |
1499 ?c channel ?u num-users ?t (or topic ""))))) | |
1500 | |
1501 (define-erc-response-handler (324) | |
1502 "Channel or nick modes." nil | |
1503 (let ((channel (second (erc-response.command-args parsed))) | |
1504 (modes (mapconcat 'identity (cddr (erc-response.command-args parsed)) | |
1505 " "))) | |
1506 (erc-set-modes channel modes) | |
1507 (erc-display-message | |
1508 parsed 'notice (erc-get-buffer channel proc) | |
1509 's324 ?c channel ?m modes))) | |
1510 | |
1511 (define-erc-response-handler (329) | |
1512 "Channel creation date." nil | |
1513 (let ((channel (second (erc-response.command-args parsed))) | |
1514 (time (erc-string-to-emacs-time | |
1515 (third (erc-response.command-args parsed))))) | |
1516 (erc-display-message | |
1517 parsed 'notice (erc-get-buffer channel proc) | |
1518 's329 ?c channel ?t (format-time-string "%A %Y/%m/%d %X" time)))) | |
1519 | |
1520 (define-erc-response-handler (330) | |
1521 nil nil | |
1522 ;; FIXME: I don't know what the magic numbers mean. Mummy, make | |
1523 ;; the magic numbers go away. | |
1524 ;; No seriously, I have no clue about the format of this command, | |
1525 ;; and don't sit on Quakenet, so can't test. Originally we had: | |
1526 ;; nick == (aref parsed 3) | |
1527 ;; authaccount == (aref parsed 4) | |
1528 ;; authmsg == (aref parsed 5) | |
1529 ;; The guesses below are, well, just that. -- Lawrence 2004/05/10 | |
1530 (let ((nick (second (erc-response.command-args parsed))) | |
1531 (authaccount (third (erc-response.command-args parsed))) | |
1532 (authmsg (erc-response.contents parsed))) | |
1533 (erc-display-message parsed 'notice 'active 's330 | |
1534 ?n nick ?a authmsg ?i authaccount))) | |
1535 | |
1536 (define-erc-response-handler (331) | |
1537 "Channel topic." nil | |
1538 (let ((channel (second (erc-response.command-args parsed))) | |
1539 (topic (erc-response.contents parsed))) | |
1540 ;; FIXME: why don't we do anything with the topic? -- Lawrence 2004/05/10 | |
1541 (erc-display-message parsed 'notice (erc-get-buffer channel proc) | |
1542 's331 ?c channel))) | |
1543 | |
1544 (define-erc-response-handler (332) | |
1545 "TOPIC notice." nil | |
1546 (let ((channel (second (erc-response.command-args parsed))) | |
1547 (topic (erc-response.contents parsed))) | |
1548 (erc-update-channel-topic channel topic) | |
1549 (erc-display-message parsed 'notice (erc-get-buffer channel proc) | |
1550 's332 ?c channel ?T topic))) | |
1551 | |
1552 (define-erc-response-handler (333) | |
1553 ;; Who set the topic, and when | |
1554 nil nil | |
1555 (multiple-value-bind (channel nick time) | |
1556 (cdr (erc-response.command-args parsed)) | |
1557 (setq time (format-time-string "%T %Y/%m/%d" | |
1558 (erc-string-to-emacs-time time))) | |
1559 (erc-update-channel-topic channel | |
1560 (format "\C-o (%s, %s)" nick time) | |
1561 'append) | |
1562 (erc-display-message parsed 'notice (erc-get-buffer channel proc) | |
1563 's333 ?c channel ?n nick ?t time))) | |
1564 | |
1565 (define-erc-response-handler (341) | |
1566 "Let user know when an INVITE attempt has been sent successfully." | |
1567 nil | |
1568 (multiple-value-bind (nick channel) | |
1569 (cdr (erc-response.command-args parsed)) | |
1570 (erc-display-message parsed 'notice (erc-get-buffer channel proc) | |
1571 's341 ?n nick ?c channel))) | |
1572 | |
1573 (define-erc-response-handler (352) | |
1574 "WHO notice." nil | |
1575 (multiple-value-bind (channel user host server nick away-flag) | |
1576 (cdr (erc-response.command-args parsed)) | |
1577 (let ((full-name (erc-response.contents parsed)) | |
1578 hopcount) | |
1579 (when (string-match "\\(^[0-9]+ \\)\\(.*\\)$" full-name) | |
1580 (setq hopcount (match-string 1 full-name)) | |
1581 (setq full-name (match-string 2 full-name))) | |
1582 (erc-update-channel-member channel nick nick nil nil nil host | |
1583 user full-name) | |
1584 (erc-display-message parsed 'notice 'active 's352 | |
1585 ?c channel ?n nick ?a away-flag | |
1586 ?u user ?h host ?f full-name)))) | |
1587 | |
1588 (define-erc-response-handler (353) | |
1589 "NAMES notice." nil | |
1590 (let ((channel (third (erc-response.command-args parsed))) | |
1591 (users (erc-response.contents parsed))) | |
1592 (erc-with-buffer (channel proc) | |
1593 (erc-channel-receive-names users)) | |
1594 (erc-display-message parsed 'notice (or (erc-get-buffer channel proc) | |
1595 'active) | |
1596 's353 ?c channel ?u users))) | |
1597 | |
1598 (define-erc-response-handler (366) | |
1599 "End of NAMES." nil | |
1600 (erc-with-buffer ((second (erc-response.command-args parsed)) proc) | |
1601 (erc-channel-end-receiving-names))) | |
1602 | |
1603 (define-erc-response-handler (367) | |
1604 "Channel ban list entries" nil | |
1605 (multiple-value-bind (channel banmask setter time) | |
1606 (cdr (erc-response.command-args parsed)) | |
1607 (erc-display-message parsed 'notice 'active 's367 | |
1608 ?c channel | |
1609 ?b banmask | |
1610 ?s setter | |
1611 ?t time))) | |
1612 | |
1613 (define-erc-response-handler (368) | |
1614 "End of channel ban list" nil | |
1615 (let ((channel (second (erc-response.command-args parsed)))) | |
1616 (erc-display-message parsed 'notice 'active 's368 | |
1617 ?c channel))) | |
1618 | |
1619 (define-erc-response-handler (379) | |
1620 "Forwarding to another channel." nil | |
1621 ;; FIXME: Yet more magic numbers in original code, I'm guessing this | |
1622 ;; command takes two arguments, and doesn't have any "contents". -- | |
1623 ;; Lawrence 2004/05/10 | |
1624 (multiple-value-bind (from to) | |
1625 (cdr (erc-response.command-args parsed)) | |
1626 (erc-display-message parsed 'notice 'active | |
1627 's379 ?c from ?f to))) | |
1628 | |
1629 (define-erc-response-handler (391) | |
1630 "Server's time string" nil | |
1631 (erc-display-message | |
1632 parsed 'notice 'active | |
1633 's391 ?s (second (erc-response.command-args parsed)) | |
1634 ?t (third (erc-response.command-args parsed)))) | |
1635 | |
1636 (define-erc-response-handler (401) | |
1637 "No such nick/channel." nil | |
1638 (let ((nick/channel (second (erc-response.command-args parsed)))) | |
1639 (when erc-whowas-on-nosuchnick | |
1640 (erc-log (format "cmd: WHOWAS: %s" nick/channel)) | |
1641 (erc-server-send (format "WHOWAS %s 1" nick/channel))) | |
1642 (erc-display-message parsed '(notice error) 'active | |
1643 's401 ?n nick/channel))) | |
1644 | |
1645 (define-erc-response-handler (403) | |
1646 "No such channel." nil | |
1647 (erc-display-message parsed '(notice error) 'active | |
1648 's403 ?c (second (erc-response.command-args parsed)))) | |
1649 | |
1650 (define-erc-response-handler (404) | |
1651 "Cannot send to channel." nil | |
1652 (erc-display-message parsed '(notice error) 'active | |
1653 's404 ?c (second (erc-response.command-args parsed)))) | |
1654 | |
1655 | |
1656 (define-erc-response-handler (405) | |
1657 ;; Can't join that many channels. | |
1658 nil nil | |
1659 (erc-display-message parsed '(notice error) 'active | |
1660 's405 ?c (second (erc-response.command-args parsed)))) | |
1661 | |
1662 (define-erc-response-handler (406) | |
1663 ;; No such nick | |
1664 nil nil | |
1665 (erc-display-message parsed '(notice error) 'active | |
1666 's406 ?n (second (erc-response.command-args parsed)))) | |
1667 | |
1668 (define-erc-response-handler (412) | |
1669 ;; No text to send | |
1670 nil nil | |
1671 (erc-display-message parsed '(notice error) 'active 's412)) | |
1672 | |
1673 (define-erc-response-handler (421) | |
1674 ;; Unknown command | |
1675 nil nil | |
1676 (erc-display-message parsed '(notice error) 'active 's421 | |
1677 ?c (second (erc-response.command-args parsed)))) | |
1678 | |
1679 (define-erc-response-handler (432) | |
1680 ;; Bad nick. | |
1681 nil nil | |
1682 (erc-display-message parsed '(notice error) 'active 's432 | |
1683 ?n (second (erc-response.command-args parsed)))) | |
1684 | |
1685 (define-erc-response-handler (433) | |
1686 ;; Login-time "nick in use" | |
1687 nil nil | |
1688 (erc-nickname-in-use (second (erc-response.command-args parsed)) | |
1689 "already in use")) | |
1690 | |
1691 (define-erc-response-handler (437) | |
1692 ;; Nick temporarily unavailable (IRCnet) | |
1693 nil nil | |
1694 (let ((nick/channel (second (erc-response.command-args parsed)))) | |
1695 (unless (erc-channel-p nick/channel) | |
1696 (erc-nickname-in-use nick/channel "temporarily unavailable")))) | |
1697 | |
1698 (define-erc-response-handler (442) | |
1699 ;; Not on channel | |
1700 nil nil | |
1701 (erc-display-message parsed '(notice error) 'active 's442 | |
1702 ?c (second (erc-response.command-args parsed)))) | |
1703 | |
1704 (define-erc-response-handler (461) | |
1705 ;; Not enough params for command. | |
1706 nil nil | |
1707 (erc-display-message parsed '(notice error) 'active 's461 | |
1708 ?c (second (erc-response.command-args parsed)) | |
1709 ?m (erc-response.contents parsed))) | |
1710 | |
1711 (define-erc-response-handler (474) | |
1712 "Banned from channel errors" nil | |
1713 (erc-display-message parsed '(notice error) nil | |
1714 (intern (format "s%s" | |
1715 (erc-response.command parsed))) | |
1716 ?c (second (erc-response.command-args parsed)))) | |
1717 | |
1718 (define-erc-response-handler (475) | |
1719 "Channel key needed." nil | |
1720 (erc-display-message parsed '(notice error) nil 's475 | |
1721 ?c (second (erc-response.command-args parsed))) | |
1722 (when erc-prompt-for-channel-key | |
1723 (let ((channel (second (erc-response.command-args parsed))) | |
1724 (key (read-from-minibuffer | |
1725 (format "Channel %s is mode +k. Enter key (RET to cancel): " | |
1726 (second (erc-response.command-args parsed)))))) | |
1727 (when (and key (> (length key) 0)) | |
1728 (erc-cmd-JOIN channel key))))) | |
1729 | |
1730 (define-erc-response-handler (477) | |
1731 nil nil | |
1732 (let ((channel (second (erc-response.command-args parsed))) | |
1733 (message (erc-response.contents parsed))) | |
1734 (erc-display-message parsed 'notice (erc-get-buffer channel proc) | |
1735 (format "%s: %s" channel message)))) | |
1736 | |
1737 (define-erc-response-handler (482) | |
1738 nil nil | |
1739 (let ((channel (second (erc-response.command-args parsed))) | |
1740 (message (erc-response.contents parsed))) | |
1741 (erc-display-message parsed '(error notice) 'active 's482 | |
1742 ?c channel ?m message))) | |
1743 | |
1744 (define-erc-response-handler (431 445 446 451 462 463 464 465 481 483 484 485 | |
1745 491 501 502) | |
1746 ;; 431 - No nickname given | |
1747 ;; 445 - SUMMON has been disabled | |
1748 ;; 446 - USERS has been disabled | |
1749 ;; 451 - You have not registered | |
1750 ;; 462 - Unauthorized command (already registered) | |
1751 ;; 463 - Your host isn't among the privileged | |
1752 ;; 464 - Password incorrect | |
1753 ;; 465 - You are banned from this server | |
1754 ;; 481 - Need IRCop privileges | |
1755 ;; 483 - You can't kill a server! | |
1756 ;; 484 - Your connection is restricted! | |
1757 ;; 485 - You're not the original channel operator | |
1758 ;; 491 - No O-lines for your host | |
1759 ;; 501 - Unknown MODE flag | |
1760 ;; 502 - Cannot change mode for other users | |
1761 nil nil | |
1762 (erc-display-error-notice | |
1763 parsed | |
1764 (intern (format "s%s" (erc-response.command parsed))))) | |
1765 | |
1766 ;; FIXME: These are yet to be implemented, they're just stubs for now | |
1767 ;; -- Lawrence 2004/05/12 | |
1768 | |
1769 ;; response numbers left here for reference | |
1770 | |
1771 ;; (define-erc-response-handler (323 364 365 381 382 392 393 394 395 | |
1772 ;; 200 201 202 203 204 205 206 208 209 211 212 213 | |
1773 ;; 214 215 216 217 218 219 241 242 243 244 249 261 | |
1774 ;; 262 302 342 351 402 407 409 411 413 414 415 | |
1775 ;; 423 424 436 441 443 444 467 471 472 473 KILL) | |
1776 ;; nil nil | |
1777 ;; (ignore proc parsed)) | |
1778 | |
1779 (provide 'erc-backend) | |
1780 | |
1781 ;;; erc-backend.el ends here | |
1782 ;; Local Variables: | |
1783 ;; indent-tabs-mode: nil | |
1784 ;; End: | |
1785 | |
1786 ;; arch-tag: a64e6bb7-a780-4efd-8f98-083b18c7c84a |