63863752dff430a95b8d7186b6e66c9b645cc24c
[elisp/riece.git] / lisp / riece-400.el
1 ;;; riece-400.el --- handlers for 400 replies
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
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)
13 ;; any later version.
14
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.
19
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Code:
26
27 (require 'riece-globals)
28 (require 'riece-misc)
29 (require 'riece-mcat)
30
31 (eval-when-compile
32   (autoload 'riece-default-handle-numeric-reply "riece-handle"))
33 (defun riece-handle-default-400-message (prefix number name string)
34   (riece-default-handle-numeric-reply
35    riece-error-prefix prefix number name string))
36
37 (defun riece-handle-read-string (prompt)
38   (condition-case nil
39       (let (inhibit-quit)
40         (read-string prompt))
41     (quit
42      (ignore (message "%s" (concat prompt "Quit"))))))
43
44 (defun riece-handle-432-message (prefix number name string)
45   "ERR_ERRONEUSNICKNAME \"<nick> :Erroneous nickname\"."
46   (let ((nickname
47          (riece-handle-read-string
48           (format (riece-mcat "Erroneous nickname \"%s\".  Choose a new one: ")
49                   (car (riece-split-parameters string))))))
50     (if nickname
51         (riece-send-string (format "NICK %s\r\n" nickname)))))
52
53 (defun riece-handle-433-message (prefix number name string)
54   "ERR_NICKNAMEINUSE \"<nick> :Nickname is already in use\"."
55   (let ((nickname
56          (riece-handle-read-string
57           (format (riece-mcat "Nickname \"%s\" already in use.  Choose a new one: ")
58                   (car (riece-split-parameters string))))))
59     (if nickname
60         (riece-send-string (format "NICK %s\r\n" nickname)))))
61
62 (defun riece-handle-464-message (prefix number name string)
63   "ERR_PASSWDMISMATCH \":Password incorrect\"."
64   (message (riece-mcat "Password incorrect from %s.") prefix)
65   (setq riece-reconnect-with-password t))
66
67 (defun riece-handle-475-message (prefix number name string)
68   "ERR_BADCHANNELKEY \"<channel> :Cannot join channel (+k)\"."
69   (let* ((parameters (riece-split-parameters string))
70          (channel-identity (riece-make-identity (car parameters)
71                                                 riece-server-name))
72          key)
73     (setq key
74           (condition-case nil
75               (let (inhibit-quit)
76                 (riece-read-passwd
77                  (format (riece-mcat "Key for %s: ")
78                          (riece-format-identity channel-identity t))))
79             (quit
80              (message (riece-mcat "Key for %s: Quit")
81                       (riece-format-identity channel-identity t))
82              'quit)))
83     (unless (eq key 'quit)
84       (riece-command-join-channel channel-identity key))))
85
86 (provide 'riece-400)
87
88 ;;; riece-400.el ends here