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