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