1 ;;; erc-backend.el --- Backend network communication for ERC
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Filename: erc-backend.el
6 ;; Author: Lawrence Mitchell <wence@gmx.li>
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/>.
28 ;; This file defines backend network communication handlers for ERC.
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
38 ;; Upon receiving a line from the server, `erc-parse-server-response'
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'
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
66 ;; (while (erc-response.command-args parsed)
67 ;; (let ((a (pop (erc-response.command-args parsed))))
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'.
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
93 ;; 2004/05/10 -- Handler bodies taken out of erc.el and ported to new
96 ;; 2005-08-13 -- Moved sending commands from erc.el.
100 (require 'erc-compat
)
101 (eval-when-compile (require 'cl
))
102 (autoload 'erc-with-buffer
"erc" nil nil
'macro
)
103 (autoload 'erc-log
"erc" nil nil
'macro
)
105 ;;;; Variables and options
107 (defvar erc-server-responses
(make-hash-table :test
#'equal
)
108 "Hashtable mapping server responses to their handler hooks.")
110 (defstruct (erc-response (:conc-name erc-response.
))
111 (unparsed "" :type string
)
112 (sender "" :type string
)
113 (command "" :type string
)
114 (command-args '() :type list
)
115 (contents "" :type string
))
119 (defvar erc-server-current-nick nil
120 "Nickname on the current server.
121 Use `erc-current-nick' to access this.")
122 (make-variable-buffer-local 'erc-server-current-nick
)
124 ;;; Server attributes
126 (defvar erc-server-process nil
127 "The process object of the corresponding server connection.")
128 (make-variable-buffer-local 'erc-server-process
)
130 (defvar erc-session-server nil
131 "The server name used to connect to for this session.")
132 (make-variable-buffer-local 'erc-session-server
)
134 (defvar erc-session-connector nil
135 "The function used to connect to this session (nil for the default).")
136 (make-variable-buffer-local 'erc-session-connector
)
138 (defvar erc-session-port nil
139 "The port used to connect to.")
140 (make-variable-buffer-local 'erc-session-port
)
142 (defvar erc-server-announced-name nil
143 "The name the server announced to use.")
144 (make-variable-buffer-local 'erc-server-announced-name
)
146 (defvar erc-server-version nil
147 "The name and version of the server's ircd.")
148 (make-variable-buffer-local 'erc-server-version
)
150 (defvar erc-server-parameters nil
151 "Alist listing the supported server parameters.
153 This is only set if the server sends 005 messages saying what is
154 supported on the server.
156 Entries are of the form:
159 (PARAMETER) if no value is provided.
161 Some examples of possible parameters sent by servers:
162 CHANMODES=b,k,l,imnpst - list of supported channel modes
163 CHANNELLEN=50 - maximum length of channel names
164 CHANTYPES=#&!+ - supported channel prefixes
165 CHARMAPPING=rfc1459 - character mapping used for nickname and channels
166 KICKLEN=160 - maximum allowed kick message length
167 MAXBANS=30 - maximum number of bans per channel
168 MAXCHANNELS=10 - maximum number of channels allowed to join
169 NETWORK=EFnet - the network identifier
170 NICKLEN=9 - maximum allowed length of nicknames
171 PREFIX=(ov)@+ - list of channel modes and the user prefixes if user has mode
172 RFC2812 - server supports RFC 2812 features
173 SILENCE=10 - supports the SILENCE command, maximum allowed number of entries
174 TOPICLEN=160 - maximum allowed topic length
175 WALLCHOPS - supports sending messages to all operators in a channel")
176 (make-variable-buffer-local 'erc-server-parameters
)
178 ;;; Server and connection state
180 (defvar erc-server-ping-timer-alist nil
181 "Mapping of server buffers to their specific ping timer.")
183 (defvar erc-server-connected nil
184 "Non-nil if the current buffer has been used by ERC to establish
187 If you wish to determine whether an IRC connection is currently
188 active, use the `erc-server-process-alive' function instead.")
189 (make-variable-buffer-local 'erc-server-connected
)
191 (defvar erc-server-reconnect-count
0
192 "Number of times we have failed to reconnect to the current server.")
193 (make-variable-buffer-local 'erc-server-reconnect-count
)
195 (defvar erc-server-quitting nil
196 "Non-nil if the user requests a quit.")
197 (make-variable-buffer-local 'erc-server-quitting
)
199 (defvar erc-server-reconnecting nil
200 "Non-nil if the user requests an explicit reconnect, and the
201 current IRC process is still alive.")
202 (make-variable-buffer-local 'erc-server-reconnecting
)
204 (defvar erc-server-timed-out nil
205 "Non-nil if the IRC server failed to respond to a ping.")
206 (make-variable-buffer-local 'erc-server-timed-out
)
208 (defvar erc-server-banned nil
209 "Non-nil if the user is denied access because of a server ban.")
210 (make-variable-buffer-local 'erc-server-banned
)
212 (defvar erc-server-error-occurred nil
213 "Non-nil if the user triggers some server error.")
214 (make-variable-buffer-local 'erc-server-error-occurred
)
216 (defvar erc-server-lines-sent nil
218 (make-variable-buffer-local 'erc-server-lines-sent
)
220 (defvar erc-server-last-peers
'(nil . nil
)
221 "Last peers used, both sender and receiver.
222 Those are used for /MSG destination shortcuts.")
223 (make-variable-buffer-local 'erc-server-last-peers
)
225 (defvar erc-server-last-sent-time nil
226 "Time the message was sent.
227 This is useful for flood protection.")
228 (make-variable-buffer-local 'erc-server-last-sent-time
)
230 (defvar erc-server-last-ping-time nil
231 "Time the last ping was sent.
232 This is useful for flood protection.")
233 (make-variable-buffer-local 'erc-server-last-ping-time
)
235 (defvar erc-server-last-received-time nil
236 "Time the last message was received from the server.
237 This is useful for detecting hung connections.")
238 (make-variable-buffer-local 'erc-server-last-received-time
)
240 (defvar erc-server-lag nil
241 "Calculated server lag time in seconds.
242 This variable is only set in a server buffer.")
243 (make-variable-buffer-local 'erc-server-lag
)
245 (defvar erc-server-filter-data nil
246 "The data that arrived from the server
247 but has not been processed yet.")
248 (make-variable-buffer-local 'erc-server-filter-data
)
250 (defvar erc-server-duplicates
(make-hash-table :test
'equal
)
251 "Internal variable used to track duplicate messages.")
252 (make-variable-buffer-local 'erc-server-duplicates
)
255 (defvar erc-server-processing-p nil
256 "Non-nil when we're currently processing a message.
258 When ERC receives a private message, it sets up a new buffer for
259 this query. These in turn, though, do start flyspell. This
260 involves starting an external process, in which case Emacs will
261 wait - and when it waits, it does accept other stuff from, say,
262 network exceptions. So, if someone sends you two messages
263 quickly after each other, ispell is started for the first, but
264 might take long enough for the second message to be processed
266 (make-variable-buffer-local 'erc-server-processing-p
)
268 (defvar erc-server-flood-last-message
0
269 "When we sent the last message.
270 See `erc-server-flood-margin' for an explanation of the flood
271 protection algorithm.")
272 (make-variable-buffer-local 'erc-server-flood-last-message
)
274 (defvar erc-server-flood-queue nil
275 "The queue of messages waiting to be sent to the server.
276 See `erc-server-flood-margin' for an explanation of the flood
277 protection algorithm.")
278 (make-variable-buffer-local 'erc-server-flood-queue
)
280 (defvar erc-server-flood-timer nil
281 "The timer to resume sending.")
282 (make-variable-buffer-local 'erc-server-flood-timer
)
284 ;;; IRC protocol and misc options
286 (defgroup erc-server nil
287 "Parameters for dealing with IRC servers."
290 (defcustom erc-server-auto-reconnect t
291 "Non-nil means that ERC will attempt to reestablish broken connections.
293 Reconnection will happen automatically for any unexpected disconnection."
297 (defcustom erc-server-reconnect-attempts
2
298 "The number of times that ERC will attempt to reestablish a
299 broken connection, or t to always attempt to reconnect.
301 This only has an effect if `erc-server-auto-reconnect' is non-nil."
303 :type
'(choice (const :tag
"Always reconnect" t
)
306 (defcustom erc-server-reconnect-timeout
1
307 "The amount of time, in seconds, that ERC will wait between
308 successive reconnect attempts.
310 If a key is pressed while ERC is waiting, it will stop waiting."
314 (defcustom erc-split-line-length
440
315 "The maximum length of a single message.
316 If a message exceeds this size, it is broken into multiple ones.
318 IRC allows for lines up to 512 bytes. Two of them are CR LF.
319 And a typical message looks like this:
321 :nicky!uhuser@host212223.dialin.fnordisp.net PRIVMSG #lazybastards :Hello!
323 You can limit here the maximum length of the \"Hello!\" part.
328 (defcustom erc-coding-system-precedence
'(utf-8 undecided
)
329 "List of coding systems to be preferred when receiving a string from the server.
330 This will only be consulted if the coding system in
331 `erc-server-coding-system' is `undecided'."
334 :type
'(repeat coding-system
))
336 (defcustom erc-server-coding-system
(if (and (fboundp 'coding-system-p
)
337 (coding-system-p 'undecided
)
338 (coding-system-p 'utf-8
))
341 "The default coding system for incoming and outgoing text.
342 This is either a coding system, a cons, a function, or nil.
344 If a cons, the encoding system for outgoing text is in the car
345 and the decoding system for incoming text is in the cdr. The most
346 interesting use for this is to put `undecided' in the cdr. This
347 means that `erc-coding-system-precedence' will be consulted, and the
348 first match there will be used.
350 If a function, it is called with the argument `target' and should
351 return a coding system or a cons as described above.
353 If you need to send non-ASCII text to people not using a client that
354 does decoding on its own, you must tell ERC what encoding to use.
355 Emacs cannot guess it, since it does not know what the people on the
356 other end of the line are using."
358 :type
'(choice (const :tag
"None" nil
)
360 (cons (coding-system :tag
"encoding" :value utf-8
)
361 (coding-system :tag
"decoding" :value undecided
))
364 (defcustom erc-encoding-coding-alist nil
365 "Alist of target regexp and coding-system pairs to use.
366 This overrides `erc-server-coding-system' depending on the
367 current target as returned by `erc-default-target'.
369 Example: If you know that the channel #linux-ru uses the coding-system
370 `cyrillic-koi8', then add '(\"#linux-ru\" . cyrillic-koi8) to the
373 :type
'(repeat (cons (string :tag
"Target")
376 (defcustom erc-server-connect-function
'open-network-stream
377 "Function used to initiate a connection.
378 It should take same arguments as `open-network-stream' does."
382 (defcustom erc-server-prevent-duplicates
'("301")
383 "Either nil or a list of strings.
384 Each string is a IRC message type, like PRIVMSG or NOTICE.
385 All Message types in that list of subjected to duplicate prevention."
386 :type
'(choice (const nil
) (list string
))
389 (defcustom erc-server-duplicate-timeout
60
390 "The time allowed in seconds between duplicate messages.
392 If two identical messages arrive within this value of one another, the second
397 (defcustom erc-server-timestamp-format
"%Y-%m-%d %T"
398 "Timestamp format used with server response messages.
399 This string is processed using `format-time-string'."
406 ;; Most of this is courtesy of Jorgen Schaefer and Circe
407 ;; (http://www.nongnu.org/circe)
409 (defcustom erc-server-flood-margin
10
410 "A margin on how much excess data we send.
411 The flood protection algorithm of ERC works like the one
412 detailed in RFC 2813, section 5.8 \"Flood control of clients\".
414 * If `erc-server-flood-last-message' is less than the current
416 * While `erc-server-flood-last-message' is less than
417 `erc-server-flood-margin' seconds ahead of the current
418 time, send a message, and increase
419 `erc-server-flood-last-message' by
420 `erc-server-flood-penalty' for each message."
424 (defcustom erc-server-flood-penalty
3
425 "How much we penalize a message.
426 See `erc-server-flood-margin' for an explanation of the flood
427 protection algorithm."
433 (defcustom erc-server-send-ping-interval
30
434 "Interval of sending pings to the server, in seconds.
435 If this is set to nil, pinging the server is disabled."
437 :type
'(choice (const :tag
"Disabled" nil
)
438 (integer :tag
"Seconds")))
440 (defcustom erc-server-send-ping-timeout
120
441 "If the time between ping and response is greater than this, reconnect.
442 The time is in seconds.
444 This must be greater than or equal to the value for
445 `erc-server-send-ping-interval'.
447 If this is set to nil, never try to reconnect."
449 :type
'(choice (const :tag
"Disabled" nil
)
450 (integer :tag
"Seconds")))
452 (defvar erc-server-ping-handler nil
453 "This variable holds the periodic ping timer.")
454 (make-variable-buffer-local 'erc-server-ping-handler
)
456 ;;;; Helper functions
459 (defun erc-split-line (longline)
460 "Return a list of lines which are not too long for IRC.
461 The length is specified in `erc-split-line-length'.
463 Currently this is called by `erc-send-input'."
464 (if (< (length longline
)
465 erc-split-line-length
)
469 (let ((fill-column erc-split-line-length
))
470 (fill-region (point-min) (point-max)
472 (split-string (buffer-string) "\n"))))
474 ;; Used by CTCP functions
475 (defun erc-upcase-first-word (str)
476 "Upcase the first word in STR."
479 (goto-char (point-min))
483 (defun erc-server-setup-periodical-ping (buffer)
484 "Set up a timer to periodically ping the current server.
485 The current buffer is given by BUFFER."
486 (with-current-buffer buffer
487 (and erc-server-ping-handler
(erc-cancel-timer erc-server-ping-handler
))
488 (when erc-server-send-ping-interval
489 (setq erc-server-ping-handler
(run-with-timer
490 4 erc-server-send-ping-interval
491 #'erc-server-send-ping
493 (setq erc-server-ping-timer-alist
(cons (cons buffer
494 erc-server-ping-handler
)
495 erc-server-ping-timer-alist
)))))
497 (defun erc-server-process-alive ()
498 "Return non-nil when `erc-server-process' is open or running."
499 (and erc-server-process
500 (processp erc-server-process
)
501 (memq (process-status erc-server-process
) '(run open
))))
503 ;;;; Connecting to a server
505 (defun erc-server-connect (server port buffer
)
506 "Perform the connection and login using the specified SERVER and PORT.
507 We will store server variables in the buffer given by BUFFER."
508 (let ((msg (erc-format-message 'connect ?S server ?p port
)))
510 (let ((process (funcall erc-server-connect-function
511 (format "erc-%s-%s" server port
)
513 (unless (processp process
)
514 (error "Connection attempt failed"))
515 (message "%s...done" msg
)
516 ;; Misc server variables
517 (with-current-buffer buffer
518 (setq erc-server-process process
)
519 (setq erc-server-quitting nil
)
520 (setq erc-server-reconnecting nil
)
521 (setq erc-server-timed-out nil
)
522 (setq erc-server-banned nil
)
523 (setq erc-server-error-occurred nil
)
524 (let ((time (erc-current-time)))
525 (setq erc-server-last-sent-time time
)
526 (setq erc-server-last-ping-time time
)
527 (setq erc-server-last-received-time time
))
528 (setq erc-server-lines-sent
0)
529 ;; last peers (sender and receiver)
530 (setq erc-server-last-peers
'(nil . nil
)))
531 ;; we do our own encoding and decoding
532 (when (fboundp 'set-process-coding-system
)
533 (set-process-coding-system process
'raw-text
))
535 (set-process-sentinel process
'erc-process-sentinel
)
536 (set-process-filter process
'erc-server-filter-function
)
537 (set-process-buffer process buffer
)))
538 (erc-log "\n\n\n********************************************\n")
539 (message "%s" (erc-format-message
541 (with-current-buffer buffer
(erc-current-nick))))
542 ;; wait with script loading until we receive a confirmation (first
544 (if (eq erc-server-connect-function
'open-network-stream-nowait
)
545 ;; it's a bit unclear otherwise that it's attempting to establish a
547 (erc-display-message nil nil buffer
"Opening connection..\n")
550 (defun erc-server-reconnect ()
551 "Reestablish the current IRC connection.
552 Make sure you are in an ERC buffer when running this."
553 (let ((buffer (erc-server-buffer)))
554 (unless (buffer-live-p buffer
)
555 (if (eq major-mode
'erc-mode
)
556 (setq buffer
(current-buffer))
557 (error "Reconnect must be run from an ERC buffer")))
558 (with-current-buffer buffer
559 (erc-update-mode-line)
560 (erc-set-active-buffer (current-buffer))
561 (setq erc-server-last-sent-time
0)
562 (setq erc-server-lines-sent
0)
563 (let ((erc-server-connect-function (or erc-session-connector
564 'open-network-stream
)))
565 (erc-open erc-session-server erc-session-port erc-server-current-nick
566 erc-session-user-full-name t erc-session-password
)))))
568 (defun erc-server-filter-function (process string
)
569 "The process filter for the ERC server."
570 (with-current-buffer (process-buffer process
)
571 (setq erc-server-last-received-time
(erc-current-time))
572 ;; If you think this is written in a weird way - please refer to the
573 ;; docstring of `erc-server-processing-p'
574 (if erc-server-processing-p
575 (setq erc-server-filter-data
576 (if erc-server-filter-data
577 (concat erc-server-filter-data string
)
579 ;; This will be true even if another process is spawned!
580 (let ((erc-server-processing-p t
))
581 (setq erc-server-filter-data
(if erc-server-filter-data
582 (concat erc-server-filter-data
585 (while (and erc-server-filter-data
586 (string-match "[\n\r]+" erc-server-filter-data
))
587 (let ((line (substring erc-server-filter-data
588 0 (match-beginning 0))))
589 (setq erc-server-filter-data
591 (length erc-server-filter-data
))
593 (substring erc-server-filter-data
595 (erc-log-irc-protocol line nil
)
596 (erc-parse-server-response process line
)))))))
598 (defsubst erc-server-reconnect-p
(event)
599 "Return non-nil if ERC should attempt to reconnect automatically.
600 EVENT is the message received from the closed connection process."
601 (or erc-server-reconnecting
602 (and erc-server-auto-reconnect
603 (not erc-server-banned
)
604 (not erc-server-error-occurred
)
605 ;; make sure we don't infinitely try to reconnect, unless the
607 (or (eq erc-server-reconnect-attempts t
)
608 (and (integerp erc-server-reconnect-attempts
)
609 (< erc-server-reconnect-count
610 erc-server-reconnect-attempts
)))
611 (or erc-server-timed-out
612 (not (string-match "^deleted" event
)))
613 ;; open-network-stream-nowait error for connection refused
614 (not (string-match "^failed with code 111" event
)))))
616 (defun erc-process-sentinel-2 (event buffer
)
617 "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
618 (if (not (buffer-live-p buffer
))
619 (erc-update-mode-line)
620 (with-current-buffer buffer
621 (let ((reconnect-p (erc-server-reconnect-p event
)))
622 (erc-display-message nil
'error
(current-buffer)
623 (if reconnect-p
'disconnected
624 'disconnected-noreconnect
))
625 (if (not reconnect-p
)
626 ;; terminate, do not reconnect
628 (erc-display-message nil
'error
(current-buffer)
629 'terminated ?e event
)
630 ;; Update mode line indicators
631 (erc-update-mode-line)
632 (set-buffer-modified-p nil
))
636 (setq erc-server-reconnecting nil
)
637 (erc-server-reconnect)
638 (setq erc-server-reconnect-count
0))
639 (error (when (buffer-live-p buffer
)
641 (if (integerp erc-server-reconnect-attempts
)
642 (setq erc-server-reconnect-count
643 (1+ erc-server-reconnect-count
))
645 "Reconnecting until we succeed"
646 "kill the ERC server buffer to stop"))
647 (if (numberp erc-server-reconnect-timeout
)
648 (run-at-time erc-server-reconnect-timeout nil
649 #'erc-process-sentinel-2
651 (error (concat "`erc-server-reconnect-timeout`"
652 " must be a number")))))))))))
654 (defun erc-process-sentinel-1 (event buffer
)
655 "Called when `erc-process-sentinel' has decided that we're disconnecting.
656 Determine whether user has quit or whether erc has been terminated.
657 Conditionally try to reconnect and take appropriate action."
658 (with-current-buffer buffer
659 (if erc-server-quitting
662 (erc-display-message nil
'error
(current-buffer) 'finished
)
663 ;; Update mode line indicators
664 (erc-update-mode-line)
665 ;; Kill server buffer if user wants it
666 (set-buffer-modified-p nil
)
667 (when erc-kill-server-buffer-on-quit
668 (kill-buffer (current-buffer))))
669 ;; unexpected disconnect
670 (erc-process-sentinel-2 event buffer
))))
672 (defun erc-process-sentinel (cproc event
)
673 "Sentinel function for ERC process."
674 (let ((buf (process-buffer cproc
)))
675 (when (buffer-live-p buf
)
676 (with-current-buffer buf
678 "SENTINEL: proc: %S status: %S event: %S (quitting: %S)"
679 cproc
(process-status cproc
) event erc-server-quitting
))
680 (if (string-match "^open" event
)
681 ;; newly opened connection (no wait)
683 ;; assume event is 'failed
684 (erc-with-all-buffers-of-server cproc nil
685 (setq erc-server-connected nil
))
686 (when erc-server-ping-handler
687 (progn (erc-cancel-timer erc-server-ping-handler
)
688 (setq erc-server-ping-handler nil
)))
689 (run-hook-with-args 'erc-disconnected-hook
690 (erc-current-nick) (system-name) "")
692 (goto-char (or (marker-position erc-input-marker
) (point-max)))
694 (erc-remove-text-properties-region (point) (point-max))
695 (delete-region (point) (point-max))
696 ;; Decide what to do with the buffer
697 ;; Restart if disconnected
698 (erc-process-sentinel-1 event buf
))))))
700 ;;;; Sending messages
702 (defun erc-coding-system-for-target (target)
703 "Return the coding system or cons cell appropriate for TARGET.
704 This is determined via `erc-encoding-coding-alist' or
705 `erc-server-coding-system'."
706 (unless target
(setq target
(erc-default-target)))
708 (let ((case-fold-search t
))
710 (dolist (pat erc-encoding-coding-alist
)
711 (when (string-match (car pat
) target
)
712 (throw 'match
(cdr pat
)))))))
713 (and (functionp erc-server-coding-system
)
714 (funcall erc-server-coding-system target
))
715 erc-server-coding-system
))
717 (defun erc-decode-string-from-target (str target
)
718 "Decode STR as appropriate for TARGET.
719 This is indicated by `erc-encoding-coding-alist', defaulting to the value of
720 `erc-server-coding-system'."
721 (unless (stringp str
)
723 (let ((coding (erc-coding-system-for-target target
)))
725 (setq coding
(cdr coding
)))
726 (when (eq coding
'undecided
)
727 (let ((codings (detect-coding-string str
))
728 (precedence erc-coding-system-precedence
))
729 (while (and precedence
730 (not (memq (car precedence
) codings
)))
733 (setq coding
(car precedence
)))))
734 (erc-decode-coding-string str coding
)))
736 ;; proposed name, not used by anything yet
737 (defun erc-send-line (text display-fn
)
738 "Send TEXT to the current server. Wrapping and flood control apply.
739 Use DISPLAY-FN to show the results."
741 (erc-server-send line
)
742 (funcall display-fn
))
743 (erc-split-line text
)))
745 ;; From Circe, with modifications
746 (defun erc-server-send (string &optional forcep target
)
747 "Send STRING to the current server.
748 If FORCEP is non-nil, no flood protection is done - the string is
749 sent directly. This might cause the messages to arrive in a wrong
752 If TARGET is specified, look up encoding information for that
753 channel in `erc-encoding-coding-alist' or
754 `erc-server-coding-system'.
756 See `erc-server-flood-margin' for an explanation of the flood
757 protection algorithm."
758 (erc-log (concat "erc-server-send: " string
"(" (buffer-name) ")"))
759 (setq erc-server-last-sent-time
(erc-current-time))
760 (let ((encoding (erc-coding-system-for-target target
)))
761 (when (consp encoding
)
762 (setq encoding
(car encoding
)))
763 (if (erc-server-process-alive)
764 (erc-with-server-buffer
765 (let ((str (concat string
"\r\n")))
768 (setq erc-server-flood-last-message
769 (+ erc-server-flood-penalty
770 erc-server-flood-last-message
))
771 (erc-log-irc-protocol str
'outbound
)
774 ;; Set encoding just before sending the string
775 (when (fboundp 'set-process-coding-system
)
776 (set-process-coding-system erc-server-process
778 (process-send-string erc-server-process str
))
779 ;; See `erc-server-send-queue' for full
780 ;; explanation of why we need this condition-case
782 (setq erc-server-flood-queue
783 (append erc-server-flood-queue
784 (list (cons str encoding
))))
785 (erc-server-send-queue (current-buffer))))
787 (message "ERC: No process running")
790 (defun erc-server-send-ping (buf)
791 "Send a ping to the IRC server buffer in BUF.
792 Additionally, detect whether the IRC process has hung."
793 (if (buffer-live-p buf
)
794 (with-current-buffer buf
795 (if (and erc-server-send-ping-timeout
797 (erc-time-diff (erc-current-time)
798 erc-server-last-received-time
)
799 erc-server-send-ping-timeout
))
801 ;; if the process is hung, kill it
802 (setq erc-server-timed-out t
)
803 (delete-process erc-server-process
))
804 (erc-server-send (format "PING %.0f" (erc-current-time)))))
805 ;; remove timer if the server buffer has been killed
806 (let ((timer (assq buf erc-server-ping-timer-alist
)))
808 (erc-cancel-timer (cdr timer
))
809 (setcdr timer nil
)))))
812 (defun erc-server-send-queue (buffer)
813 "Send messages in `erc-server-flood-queue'.
814 See `erc-server-flood-margin' for an explanation of the flood
815 protection algorithm."
816 (with-current-buffer buffer
817 (let ((now (erc-current-time)))
818 (when erc-server-flood-timer
819 (erc-cancel-timer erc-server-flood-timer
)
820 (setq erc-server-flood-timer nil
))
821 (when (< erc-server-flood-last-message
823 (setq erc-server-flood-last-message now
))
824 (while (and erc-server-flood-queue
825 (< erc-server-flood-last-message
826 (+ now erc-server-flood-margin
)))
827 (let ((msg (caar erc-server-flood-queue
))
828 (encoding (cdar erc-server-flood-queue
)))
829 (setq erc-server-flood-queue
(cdr erc-server-flood-queue
)
830 erc-server-flood-last-message
831 (+ erc-server-flood-last-message
832 erc-server-flood-penalty
))
833 (erc-log-irc-protocol msg
'outbound
)
834 (erc-log (concat "erc-server-send-queue: "
835 msg
"(" (buffer-name buffer
) ")"))
836 (when (erc-server-process-alive)
838 ;; Set encoding just before sending the string
840 (when (fboundp 'set-process-coding-system
)
841 (set-process-coding-system erc-server-process
843 (process-send-string erc-server-process msg
))
844 ;; Sometimes the send can occur while the process is
845 ;; being killed, which results in a weird SIGPIPE error.
846 ;; Catch this and ignore it.
848 (when erc-server-flood-queue
849 (setq erc-server-flood-timer
850 (run-at-time (+ 0.2 erc-server-flood-penalty
)
851 nil
#'erc-server-send-queue buffer
))))))
853 (defun erc-message (message-command line
&optional force
)
854 "Send LINE to the server as a privmsg or a notice.
855 MESSAGE-COMMAND should be either \"PRIVMSG\" or \"NOTICE\".
856 If the target is \",\", the last person you've got a message from will
857 be used. If the target is \".\", the last person you've sent a message
860 ((string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line
)
861 (let ((tgt (match-string 1 line
))
862 (s (match-string 2 line
)))
863 (erc-log (format "cmd: MSG(%s): [%s] %s" message-command tgt s
))
866 (if (car erc-server-last-peers
)
867 (setq tgt
(car erc-server-last-peers
))
870 (if (cdr erc-server-last-peers
)
871 (setq tgt
(cdr erc-server-last-peers
))
875 (setcdr erc-server-last-peers tgt
)
876 (erc-server-send (format "%s %s :%s" message-command tgt s
)
879 (erc-display-message nil
'error
(current-buffer) 'no-target
))))
885 (defun erc-send-ctcp-message (tgt l
&optional force
)
886 "Send CTCP message L to TGT.
888 If TGT is nil the message is not sent.
889 The command must contain neither a prefix nor a trailing `\\n'.
891 See also `erc-server-send'."
892 (let ((l (erc-upcase-first-word l
)))
895 (erc-log (format "erc-send-CTCP-message: [%s] %s" tgt l
))
896 (erc-server-send (format "PRIVMSG %s :\C-a%s\C-a" tgt l
)
899 (defun erc-send-ctcp-notice (tgt l
&optional force
)
900 "Send CTCP notice L to TGT.
902 If TGT is nil the message is not sent.
903 The command must contain neither a prefix nor a trailing `\\n'.
905 See also `erc-server-send'."
906 (let ((l (erc-upcase-first-word l
)))
909 (erc-log (format "erc-send-CTCP-notice: [%s] %s" tgt l
))
910 (erc-server-send (format "NOTICE %s :\C-a%s\C-a" tgt l
)
913 ;;;; Handling responses
915 (defun erc-parse-server-response (proc string
)
916 "Parse and act upon a complete line from an IRC server.
917 PROC is the process (connection) from which STRING was received.
918 PROCs `process-buffer' is `current-buffer' when this function is called."
919 (unless (string= string
"") ;; Ignore empty strings
921 (let ((posn (if (eq (aref string
0) ?
:)
922 (string-match " " string
)
924 (msg (make-erc-response :unparsed string
)))
926 (setf (erc-response.sender msg
)
929 (substring string
1 posn
)))
931 (setf (erc-response.command msg
)
932 (let* ((bposn (string-match "[^ \n]" string posn
))
933 (eposn (string-match " " string bposn
)))
934 (setq posn
(and eposn
935 (string-match "[^ \n]" string eposn
)))
936 (substring string bposn eposn
)))
939 (not (eq (aref string posn
) ?
:)))
940 (push (let* ((bposn posn
)
941 (eposn (string-match " " string bposn
)))
942 (setq posn
(and eposn
943 (string-match "[^ \n]" string eposn
)))
944 (substring string bposn eposn
))
945 (erc-response.command-args msg
)))
947 (let ((str (substring string
(1+ posn
))))
948 (push str
(erc-response.command-args msg
))))
950 (setf (erc-response.contents msg
)
951 (first (erc-response.command-args msg
)))
953 (setf (erc-response.command-args msg
)
954 (nreverse (erc-response.command-args msg
)))
956 (erc-decode-parsed-server-response msg
)
958 (erc-handle-parsed-server-response proc msg
)))))
960 (defun erc-decode-parsed-server-response (parsed-response)
961 "Decode a pre-parsed PARSED-RESPONSE before it can be handled.
963 If there is a channel name in `erc-response.command-args', decode
964 `erc-response' according to this channel name and
965 `erc-encoding-coding-alist', or use `erc-server-coding-system'
967 (let ((args (erc-response.command-args parsed-response
))
970 (dolist (arg args nil
)
971 (when (string-match "^[#&].*" arg
)
972 (setq decode-target arg
)))
973 (when (stringp decode-target
)
974 (setq decode-target
(erc-decode-string-from-target decode-target nil
)))
975 (setf (erc-response.unparsed parsed-response
)
976 (erc-decode-string-from-target
977 (erc-response.unparsed parsed-response
)
979 (setf (erc-response.sender parsed-response
)
980 (erc-decode-string-from-target
981 (erc-response.sender parsed-response
)
983 (setf (erc-response.command parsed-response
)
984 (erc-decode-string-from-target
985 (erc-response.command parsed-response
)
987 (dolist (arg (nreverse args
) nil
)
988 (push (erc-decode-string-from-target arg decode-target
)
990 (setf (erc-response.command-args parsed-response
) decoded-args
)
991 (setf (erc-response.contents parsed-response
)
992 (erc-decode-string-from-target
993 (erc-response.contents parsed-response
)
996 (defun erc-handle-parsed-server-response (process parsed-response
)
997 "Handle a pre-parsed PARSED-RESPONSE from PROCESS.
999 Hands off to helper functions via `erc-call-hooks'."
1000 (if (member (erc-response.command parsed-response
)
1001 erc-server-prevent-duplicates
)
1002 (let ((m (erc-response.unparsed parsed-response
)))
1003 ;; duplicate suppression
1004 (if (< (or (gethash m erc-server-duplicates
) 0)
1005 (- (erc-current-time) erc-server-duplicate-timeout
))
1006 (erc-call-hooks process parsed-response
))
1007 (puthash m
(erc-current-time) erc-server-duplicates
))
1008 ;; Hand off to the relevant handler.
1009 (erc-call-hooks process parsed-response
)))
1011 (defun erc-get-hook (command)
1012 "Return the hook variable associated with COMMAND.
1014 See also `erc-server-responses'."
1015 (gethash (format (if (numberp command
) "%03i" "%s") command
)
1016 erc-server-responses
))
1018 (defun erc-call-hooks (process message
)
1019 "Call hooks associated with MESSAGE in PROCESS.
1021 Finds hooks by looking in the `erc-server-responses' hashtable."
1022 (let ((hook (or (erc-get-hook (erc-response.command message
))
1023 'erc-default-server-functions
)))
1024 (run-hook-with-args-until-success hook process message
)
1025 (erc-with-server-buffer
1026 (run-hook-with-args 'erc-timer-hook
(erc-current-time)))))
1028 (add-hook 'erc-default-server-functions
'erc-handle-unknown-server-response
)
1030 (defun erc-handle-unknown-server-response (proc parsed
)
1031 "Display unknown server response's message."
1032 (let ((line (concat (erc-response.sender parsed
)
1034 (erc-response.command parsed
)
1036 (mapconcat 'identity
(erc-response.command-args parsed
)
1038 (erc-display-message parsed
'notice proc line
)))
1041 (put 'define-erc-response-handler
'edebug-form-spec
1042 '(&define
:name erc-response-handler
1044 &optional sexp sexp def-body
))
1046 (defmacro* define-erc-response-handler
((name &rest aliases
)
1047 &optional extra-fn-doc extra-var-doc
1049 "Define an ERC handler hook/function pair.
1050 NAME is the response name as sent by the server (see the IRC RFC for
1054 - a hook variable `erc-server-NAME-functions' initialized to `erc-server-NAME'.
1055 - a function `erc-server-NAME' with body FN-BODY.
1057 If ALIASES is non-nil, each alias in ALIASES is `defalias'ed to
1059 Alias hook variables are created as `erc-server-ALIAS-functions' and
1060 initialized to the same default value as `erc-server-NAME-functions'.
1062 FN-BODY is the body of `erc-server-NAME' it may refer to the two
1063 function arguments PROC and PARSED.
1065 If EXTRA-FN-DOC is non-nil, it is inserted at the beginning of the
1066 defined function's docstring.
1068 If EXTRA-VAR-DOC is non-nil, it is inserted at the beginning of the
1069 defined variable's docstring.
1073 (define-erc-response-handler (311 WHOIS WI)
1074 \"Some non-generic function documentation.\"
1075 \"Some non-generic variable documentation.\"
1076 (do-stuff-with-whois proc parsed))
1081 (defvar erc-server-311-functions 'erc-server-311
1082 \"Some non-generic variable documentation.
1084 Hook called upon receiving a 311 server response.
1085 Each function is called with two arguments, the process associated
1086 with the response and the parsed response.
1087 See also `erc-server-311'.\")
1089 (defun erc-server-311 (proc parsed)
1090 \"Some non-generic function documentation.
1092 Handler for a 311 server response.
1093 PROC is the server process which returned the response.
1094 PARSED is the actual response as an `erc-response' struct.
1095 If you want to add responses don't modify this function, but rather
1096 add things to `erc-server-311-functions' instead.\"
1097 (do-stuff-with-whois proc parsed))
1099 (puthash \"311\" 'erc-server-311-functions erc-server-responses)
1100 (puthash \"WHOIS\" 'erc-server-WHOIS-functions erc-server-responses)
1101 (puthash \"WI\" 'erc-server-WI-functions erc-server-responses)
1103 (defalias 'erc-server-WHOIS 'erc-server-311)
1104 (defvar erc-server-WHOIS-functions 'erc-server-311
1105 \"Some non-generic variable documentation.
1107 Hook called upon receiving a WHOIS server response.
1109 Each function is called with two arguments, the process associated
1110 with the response and the parsed response. If the function returns
1111 non-nil, stop processing the hook. Otherwise, continue.
1113 See also `erc-server-311'.\")
1115 (defalias 'erc-server-WI 'erc-server-311)
1116 (defvar erc-server-WI-functions 'erc-server-311
1117 \"Some non-generic variable documentation.
1119 Hook called upon receiving a WI server response.
1120 Each function is called with two arguments, the process associated
1121 with the response and the parsed response. If the function returns
1122 non-nil, stop processing the hook. Otherwise, continue.
1124 See also `erc-server-311'.\"))
1126 \(fn (NAME &rest ALIASES) &optional EXTRA-FN-DOC EXTRA-VAR-DOC &rest FN-BODY)"
1127 (if (numberp name
) (setq name
(intern (format "%03i" name
))))
1128 (setq aliases
(mapcar (lambda (a)
1133 (let* ((hook-name (intern (format "erc-server-%s-functions" name
)))
1134 (fn-name (intern (format "erc-server-%s" name
)))
1135 (hook-doc (format "%sHook called upon receiving a %%s server response.
1136 Each function is called with two arguments, the process associated
1137 with the response and the parsed response. If the function returns
1138 non-nil, stop processing the hook. Otherwise, continue.
1142 (concat extra-var-doc
"\n\n")
1145 (fn-doc (format "%sHandler for a %s server response.
1146 PROC is the server process which returned the response.
1147 PARSED is the actual response as an `erc-response' struct.
1148 If you want to add responses don't modify this function, but rather
1149 add things to `%s' instead."
1151 (concat extra-fn-doc
"\n\n")
1155 (loop for alias in aliases
1156 collect
(intern (format "erc-server-%s" alias
))))
1158 (loop for alias in aliases
1159 collect
(intern (format "erc-server-%s-functions" alias
)))))
1161 ;; Normal hook variable.
1162 (defvar ,hook-name
',fn-name
,(format hook-doc name
))
1164 (defun ,fn-name
(proc parsed
)
1168 ;; Make find-function and find-variable find them
1169 (put ',fn-name
'definition-name
',name
)
1170 (put ',hook-name
'definition-name
',name
)
1172 ;; Hashtable map of responses to hook variables
1173 ,@(loop for response in
(cons name aliases
)
1174 for var in
(cons hook-name var-alternates
)
1175 collect
`(puthash ,(format "%s" response
) ',var
1176 erc-server-responses
))
1178 ;; Functions are defaliased, hook variables are defvared so we
1179 ;; can add hooks to one alias, but not another.
1180 ,@(loop for fn in fn-alternates
1181 for var in var-alternates
1183 nconc
(list `(defalias ',fn
',fn-name
)
1184 `(defvar ,var
',fn-name
,(format hook-doc a
))
1185 `(put ',var
'definition-name
',hook-name
))))))
1187 (define-erc-response-handler (ERROR)
1188 "Handle an ERROR command from the server." nil
1189 (setq erc-server-error-occurred t
)
1190 (erc-display-message
1191 parsed
'error nil
'ERROR
1192 ?s
(erc-response.sender parsed
) ?c
(erc-response.contents parsed
)))
1194 (define-erc-response-handler (INVITE)
1195 "Handle invitation messages."
1197 (let ((target (first (erc-response.command-args parsed
)))
1198 (chnl (erc-response.contents parsed
)))
1199 (multiple-value-bind (nick login host
)
1200 (values-list (erc-parse-user (erc-response.sender parsed
)))
1201 (setq erc-invitation chnl
)
1202 (when (string= target
(erc-current-nick))
1203 (erc-display-message
1204 parsed
'notice
'active
1205 'INVITE ?n nick ?u login ?h host ?c chnl
)))))
1208 (define-erc-response-handler (JOIN)
1209 "Handle join messages."
1211 (let ((chnl (erc-response.contents parsed
))
1213 (multiple-value-bind (nick login host
)
1214 (values-list (erc-parse-user (erc-response.sender parsed
)))
1215 ;; strip the stupid combined JOIN facility (IRC 2.9)
1216 (if (string-match "^\\(.*\\)?\^g.*$" chnl
)
1217 (setq chnl
(match-string 1 chnl
)))
1220 ;; If I have joined a channel
1221 ((erc-current-nick-p nick
)
1222 (setq buffer
(erc-open erc-session-server erc-session-port
1223 nick erc-session-user-full-name
1226 erc-server-process
))
1229 (erc-add-default-channel chnl
)
1230 (erc-server-send (format "MODE %s" chnl
)))
1231 (erc-with-buffer (chnl proc
)
1232 (erc-channel-begin-receiving-names))
1233 (erc-update-mode-line)
1234 (run-hooks 'erc-join-hook
)
1236 (erc-format-message 'JOIN-you ?c chnl
)))
1238 (setq buffer
(erc-get-buffer chnl proc
))
1241 'JOIN ?n nick ?u login ?h host ?c chnl
))))))
1242 (when buffer
(set-buffer buffer
))
1243 (erc-update-channel-member chnl nick nick t nil nil host login
)
1244 ;; on join, we want to stay in the new channel buffer
1246 (erc-display-message parsed nil buffer str
))))))
1248 (define-erc-response-handler (KICK)
1249 "Handle kick messages received from the server." nil
1250 (let* ((ch (first (erc-response.command-args parsed
)))
1251 (tgt (second (erc-response.command-args parsed
)))
1252 (reason (erc-trim-string (erc-response.contents parsed
)))
1253 (buffer (erc-get-buffer ch proc
)))
1254 (multiple-value-bind (nick login host
)
1255 (values-list (erc-parse-user (erc-response.sender parsed
)))
1256 (erc-remove-channel-member buffer tgt
)
1258 ((string= tgt
(erc-current-nick))
1259 (erc-display-message
1260 parsed
'notice buffer
1261 'KICK-you ?n nick ?u login ?h host ?c ch ?r reason
)
1262 (run-hook-with-args 'erc-kick-hook buffer
)
1265 (erc-remove-channel-users))
1266 (erc-delete-default-channel ch buffer
)
1267 (erc-update-mode-line buffer
))
1268 ((string= nick
(erc-current-nick))
1269 (erc-display-message
1270 parsed
'notice buffer
1271 'KICK-by-you ?k tgt ?c ch ?r reason
))
1272 (t (erc-display-message
1273 parsed
'notice buffer
1274 'KICK ?k tgt ?n nick ?u login ?h host ?c ch ?r reason
))))))
1276 (define-erc-response-handler (MODE)
1277 "Handle server mode changes." nil
1278 (let ((tgt (first (erc-response.command-args parsed
)))
1279 (mode (mapconcat 'identity
(cdr (erc-response.command-args parsed
))
1281 (multiple-value-bind (nick login host
)
1282 (values-list (erc-parse-user (erc-response.sender parsed
)))
1283 (erc-log (format "MODE: %s -> %s: %s" nick tgt mode
))
1285 (let ((buf (cond ((erc-channel-p tgt
)
1286 (erc-get-buffer tgt proc
))
1287 ((string= tgt
(erc-current-nick)) nil
)
1288 ((erc-active-buffer) (erc-active-buffer))
1289 (t (erc-get-buffer tgt
)))))
1290 (with-current-buffer (or buf
1292 (erc-update-modes tgt mode nick host login
))
1293 (if (or (string= login
"") (string= host
""))
1294 (erc-display-message parsed
'notice buf
1297 (erc-display-message parsed
'notice buf
1298 'MODE ?n nick ?u login
1299 ?h host ?t tgt ?m mode
)))
1300 (erc-banlist-update proc parsed
))))
1302 (define-erc-response-handler (NICK)
1303 "Handle nick change messages." nil
1304 (let ((nn (erc-response.contents parsed
))
1306 (multiple-value-bind (nick login host
)
1307 (values-list (erc-parse-user (erc-response.sender parsed
)))
1308 (setq bufs
(erc-buffer-list-with-nick nick proc
))
1309 (erc-log (format "NICK: %s -> %s" nick nn
))
1310 ;; if we had a query with this user, make sure future messages will be
1311 ;; sent to the correct nick. also add to bufs, since the user will want
1312 ;; to see the nick change in the query, and if it's a newly begun query,
1313 ;; erc-channel-users won't contain it
1316 (when (equal (erc-default-target) nick
)
1317 (setq erc-default-recipients
1318 (cons nn
(cdr erc-default-recipients
)))
1319 (rename-buffer nn t
) ; bug#12002
1320 (erc-update-mode-line)
1321 (add-to-list 'bufs
(current-buffer)))))
1322 (erc-update-user-nick nick nn host nil nil login
)
1324 ((string= nick
(erc-current-nick))
1325 (add-to-list 'bufs
(erc-server-buffer))
1326 (erc-set-current-nick nn
)
1327 (erc-update-mode-line)
1328 (setq erc-nick-change-attempt-count
0)
1329 (setq erc-default-nicks
(if (consp erc-nick
) erc-nick
(list erc-nick
)))
1330 (erc-display-message
1332 'NICK-you ?n nick ?N nn
)
1333 (run-hook-with-args 'erc-nick-changed-functions nn nick
))
1335 (erc-handle-user-status-change 'nick
(list nick login host
) (list nn
))
1336 (erc-display-message parsed
'notice bufs
'NICK ?n nick
1337 ?u login ?h host ?N nn
))))))
1339 (define-erc-response-handler (PART)
1340 "Handle part messages." nil
1341 (let* ((chnl (first (erc-response.command-args parsed
)))
1342 (reason (erc-trim-string (erc-response.contents parsed
)))
1343 (buffer (erc-get-buffer chnl proc
)))
1344 (multiple-value-bind (nick login host
)
1345 (values-list (erc-parse-user (erc-response.sender parsed
)))
1346 (erc-remove-channel-member buffer nick
)
1347 (erc-display-message parsed
'notice buffer
1348 'PART ?n nick ?u login
1349 ?h host ?c chnl ?r
(or reason
""))
1350 (when (string= nick
(erc-current-nick))
1351 (run-hook-with-args 'erc-part-hook buffer
)
1354 (erc-remove-channel-users))
1355 (erc-delete-default-channel chnl buffer
)
1356 (erc-update-mode-line buffer
)
1357 (when erc-kill-buffer-on-part
1358 (kill-buffer buffer
))))))
1360 (define-erc-response-handler (PING)
1361 "Handle ping messages." nil
1362 (let ((pinger (first (erc-response.command-args parsed
))))
1363 (erc-log (format "PING: %s" pinger
))
1364 ;; ping response to the server MUST be forced, or you can lose big
1365 (erc-server-send (format "PONG :%s" pinger
) t
)
1366 (when erc-verbose-server-ping
1367 (erc-display-message
1369 'PING ?s
(erc-time-diff erc-server-last-ping-time
(erc-current-time))))
1370 (setq erc-server-last-ping-time
(erc-current-time))))
1372 (define-erc-response-handler (PONG)
1373 "Handle pong messages." nil
1374 (let ((time (string-to-number (erc-response.contents parsed
))))
1376 (setq erc-server-lag
(erc-time-diff time
(erc-current-time)))
1377 (when erc-verbose-server-ping
1378 (erc-display-message
1379 parsed
'notice proc
'PONG
1380 ?h
(first (erc-response.command-args parsed
)) ?i erc-server-lag
1381 ?s
(if (/= erc-server-lag
1) "s" "")))
1382 (erc-update-mode-line))))
1384 (define-erc-response-handler (PRIVMSG NOTICE
)
1385 "Handle private messages, including messages in channels." nil
1386 (let ((sender-spec (erc-response.sender parsed
))
1387 (cmd (erc-response.command parsed
))
1388 (tgt (car (erc-response.command-args parsed
)))
1389 (msg (erc-response.contents parsed
)))
1390 (if (or (erc-ignored-user-p sender-spec
)
1391 (erc-ignored-reply-p msg tgt proc
))
1392 (when erc-minibuffer-ignored
1393 (message "Ignored %s from %s to %s" cmd sender-spec tgt
))
1394 (let* ((sndr (erc-parse-user sender-spec
))
1396 (login (nth 1 sndr
))
1398 (msgp (string= cmd
"PRIVMSG"))
1399 (noticep (string= cmd
"NOTICE"))
1400 ;; S.B. downcase *both* tgt and current nick
1401 (privp (erc-current-nick-p tgt
))
1404 (setf (erc-response.contents parsed
) msg
)
1405 (setq buffer
(erc-get-buffer (if privp nick tgt
) proc
))
1407 (with-current-buffer buffer
1408 ;; update the chat partner info. Add to the list if private
1409 ;; message. We will accumulate private identities indefinitely
1411 (erc-update-channel-member (if privp nick tgt
) nick nick
1412 privp nil nil host login nil nil t
)
1413 (let ((cdata (erc-get-channel-user nick
)))
1414 (setq fnick
(funcall erc-format-nick-function
1415 (car cdata
) (cdr cdata
))))))
1417 ((erc-is-message-ctcp-p msg
)
1419 (erc-process-ctcp-query proc parsed nick login host
)
1420 (erc-process-ctcp-reply proc parsed nick login host
1421 (match-string 1 msg
)))))
1423 (setcar erc-server-last-peers nick
)
1424 (setq s
(erc-format-privmessage
1426 ;; If buffer is a query buffer,
1427 ;; format the nick as for a channel.
1428 (and (not (and buffer
1429 (erc-query-buffer-p buffer
)
1430 erc-format-query-as-channel-p
))
1434 (if (and noticep privp
)
1436 (run-hook-with-args 'erc-echo-notice-always-hook
1437 s parsed buffer nick
)
1438 (run-hook-with-args-until-success
1439 'erc-echo-notice-hook s parsed buffer nick
))
1440 (erc-display-message parsed nil buffer s
)))
1441 (when (string= cmd
"PRIVMSG")
1442 (erc-auto-query proc parsed
))))))
1444 ;; FIXME: need clean way of specifying extra hooks in
1445 ;; define-erc-response-handler.
1446 (add-hook 'erc-server-PRIVMSG-functions
'erc-auto-query
)
1448 (define-erc-response-handler (QUIT)
1449 "Another user has quit IRC." nil
1450 (let ((reason (erc-response.contents parsed
))
1452 (multiple-value-bind (nick login host
)
1453 (values-list (erc-parse-user (erc-response.sender parsed
)))
1454 (setq bufs
(erc-buffer-list-with-nick nick proc
))
1455 (erc-remove-user nick
)
1456 (setq reason
(erc-wash-quit-reason reason nick login host
))
1457 (erc-display-message parsed
'notice bufs
1458 'QUIT ?n nick ?u login
1459 ?h host ?r reason
))))
1461 (define-erc-response-handler (TOPIC)
1462 "The channel topic has changed." nil
1463 (let* ((ch (first (erc-response.command-args parsed
)))
1464 (topic (erc-trim-string (erc-response.contents parsed
)))
1465 (time (format-time-string erc-server-timestamp-format
1467 (multiple-value-bind (nick login host
)
1468 (values-list (erc-parse-user (erc-response.sender parsed
)))
1469 (erc-update-channel-member ch nick nick nil nil nil host login
)
1470 (erc-update-channel-topic ch
(format "%s\C-o (%s, %s)" topic nick time
))
1471 (erc-display-message parsed
'notice
(erc-get-buffer ch proc
)
1472 'TOPIC ?n nick ?u login ?h host
1475 (define-erc-response-handler (WALLOPS)
1476 "Display a WALLOPS message." nil
1477 (let ((message (erc-response.contents parsed
)))
1478 (multiple-value-bind (nick login host
)
1479 (values-list (erc-parse-user (erc-response.sender parsed
)))
1480 (erc-display-message
1482 'WALLOPS ?n nick ?m message
))))
1484 (define-erc-response-handler (001)
1485 "Set `erc-server-current-nick' to reflect server settings and display the welcome message."
1487 (erc-set-current-nick (first (erc-response.command-args parsed
)))
1488 (erc-update-mode-line) ; needed here?
1489 (setq erc-nick-change-attempt-count
0)
1490 (setq erc-default-nicks
(if (consp erc-nick
) erc-nick
(list erc-nick
)))
1491 (erc-display-message
1492 parsed
'notice
'active
(erc-response.contents parsed
)))
1494 (define-erc-response-handler (MOTD 002 003 371 372 374 375)
1495 "Display the server's message of the day." nil
1497 (erc-display-message
1498 parsed
'notice
(if erc-server-connected
'active proc
)
1499 (erc-response.contents parsed
)))
1501 (define-erc-response-handler (376 422)
1502 "End of MOTD/MOTD is missing." nil
1503 (erc-server-MOTD proc parsed
)
1504 (erc-connection-established proc parsed
))
1506 (define-erc-response-handler (004)
1507 "Display the server's identification." nil
1508 (multiple-value-bind (server-name server-version
)
1509 (values-list (cdr (erc-response.command-args parsed
)))
1510 (setq erc-server-version server-version
)
1511 (setq erc-server-announced-name server-name
)
1512 (erc-update-mode-line-buffer (process-buffer proc
))
1513 (erc-display-message
1515 's004 ?s server-name ?v server-version
1516 ?U
(fourth (erc-response.command-args parsed
))
1517 ?C
(fifth (erc-response.command-args parsed
)))))
1519 (define-erc-response-handler (005)
1520 "Set the variable `erc-server-parameters' and display the received message.
1522 According to RFC 2812, suggests alternate servers on the network.
1523 Many servers, however, use this code to show which parameters they have set,
1524 for example, the network identifier, maximum allowed topic length, whether
1525 certain commands are accepted and more. See documentation for
1526 `erc-server-parameters' for more information on the parameters sent.
1528 A server may send more than one 005 message."
1530 (let ((line (mapconcat 'identity
1531 (setf (erc-response.command-args parsed
)
1532 (cdr (erc-response.command-args parsed
)))
1534 (while (erc-response.command-args parsed
)
1535 (let ((section (pop (erc-response.command-args parsed
))))
1536 ;; fill erc-server-parameters
1537 (when (string-match "^\\([A-Z]+\\)\=\\(.*\\)$\\|^\\([A-Z]+\\)$"
1539 (add-to-list 'erc-server-parameters
1540 `(,(or (match-string 1 section
)
1541 (match-string 3 section
))
1543 ,(match-string 2 section
))))))
1544 (erc-display-message parsed
'notice proc line
)))
1546 (define-erc-response-handler (221)
1547 "Display the current user modes." nil
1548 (let* ((nick (first (erc-response.command-args parsed
)))
1549 (modes (mapconcat 'identity
1550 (cdr (erc-response.command-args parsed
)) " ")))
1551 (erc-set-modes nick modes
)
1552 (erc-display-message parsed
'notice
'active
's221 ?n nick ?m modes
)))
1554 (define-erc-response-handler (252)
1555 "Display the number of IRC operators online." nil
1556 (erc-display-message parsed
'notice
'active
's252
1557 ?i
(second (erc-response.command-args parsed
))))
1559 (define-erc-response-handler (253)
1560 "Display the number of unknown connections." nil
1561 (erc-display-message parsed
'notice
'active
's253
1562 ?i
(second (erc-response.command-args parsed
))))
1564 (define-erc-response-handler (254)
1565 "Display the number of channels formed." nil
1566 (erc-display-message parsed
'notice
'active
's254
1567 ?i
(second (erc-response.command-args parsed
))))
1569 (define-erc-response-handler (250 251 255 256 257 258 259 265 266 377 378)
1570 "Generic display of server messages as notices.
1572 See `erc-display-server-message'." nil
1573 (erc-display-server-message proc parsed
))
1575 (define-erc-response-handler (275)
1576 "Display secure connection message." nil
1577 (multiple-value-bind (nick user message
)
1578 (values-list (cdr (erc-response.command-args parsed
)))
1579 (erc-display-message
1580 parsed
'notice
'active
's275
1582 ?m
(mapconcat 'identity
(cddr (erc-response.command-args parsed
))
1585 (define-erc-response-handler (290)
1586 "Handle dancer-ircd CAPAB messages." nil nil
)
1588 (define-erc-response-handler (301)
1590 (erc-display-message parsed
'notice
'active
's301
1591 ?n
(second (erc-response.command-args parsed
))
1592 ?r
(erc-response.contents parsed
)))
1594 (define-erc-response-handler (303)
1596 (erc-display-message parsed
'notice
'active
's303
1597 ?n
(second (erc-response.command-args parsed
))))
1599 (define-erc-response-handler (305)
1600 "Return from AWAYness." nil
1601 (erc-process-away proc nil
)
1602 (erc-display-message parsed
'notice
'active
1603 's305 ?m
(erc-response.contents parsed
)))
1605 (define-erc-response-handler (306)
1607 (erc-process-away proc t
)
1608 (erc-display-message parsed
'notice
'active
1609 's306 ?m
(erc-response.contents parsed
)))
1611 (define-erc-response-handler (307)
1612 "Display nick-identified message." nil
1613 (multiple-value-bind (nick user message
)
1614 (values-list (cdr (erc-response.command-args parsed
)))
1615 (erc-display-message
1616 parsed
'notice
'active
's307
1618 ?m
(mapconcat 'identity
(cddr (erc-response.command-args parsed
))
1621 (define-erc-response-handler (311 314)
1622 "WHOIS/WHOWAS notices." nil
1623 (let ((fname (erc-response.contents parsed
))
1624 (catalog-entry (intern (format "s%s" (erc-response.command parsed
)))))
1625 (multiple-value-bind (nick user host
)
1626 (values-list (cdr (erc-response.command-args parsed
)))
1627 (erc-update-user-nick nick nick host nil fname user
)
1628 (erc-display-message
1629 parsed
'notice
'active catalog-entry
1630 ?n nick ?f fname ?u user ?h host
))))
1632 (define-erc-response-handler (312)
1633 "Server name response in WHOIS." nil
1634 (multiple-value-bind (nick server-host
)
1635 (values-list (cdr (erc-response.command-args parsed
)))
1636 (erc-display-message
1637 parsed
'notice
'active
's312
1638 ?n nick ?s server-host ?c
(erc-response.contents parsed
))))
1640 (define-erc-response-handler (313)
1641 "IRC Operator response in WHOIS." nil
1642 (erc-display-message
1643 parsed
'notice
'active
's313
1644 ?n
(second (erc-response.command-args parsed
))))
1646 (define-erc-response-handler (315 318 323 369)
1648 ;; 318 - End of WHOIS list
1649 ;; 323 - End of channel LIST
1650 ;; 369 - End of WHOWAS
1651 "End of WHO/WHOIS/LIST/WHOWAS notices." nil
1652 (ignore proc parsed
))
1654 (define-erc-response-handler (317)
1656 (multiple-value-bind (nick seconds-idle on-since time
)
1657 (values-list (cdr (erc-response.command-args parsed
)))
1658 (setq time
(when on-since
1659 (format-time-string erc-server-timestamp-format
1660 (erc-string-to-emacs-time on-since
))))
1661 (erc-update-user-nick nick nick nil nil nil
1662 (and time
(format "on since %s" time
)))
1664 (erc-display-message
1665 parsed
'notice
'active
's317-on-since
1666 ?n nick ?i
(erc-sec-to-time (string-to-number seconds-idle
)) ?t time
)
1667 (erc-display-message
1668 parsed
'notice
'active
's317
1669 ?n nick ?i
(erc-sec-to-time (string-to-number seconds-idle
))))))
1671 (define-erc-response-handler (319)
1672 "Channel names in WHOIS response." nil
1673 (erc-display-message
1674 parsed
'notice
'active
's319
1675 ?n
(second (erc-response.command-args parsed
))
1676 ?c
(erc-response.contents parsed
)))
1678 (define-erc-response-handler (320)
1679 "Identified user in WHOIS." nil
1680 (erc-display-message
1681 parsed
'notice
'active
's320
1682 ?n
(second (erc-response.command-args parsed
))))
1684 (define-erc-response-handler (321)
1686 (setq erc-channel-list nil
))
1688 (defun erc-server-321-message (proc parsed
)
1689 "Display a message for the 321 event."
1690 (erc-display-message parsed
'notice proc
's321
)
1692 (add-hook 'erc-server-321-functions
'erc-server-321-message t
)
1694 (define-erc-response-handler (322)
1696 (let ((topic (erc-response.contents parsed
)))
1697 (multiple-value-bind (channel num-users
)
1698 (values-list (cdr (erc-response.command-args parsed
)))
1699 (add-to-list 'erc-channel-list
(list channel
))
1700 (erc-update-channel-topic channel topic
))))
1702 (defun erc-server-322-message (proc parsed
)
1703 "Display a message for the 322 event."
1704 (let ((topic (erc-response.contents parsed
)))
1705 (multiple-value-bind (channel num-users
)
1706 (values-list (cdr (erc-response.command-args parsed
)))
1707 (erc-display-message
1708 parsed
'notice proc
's322
1709 ?c channel ?u num-users ?t
(or topic
"")))))
1710 (add-hook 'erc-server-322-functions
'erc-server-322-message t
)
1712 (define-erc-response-handler (324)
1713 "Channel or nick modes." nil
1714 (let ((channel (second (erc-response.command-args parsed
)))
1715 (modes (mapconcat 'identity
(cddr (erc-response.command-args parsed
))
1717 (erc-set-modes channel modes
)
1718 (erc-display-message
1719 parsed
'notice
(erc-get-buffer channel proc
)
1720 's324 ?c channel ?m modes
)))
1722 (define-erc-response-handler (328)
1723 "Channel URL (on freenode network)." nil
1724 (let ((channel (second (erc-response.command-args parsed
)))
1725 (url (erc-response.contents parsed
)))
1726 (erc-display-message parsed
'notice
(erc-get-buffer channel proc
)
1727 's328 ?c channel ?u url
)))
1729 (define-erc-response-handler (329)
1730 "Channel creation date." nil
1731 (let ((channel (second (erc-response.command-args parsed
)))
1732 (time (erc-string-to-emacs-time
1733 (third (erc-response.command-args parsed
)))))
1734 (erc-display-message
1735 parsed
'notice
(erc-get-buffer channel proc
)
1736 's329 ?c channel ?t
(format-time-string erc-server-timestamp-format
1739 (define-erc-response-handler (330)
1740 "Nick is authed as (on Quakenet network)." nil
1741 ;; FIXME: I don't know what the magic numbers mean. Mummy, make
1742 ;; the magic numbers go away.
1743 ;; No seriously, I have no clue about the format of this command,
1744 ;; and don't sit on Quakenet, so can't test. Originally we had:
1745 ;; nick == (aref parsed 3)
1746 ;; authaccount == (aref parsed 4)
1747 ;; authmsg == (aref parsed 5)
1748 ;; The guesses below are, well, just that. -- Lawrence 2004/05/10
1749 (let ((nick (second (erc-response.command-args parsed
)))
1750 (authaccount (third (erc-response.command-args parsed
)))
1751 (authmsg (erc-response.contents parsed
)))
1752 (erc-display-message parsed
'notice
'active
's330
1753 ?n nick ?a authmsg ?i authaccount
)))
1755 (define-erc-response-handler (331)
1756 "No topic set for channel." nil
1757 (let ((channel (second (erc-response.command-args parsed
)))
1758 (topic (erc-response.contents parsed
)))
1759 (erc-display-message parsed
'notice
(erc-get-buffer channel proc
)
1762 (define-erc-response-handler (332)
1764 (let ((channel (second (erc-response.command-args parsed
)))
1765 (topic (erc-response.contents parsed
)))
1766 (erc-update-channel-topic channel topic
)
1767 (erc-display-message parsed
'notice
(erc-get-buffer channel proc
)
1768 's332 ?c channel ?T topic
)))
1770 (define-erc-response-handler (333)
1771 "Who set the topic, and when." nil
1772 (multiple-value-bind (channel nick time
)
1773 (values-list (cdr (erc-response.command-args parsed
)))
1774 (setq time
(format-time-string erc-server-timestamp-format
1775 (erc-string-to-emacs-time time
)))
1776 (erc-update-channel-topic channel
1777 (format "\C-o (%s, %s)" nick time
)
1779 (erc-display-message parsed
'notice
(erc-get-buffer channel proc
)
1780 's333 ?c channel ?n nick ?t time
)))
1782 (define-erc-response-handler (341)
1783 "Let user know when an INVITE attempt has been sent successfully."
1785 (multiple-value-bind (nick channel
)
1786 (values-list (cdr (erc-response.command-args parsed
)))
1787 (erc-display-message parsed
'notice
(erc-get-buffer channel proc
)
1788 's341 ?n nick ?c channel
)))
1790 (define-erc-response-handler (352)
1792 (multiple-value-bind (channel user host server nick away-flag
)
1793 (values-list (cdr (erc-response.command-args parsed
)))
1794 (let ((full-name (erc-response.contents parsed
))
1796 (when (string-match "\\(^[0-9]+ \\)\\(.*\\)$" full-name
)
1797 (setq hopcount
(match-string 1 full-name
))
1798 (setq full-name
(match-string 2 full-name
)))
1799 (erc-update-channel-member channel nick nick nil nil nil host
1801 (erc-display-message parsed
'notice
'active
's352
1802 ?c channel ?n nick ?a away-flag
1803 ?u user ?h host ?f full-name
))))
1805 (define-erc-response-handler (353)
1807 (let ((channel (third (erc-response.command-args parsed
)))
1808 (users (erc-response.contents parsed
)))
1809 (erc-display-message parsed
'notice
(or (erc-get-buffer channel proc
)
1811 's353 ?c channel ?u users
)
1812 (erc-with-buffer (channel proc
)
1813 (erc-channel-receive-names users
))))
1815 (define-erc-response-handler (366)
1817 (erc-with-buffer ((second (erc-response.command-args parsed
)) proc
)
1818 (erc-channel-end-receiving-names)))
1820 (define-erc-response-handler (367)
1821 "Channel ban list entries." nil
1822 (multiple-value-bind (channel banmask setter time
)
1823 (values-list (cdr (erc-response.command-args parsed
)))
1824 ;; setter and time are not standard
1826 (erc-display-message parsed
'notice
'active
's367-set-by
1831 (erc-display-message parsed
'notice
'active
's367
1835 (define-erc-response-handler (368)
1836 "End of channel ban list." nil
1837 (let ((channel (second (erc-response.command-args parsed
))))
1838 (erc-display-message parsed
'notice
'active
's368
1841 (define-erc-response-handler (379)
1842 "Forwarding to another channel." nil
1843 ;; FIXME: Yet more magic numbers in original code, I'm guessing this
1844 ;; command takes two arguments, and doesn't have any "contents". --
1845 ;; Lawrence 2004/05/10
1846 (multiple-value-bind (from to
)
1847 (values-list (cdr (erc-response.command-args parsed
)))
1848 (erc-display-message parsed
'notice
'active
1849 's379 ?c from ?f to
)))
1851 (define-erc-response-handler (391)
1852 "Server's time string." nil
1853 (erc-display-message
1854 parsed
'notice
'active
1855 's391 ?s
(second (erc-response.command-args parsed
))
1856 ?t
(third (erc-response.command-args parsed
))))
1858 (define-erc-response-handler (401)
1859 "No such nick/channel." nil
1860 (let ((nick/channel
(second (erc-response.command-args parsed
))))
1861 (when erc-whowas-on-nosuchnick
1862 (erc-log (format "cmd: WHOWAS: %s" nick
/channel
))
1863 (erc-server-send (format "WHOWAS %s 1" nick
/channel
)))
1864 (erc-display-message parsed
'(notice error
) 'active
1865 's401 ?n nick
/channel
)))
1867 (define-erc-response-handler (403)
1868 "No such channel." nil
1869 (erc-display-message parsed
'(notice error
) 'active
1870 's403 ?c
(second (erc-response.command-args parsed
))))
1872 (define-erc-response-handler (404)
1873 "Cannot send to channel." nil
1874 (erc-display-message parsed
'(notice error
) 'active
1875 's404 ?c
(second (erc-response.command-args parsed
))))
1878 (define-erc-response-handler (405)
1879 "Can't join that many channels." nil
1880 (erc-display-message parsed
'(notice error
) 'active
1881 's405 ?c
(second (erc-response.command-args parsed
))))
1883 (define-erc-response-handler (406)
1885 (erc-display-message parsed
'(notice error
) 'active
1886 's406 ?n
(second (erc-response.command-args parsed
))))
1888 (define-erc-response-handler (412)
1889 "No text to send." nil
1890 (erc-display-message parsed
'(notice error
) 'active
's412
))
1892 (define-erc-response-handler (421)
1893 "Unknown command." nil
1894 (erc-display-message parsed
'(notice error
) 'active
's421
1895 ?c
(second (erc-response.command-args parsed
))))
1897 (define-erc-response-handler (432)
1899 (erc-display-message parsed
'(notice error
) 'active
's432
1900 ?n
(second (erc-response.command-args parsed
))))
1902 (define-erc-response-handler (433)
1903 "Login-time \"nick in use\"." nil
1904 (erc-nickname-in-use (second (erc-response.command-args parsed
))
1907 (define-erc-response-handler (437)
1908 "Nick temporarily unavailable (on IRCnet)." nil
1909 (let ((nick/channel
(second (erc-response.command-args parsed
))))
1910 (unless (erc-channel-p nick
/channel
)
1911 (erc-nickname-in-use nick
/channel
"temporarily unavailable"))))
1913 (define-erc-response-handler (442)
1914 "Not on channel." nil
1915 (erc-display-message parsed
'(notice error
) 'active
's442
1916 ?c
(second (erc-response.command-args parsed
))))
1918 (define-erc-response-handler (461)
1919 "Not enough parameters for command." nil
1920 (erc-display-message parsed
'(notice error
) 'active
's461
1921 ?c
(second (erc-response.command-args parsed
))
1922 ?m
(erc-response.contents parsed
)))
1924 (define-erc-response-handler (465)
1925 "You are banned from this server." nil
1926 (setq erc-server-banned t
)
1927 ;; show the server's message, as a reason might be provided
1928 (erc-display-error-notice
1930 (erc-response.contents parsed
)))
1932 (define-erc-response-handler (474)
1933 "Banned from channel errors." nil
1934 (erc-display-message parsed
'(notice error
) nil
1935 (intern (format "s%s"
1936 (erc-response.command parsed
)))
1937 ?c
(second (erc-response.command-args parsed
))))
1939 (define-erc-response-handler (475)
1940 "Channel key needed." nil
1941 (erc-display-message parsed
'(notice error
) nil
's475
1942 ?c
(second (erc-response.command-args parsed
)))
1943 (when erc-prompt-for-channel-key
1944 (let ((channel (second (erc-response.command-args parsed
)))
1945 (key (read-from-minibuffer
1946 (format "Channel %s is mode +k. Enter key (RET to cancel): "
1947 (second (erc-response.command-args parsed
))))))
1948 (when (and key
(> (length key
) 0))
1949 (erc-cmd-JOIN channel key
)))))
1951 (define-erc-response-handler (477)
1952 "Channel doesn't support modes." nil
1953 (let ((channel (second (erc-response.command-args parsed
)))
1954 (message (erc-response.contents parsed
)))
1955 (erc-display-message parsed
'notice
(erc-get-buffer channel proc
)
1956 (format "%s: %s" channel message
))))
1958 (define-erc-response-handler (482)
1959 "You need to be a channel operator to do that." nil
1960 (let ((channel (second (erc-response.command-args parsed
)))
1961 (message (erc-response.contents parsed
)))
1962 (erc-display-message parsed
'(error notice
) 'active
's482
1963 ?c channel ?m message
)))
1965 (define-erc-response-handler (671)
1966 "Secure connection response in WHOIS." nil
1967 (let ((nick (second (erc-response.command-args parsed
)))
1968 (securemsg (erc-response.contents parsed
)))
1969 (erc-display-message parsed
'notice
'active
's671
1970 ?n nick ?a securemsg
)))
1972 (define-erc-response-handler (431 445 446 451 462 463 464 481 483 484 485
1974 ;; 431 - No nickname given
1975 ;; 445 - SUMMON has been disabled
1976 ;; 446 - USERS has been disabled
1977 ;; 451 - You have not registered
1978 ;; 462 - Unauthorized command (already registered)
1979 ;; 463 - Your host isn't among the privileged
1980 ;; 464 - Password incorrect
1981 ;; 481 - Need IRCop privileges
1982 ;; 483 - You can't kill a server!
1983 ;; 484 - Your connection is restricted!
1984 ;; 485 - You're not the original channel operator
1985 ;; 491 - No O-lines for your host
1986 ;; 501 - Unknown MODE flag
1987 ;; 502 - Cannot change mode for other users
1988 "Generic display of server error messages.
1990 See `erc-display-error-notice'." nil
1991 (erc-display-error-notice
1993 (intern (format "s%s" (erc-response.command parsed
)))))
1995 ;; FIXME: These are yet to be implemented, they're just stubs for now
1996 ;; -- Lawrence 2004/05/12
1998 ;; response numbers left here for reference
2000 ;; (define-erc-response-handler (323 364 365 381 382 392 393 394 395
2001 ;; 200 201 202 203 204 205 206 208 209 211 212 213
2002 ;; 214 215 216 217 218 219 241 242 243 244 249 261
2003 ;; 262 302 342 351 402 407 409 411 413 414 415
2004 ;; 423 424 436 441 443 444 467 471 472 473 KILL)
2006 ;; (ignore proc parsed))
2008 (provide 'erc-backend
)
2010 ;;; erc-backend.el ends here
2012 ;; indent-tabs-mode: nil