1 ;;; riece-300.el --- handlers for 300 replies
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
28 (require 'riece-commands)
30 (require 'riece-filter) ;riece-default-handle-message
33 (autoload 'riece-default-handle-numeric-reply "riece-filter"))
34 (defun riece-handle-default-300-message (prefix number name string)
35 (riece-default-handle-numeric-reply
36 riece-info-prefix prefix number name string))
38 (defun riece-handle-302-message (prefix number name string)
39 "RPL_USERHOST \":*1<reply> *( \" \" <reply> )\""
40 (let ((replies (split-string (substring string 1) " ")))
43 (concat "^\\(" riece-user-regexp
44 "\\)\\(\\*\\)?=\\([-+]\\)\\([^ ]+\\)")
46 (let ((user (match-string 1 (car replies)))
47 (away (eq (match-string 3 (car replies)) ?-))
48 (user-at-host (match-string 4 (car replies)))
49 (operator (not (null (match-beginning 2)))))
50 (riece-user-toggle-away user away)
51 (riece-user-toggle-operator user operator)
53 (list riece-dialogue-buffer riece-others-buffer)
55 (riece-concat-server-name
56 (format "%s is (%s) [%s, %s]"
57 (riece-format-identity
58 (riece-make-identity user riece-server-name)
60 (riece-strip-user-at-host user-at-host)
68 (setq replies (cdr replies)))
69 (riece-update-status-indicators)
70 (force-mode-line-update t)))
72 (defun riece-handle-303-message (prefix number name string)
74 (list riece-dialogue-buffer riece-others-buffer)
76 (riece-concat-server-name
80 (riece-format-identity
81 (riece-make-identity user riece-server-name)
83 (split-string (substring string 1) " ")
87 (defun riece-handle-301-message (prefix number name string)
88 (if (string-match (concat "^\\(" riece-user-regexp "\\) :") string)
89 (let ((user (match-string 1 string))
90 (message (substring string (match-end 0))))
91 (riece-user-toggle-away user t)
93 (list riece-dialogue-buffer riece-others-buffer)
95 (riece-concat-server-name
96 (format "%s is away: %s"
97 (riece-format-identity
98 (riece-make-identity user riece-server-name)
102 (riece-update-status-indicators)
103 (force-mode-line-update t))
105 (defun riece-handle-305-message (prefix number name string)
106 (riece-user-toggle-away riece-real-nickname nil)
107 (riece-update-status-indicators)
108 (force-mode-line-update t))
110 (defun riece-handle-306-message (prefix number name string)
111 (riece-user-toggle-away riece-real-nickname t)
112 (riece-update-status-indicators)
113 (force-mode-line-update t))
115 (defun riece-handle-311-message (prefix number name string)
117 (concat "^\\(" riece-user-regexp
118 "\\) \\([^ ]+\\) \\([^ ]+\\) \\* :")
120 (let ((user (match-string 1 string))
121 (name (substring string (match-end 0)))
122 (user-at-host (concat (match-string 2 string) "@"
123 (match-string 3 string))))
125 (list riece-dialogue-buffer riece-others-buffer)
127 (riece-concat-server-name
128 (format "%s is %s (%s)"
129 (riece-format-identity
130 (riece-make-identity user riece-server-name)
136 (defun riece-handle-312-message (prefix number name string)
138 (concat "^\\(" riece-user-regexp "\\) \\([^ ]+\\) :")
141 (list riece-dialogue-buffer riece-others-buffer)
143 (riece-concat-server-name
144 (format "on via server %s: %s"
145 riece-real-server-name
146 (substring string (match-end 0))))
149 (defun riece-handle-313-message (prefix number name string)
150 (if (string-match (concat "^" riece-user-regexp) string)
151 (let ((user (match-string 0 string)))
153 (list riece-dialogue-buffer riece-others-buffer)
155 (riece-concat-server-name
156 (concat (riece-format-identity
157 (riece-make-identity user riece-server-name)
159 " is an IRC operator"))
162 (defun riece-handle-317-message (prefix number name string)
164 (concat "^\\(" riece-user-regexp "\\) \\([0-9]+\\) :")
166 (let ((user (match-string 1 string))
167 (idle (match-string 2 string)))
169 (list riece-dialogue-buffer riece-others-buffer)
171 (riece-concat-server-name
172 (format "%s is %s seconds idle"
173 (riece-format-identity
174 (riece-make-identity user riece-server-name)
179 (defun riece-handle-351-message (prefix number name string)
180 (if (string-match "\\([^ ]+\\.[^ ]+\\) \\([^ ]+\\) :" string)
182 (list riece-dialogue-buffer riece-others-buffer)
184 (riece-concat-server-name
185 (format "%s is running on %s: %s"
186 (match-string 1 string)
187 (match-string 2 string)
188 (substring string (match-end 0))))
191 (defun riece-handle-353-message (prefix number name string)
192 "RPL_NAMREPLY \"<channel> :[[@|+]<nick> [[@|+]<nick> [...]]]\"."
193 (if (string-match "^[=\*@] *\\([^ ]+\\) +:" string)
194 (let ((channel (match-string 1 string))
196 (setq string (substring string (match-end 0)))
197 (if (string-match " *$" string)
198 (setq string (substring string 0 (match-beginning 0))))
199 (setq users (split-string string))
201 (if (eq (aref (car users) 0) ?@)
203 (riece-naming-assert-join (substring (car users) 1) channel)
204 (riece-channel-toggle-operator
205 channel (substring (car users) 1) t))
206 (if (eq (aref (car users) 0) ?+)
208 (riece-naming-assert-join (substring (car users) 1) channel)
209 (riece-channel-toggle-speaker
210 channel (substring (car users) 1) t))
211 (riece-naming-assert-join (car users) channel)))
212 (setq users (cdr users)))
213 (riece-redisplay-buffers))))
215 (defun riece-handle-322-message (prefix number name string)
216 (if (string-match "^\\([^ ]+\\) \\([0-9]+\\) :" string)
217 (let* ((channel (match-string 1 string))
218 (visible (match-string 2 string))
219 (topic (substring string (match-end 0))))
220 (riece-channel-set-topic (riece-get-channel channel) topic)
221 (let* ((channel-identity (riece-make-identity channel
223 (buffer (riece-channel-buffer-name channel-identity)))
224 (riece-insert-info buffer (concat visible " users, topic: "
227 (if (and riece-channel-buffer-mode
228 (not (eq buffer riece-channel-buffer)))
229 (list riece-dialogue-buffer riece-others-buffer)
230 riece-dialogue-buffer)
232 (riece-concat-server-name
233 (format "%s users on %s, topic: %s" visible
234 (riece-format-identity channel-identity t) topic))
237 (defun riece-handle-324-message (prefix number name string)
238 (if (string-match "^\\([^ ]+\\) \\([^ ]+\\) " string)
239 (let* ((channel (match-string 1 string))
240 (mode-string (substring string (match-beginning 2)))
241 (modes (string-to-list (match-string 2 string)))
242 (toggle (car modes)))
243 (setq modes (cdr modes))
245 (riece-channel-toggle-mode channel (car modes) (eq toggle ?+))
246 (setq modes (cdr modes)))
247 (let* ((channel-identity (riece-make-identity channel
249 (buffer (riece-channel-buffer-name channel-identity)))
250 (riece-insert-info buffer (concat "Mode: " mode-string "\n"))
252 (if (and riece-channel-buffer-mode
253 (not (eq buffer riece-channel-buffer)))
254 (list riece-dialogue-buffer riece-others-buffer)
255 riece-dialogue-buffer)
257 (riece-concat-server-name
258 (format "Mode for %s: %s"
259 (riece-format-identity channel-identity t)
262 (riece-update-channel-indicator)
263 (force-mode-line-update t))))
265 (defun riece-handle-set-topic (prefix number name string remove)
266 (if (string-match "^\\([^ ]+\\) :" string)
267 (let* ((channel (match-string 1 string))
268 (message (substring string (match-end 0)))
269 (channel-identity (riece-make-identity channel riece-server-name))
270 (buffer (riece-channel-buffer-name channel-identity)))
272 (riece-channel-set-topic (riece-get-channel channel) nil)
273 (riece-channel-set-topic (riece-get-channel channel) message)
274 (riece-insert-info buffer (concat "Topic: " message "\n"))
276 (if (and riece-channel-buffer-mode
277 (not (eq buffer riece-channel-buffer)))
278 (list riece-dialogue-buffer riece-others-buffer)
279 riece-dialogue-buffer)
281 (riece-concat-server-name
282 (format "Topic for %s: %s"
283 (riece-format-identity channel-identity t)
286 (riece-update-channel-indicator)))))
288 (defun riece-handle-331-message (prefix number name string)
289 (riece-handle-set-topic prefix number name string t))
291 (defun riece-handle-332-message (prefix number name string)
292 (riece-handle-set-topic prefix number name string nil))
294 (defun riece-handle-341-message (prefix number name string)
295 (if (string-match "^\\([^ ]+\\) " string)
296 (let* ((channel (match-string 1 string))
297 (user (substring string (match-end 0)))
298 (channel-identity (riece-make-identity channel riece-server-name))
299 (buffer (riece-channel-buffer-name channel-identity)))
300 (riece-insert-info buffer (concat "Inviting " user "\n"))
302 (if (and riece-channel-buffer-mode
303 (not (eq buffer riece-channel-buffer)))
304 (list riece-dialogue-buffer riece-others-buffer)
305 riece-dialogue-buffer)
307 (riece-concat-server-name
308 (format "Inviting %s to %s" user
309 (riece-format-identity channel-identity t)))
312 (defun riece-handle-352-message (prefix number name string)
313 (if (string-match "^\\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\) \\([HG]\\)\\(\\*\\)?\\([@+]\\)? :\\([0-9]+\\) " string)
314 (let* ((channel (match-string 1 string))
315 (user (match-string 2 string))
316 (host (match-string 3 string))
317 (server (match-string 4 string))
318 (nick (match-string 5 string))
319 (away (equal (match-string 6 string) "G"))
320 (operator (not (null (match-beginning 7))))
321 (flag (match-string 8 string))
322 (hops (match-string 9 string))
323 (name (substring string (match-end 0)))
324 (buffer (riece-channel-buffer-name
325 (riece-make-identity channel riece-server-name)))
326 (info (format "%10s = %s (%s) [%s, %s, %s hops, on %s]"
328 (if (memq flag '(?@ ?+))
329 (char-to-string flag)
331 (riece-format-identity
332 (riece-make-identity nick riece-server-name)
335 (riece-strip-user-at-host
336 (concat user "@" host))
345 (riece-naming-assert-join nick channel)
346 (riece-user-toggle-away user away)
347 (riece-user-toggle-operator user operator)
348 (riece-insert-info buffer (concat info "\n"))
350 (if (and riece-channel-buffer-mode
351 (not (eq buffer riece-channel-buffer)))
352 (list riece-dialogue-buffer riece-others-buffer)
353 riece-dialogue-buffer)
355 (riece-concat-server-name
357 (riece-format-identity
358 (riece-make-identity channel riece-server-name)
363 (riece-redisplay-buffers))))
365 (defun riece-handle-315-message (prefix number name string))
366 (defun riece-handle-318-message (prefix number name string))
367 (defun riece-handle-323-message (prefix number name string))
368 (defun riece-handle-366-message (prefix number name string))
372 ;;; riece-300.el ends here