;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Code:
(require 'riece-message)
(require 'riece-channel)
(require 'riece-naming)
-(require 'riece-display)
+(require 'riece-signal)
+(require 'riece-mode)
+(require 'riece-000)
+(require 'riece-200)
+(require 'riece-300)
+(require 'riece-400)
+(require 'riece-500)
+
+(defun riece-default-handle-numeric-reply
+ (client-prefix prefix number name string)
+ (riece-insert
+ (list riece-dialogue-buffer riece-others-buffer)
+ (concat client-prefix
+ (riece-concat-server-name
+ (mapconcat #'identity (riece-split-parameters string) " "))
+ "\n")))
(defun riece-handle-nick-message (prefix string)
(let* ((old (riece-prefix-nickname prefix))
(riece-make-identity channel riece-server-name))
channels))))
(riece-naming-assert-rename old new)
- (let ((pointer (riece-identity-member old-identity
- riece-current-channels)))
- (when pointer
- (setcar pointer new-identity)
- (with-current-buffer (riece-channel-buffer-name new-identity)
- (rename-buffer (riece-channel-buffer-name new-identity)))
- (if (riece-identity-equal new-identity riece-current-channel)
- (riece-switch-to-channel new-identity))
- (setq channels (cons new-identity channels))))
- (riece-insert-change (mapcar
- (lambda (channel)
- (riece-channel-buffer-name
- (riece-make-identity channel riece-server-name)))
- channels)
+ (if (riece-identity-member old-identity riece-current-channels)
+ (setq channels (cons new channels)))
+ (riece-insert-change (delq nil (mapcar
+ (lambda (channel)
+ (riece-channel-buffer
+ (riece-make-identity
+ channel riece-server-name)))
+ channels))
(format "%s -> %s\n"
(riece-format-identity old-identity t)
(riece-format-identity new-identity t)))
(format "%s -> %s"
(riece-format-identity old-identity t)
(riece-format-identity new-identity t)))
- "\n"))
- (riece-redisplay-buffers)))
+ "\n"))))
-(defun riece-handle-privmsg-message (prefix string)
+(defun riece-handle-privmsg-message (prefix decoded)
(let* ((user (riece-prefix-nickname prefix))
- (parameters (riece-split-parameters string))
+ (parameters (riece-split-parameters (riece-decoded-string decoded)))
(targets (split-string (car parameters) ","))
- (message (nth 1 parameters)))
+ message)
+ (setq parameters (riece-split-parameters
+ (riece-decoded-string-for-identity
+ decoded
+ (riece-make-identity (car targets) riece-server-name)))
+ message (nth 1 parameters))
(riece-display-message
(riece-make-message (riece-make-identity user
riece-server-name)
(riece-make-identity (car targets)
riece-server-name)
- message))))
+ message
+ nil
+ (riece-identity-equal-no-server
+ user riece-real-nickname)))))
-(defun riece-handle-notice-message (prefix string)
+(defun riece-handle-notice-message (prefix decoded)
(let* ((user (if prefix
(riece-prefix-nickname prefix)))
- (parameters (riece-split-parameters string))
+ (parameters (riece-split-parameters (riece-decoded-string decoded)))
(targets (split-string (car parameters) ","))
- (message (nth 1 parameters)))
+ message)
+ (setq parameters (riece-split-parameters
+ (riece-decoded-string-for-identity
+ decoded
+ (riece-make-identity (car targets) riece-server-name)))
+ message (nth 1 parameters))
(if user
(riece-display-message
(riece-make-message (riece-make-identity user
riece-server-name)
(riece-make-identity (car targets)
riece-server-name)
- message 'notice))
+ message 'notice
+ (if riece-real-nickname
+ (riece-identity-equal-no-server
+ user riece-real-nickname))))
;; message from server
(riece-insert-notice
(list riece-dialogue-buffer riece-others-buffer)
(user-identity (riece-make-identity user riece-server-name)))
(while channels
(riece-naming-assert-join user (car channels))
+ (if (and riece-gather-channel-modes
+ (riece-identity-equal-no-server user riece-real-nickname))
+ (riece-send-string (format "MODE %s\r\n" (car channels))))
(let* ((channel-identity (riece-make-identity (car channels)
riece-server-name))
- (buffer (get-buffer (riece-channel-buffer-name
- channel-identity))))
+ (buffer (riece-channel-buffer channel-identity)))
(riece-insert-change
buffer
- (format "%s (%s) has joined %s\n"
+ (format (riece-mcat "%s (%s) has joined %s\n")
(riece-format-identity user-identity t)
(riece-user-get-user-at-host user)
(riece-format-identity channel-identity t)))
riece-dialogue-buffer)
(concat
(riece-concat-server-name
- (format "%s (%s) has joined %s"
+ (format (riece-mcat "%s (%s) has joined %s")
(riece-format-identity user-identity t)
(riece-user-get-user-at-host user)
(riece-format-identity channel-identity t)))
"\n")))
- (setq channels (cdr channels)))
- (riece-redisplay-buffers)))
+ (setq channels (cdr channels)))))
-(defun riece-handle-part-message (prefix string)
+(defun riece-handle-part-message (prefix decoded)
(let* ((user (riece-prefix-nickname prefix))
- (parameters (riece-split-parameters string))
+ (parameters (riece-split-parameters (riece-decoded-string decoded)))
;; RFC2812 3.2.2 doesn't recommend server to send part
;; messages which contain multiple targets.
(channels (split-string (car parameters) ","))
- (message (nth 1 parameters))
(user-identity (riece-make-identity user riece-server-name)))
(while channels
- (riece-naming-assert-part user (car channels))
(let* ((channel-identity (riece-make-identity (car channels)
riece-server-name))
- (buffer (get-buffer (riece-channel-buffer-name
- channel-identity))))
+ (buffer (riece-channel-buffer channel-identity))
+ message)
+ (setq parameters (riece-split-parameters
+ (riece-decoded-string-for-identity decoded
+ channel-identity))
+ message (nth 1 parameters))
(riece-insert-change
buffer
(concat
(riece-concat-message
- (format "%s has left %s"
+ (format (riece-mcat "%s has left %s")
(riece-format-identity user-identity t)
(riece-format-identity channel-identity t))
message)
(concat
(riece-concat-server-name
(riece-concat-message
- (format "%s has left %s"
+ (format (riece-mcat "%s has left %s")
(riece-format-identity user-identity t)
(riece-format-identity channel-identity t))
message))
"\n")))
- (setq channels (cdr channels)))
- (riece-redisplay-buffers)))
+ (riece-naming-assert-part user (car channels))
+ (setq channels (cdr channels)))))
-(defun riece-handle-kick-message (prefix string)
+(defun riece-handle-kick-message (prefix decoded)
(let* ((kicker (riece-prefix-nickname prefix))
- (parameters (riece-split-parameters string))
+ (parameters (riece-split-parameters (riece-decoded-string decoded)))
(channel (car parameters))
(user (nth 1 parameters))
- (message (nth 2 parameters))
+ message
(kicker-identity (riece-make-identity kicker riece-server-name))
(channel-identity (riece-make-identity channel riece-server-name))
(user-identity (riece-make-identity user riece-server-name)))
+ (setq parameters (riece-split-parameters
+ (riece-decoded-string-for-identity decoded
+ channel-identity))
+ message (nth 2 parameters))
(riece-naming-assert-part user channel)
- (let ((buffer (get-buffer (riece-channel-buffer-name channel-identity))))
+ (let ((buffer (riece-channel-buffer channel-identity)))
(riece-insert-change
buffer
(concat
(riece-concat-message
- (format "%s kicked %s out from %s"
+ (format (riece-mcat "%s kicked %s out from %s")
(riece-format-identity kicker-identity t)
(riece-format-identity user-identity t)
(riece-format-identity channel-identity t))
(concat
(riece-concat-server-name
(riece-concat-message
- (format "%s kicked %s out from %s\n"
+ (format (riece-mcat "%s kicked %s out from %s\n")
(riece-format-identity kicker-identity t)
(riece-format-identity user-identity t)
(riece-format-identity channel-identity t))
message))
- "\n")))
- (riece-redisplay-buffers)))
+ "\n")))))
(defun riece-handle-quit-message (prefix string)
(let* ((user (riece-prefix-nickname prefix))
(user-identity (riece-make-identity user riece-server-name)))
;; If you are talking with the user, quit it.
(if (riece-identity-member user-identity riece-current-channels)
- (riece-part-channel user))
+ (riece-part-channel user-identity))
(setq pointer channels)
(while pointer
(riece-naming-assert-part user (car pointer))
(setq pointer (cdr pointer)))
(let ((buffers
- (mapcar
- (lambda (channel)
- (get-buffer
- (riece-channel-buffer-name
- (riece-make-identity channel riece-server-name))))
- channels)))
+ (delq nil (mapcar
+ (lambda (channel)
+ (riece-channel-buffer (riece-make-identity
+ channel riece-server-name)))
+ channels))))
(riece-insert-change
buffers
(concat
(riece-concat-message
- (format "%s has left IRC"
+ (format (riece-mcat "%s has left IRC")
(riece-format-identity user-identity t))
message)
"\n"))
(concat
(riece-concat-server-name
(riece-concat-message
- (format "%s has left IRC"
+ (format (riece-mcat "%s has left IRC")
(riece-format-identity user-identity t))
message))
- "\n"))))
- (riece-redisplay-buffers))
+ "\n")))))
(defun riece-handle-kill-message (prefix string)
(let* ((killer (riece-prefix-nickname prefix))
(riece-naming-assert-part user (car pointer))
(setq pointer (cdr pointer)))
(let ((buffers
- (mapcar
- (lambda (channel)
- (get-buffer
- (riece-channel-buffer-name
- (riece-make-identity channel riece-server-name))))
- channels)))
+ (delq nil (mapcar
+ (lambda (channel)
+ (riece-channel-buffer (riece-make-identity
+ channel riece-server-name)))
+ channels))))
(riece-insert-change
buffers
(concat
(riece-concat-message
- (format "%s killed %s"
+ (format (riece-mcat "%s killed %s")
(riece-format-identity killer-identity t)
(riece-format-identity user-identity t))
message)
(concat
(riece-concat-server-name
(riece-concat-message
- (format "%s killed %s"
+ (format (riece-mcat "%s killed %s")
(riece-format-identity killer-identity t)
(riece-format-identity user-identity t))
message))
- "\n")))
- (riece-redisplay-buffers)))
+ "\n")))))
(defun riece-handle-invite-message (prefix string)
(let* ((user (riece-prefix-nickname prefix))
(parameters (riece-split-parameters string))
(invited (car parameters))
- (channel (nth 1 parameters)))
+ (channel (nth 1 parameters))
+ (channel-identity (riece-make-identity channel riece-server-name)))
+ (if (riece-identity-equal-no-server invited riece-real-nickname)
+ (setq riece-join-channel-candidate channel-identity))
(riece-insert-info
(list riece-dialogue-buffer riece-others-buffer)
(concat
(riece-concat-server-name
- (format "%s invites %s to %s"
+ (format (riece-mcat "%s invites %s to %s")
(riece-format-identity (riece-make-identity
user riece-server-name))
(riece-format-identity (riece-make-identity
invited riece-server-name))
- (riece-format-identity (riece-make-identity
- channel riece-server-name))))
+ (riece-format-identity channel-identity)))
"\n"))))
-(defun riece-handle-topic-message (prefix string)
+(defun riece-handle-topic-message (prefix decoded)
(let* ((user (riece-prefix-nickname prefix))
- (parameters (riece-split-parameters string))
+ (parameters (riece-split-parameters (riece-decoded-string decoded)))
(channel (car parameters))
- (topic (nth 1 parameters))
+ topic
(user-identity (riece-make-identity user riece-server-name))
(channel-identity (riece-make-identity channel riece-server-name)))
+ (setq parameters (riece-split-parameters
+ (riece-decoded-string-for-identity decoded
+ channel-identity))
+ topic (nth 1 parameters))
(riece-channel-set-topic (riece-get-channel channel) topic)
- (let ((buffer (get-buffer (riece-channel-buffer-name channel-identity))))
+ (riece-emit-signal 'channel-topic-changed
+ channel-identity topic)
+ (let ((buffer (riece-channel-buffer channel-identity)))
(riece-insert-change
buffer
- (format "Topic by %s: %s\n"
+ (format (riece-mcat "Topic by %s: %s\n")
(riece-format-identity user-identity t)
topic))
(riece-insert-change
riece-dialogue-buffer)
(concat
(riece-concat-server-name
- (format "Topic on %s by %s: %s"
+ (format (riece-mcat "Topic on %s by %s: %s")
(riece-format-identity channel-identity t)
(riece-format-identity user-identity t)
topic))
- "\n"))
- (riece-redisplay-buffers))))
-
-(defsubst riece-parse-channel-modes (string channel)
- (while (string-match "^[-+]\\([^ ]*\\) *" string)
- (let ((toggle (aref string 0))
- (modes (string-to-list (match-string 1 string))))
- (setq string (substring string (match-end 0)))
- (while modes
- (if (and (memq (car modes) '(?O ?o ?v ?k ?l ?b ?e ?I))
- (string-match "\\([^-+][^ ]*\\) *" string))
- (let ((parameter (match-string 1 string)))
- (setq string (substring string (match-end 0)))
- (cond
- ((eq (car modes) ?o)
- (riece-channel-toggle-operator channel parameter
- (eq toggle ?+)))
- ((eq (car modes) ?v)
- (riece-channel-toggle-speaker channel parameter
- (eq toggle ?+)))
- ((eq (car modes) ?b)
- (riece-channel-toggle-banned channel parameter
- (eq toggle ?+)))
- ((eq (car modes) ?e)
- (riece-channel-toggle-uninvited channel parameter
- (eq toggle ?+)))
- ((eq (car modes) ?I)
- (riece-channel-toggle-invited channel parameter
- (eq toggle ?+)))))
- (riece-channel-toggle-mode channel (car modes)
- (eq toggle ?+)))
- (setq modes (cdr modes))))))
+ "\n")))))
(defun riece-handle-mode-message (prefix string)
(let* ((user (riece-prefix-nickname prefix))
(user-identity (riece-make-identity user riece-server-name))
channel)
- (when (string-match "\\([^ ]+\\) *:?" string)
+ (when (string-match "^\\([^ ]+\\) *:?" string)
(setq channel (match-string 1 string)
string (substring string (match-end 0)))
- (riece-parse-channel-modes string channel)
+ (if (string-match (concat "^" riece-channel-regexp "$") channel)
+ (riece-naming-assert-channel-modes channel
+ (riece-parse-modes string)))
(let* ((channel-identity (riece-make-identity channel riece-server-name))
- (buffer (get-buffer (riece-channel-buffer-name
- channel-identity))))
+ (buffer (riece-channel-buffer channel-identity)))
(riece-insert-change
buffer
- (format "Mode by %s: %s\n"
+ (format (riece-mcat "Mode by %s: %s\n")
(riece-format-identity user-identity t)
string))
(riece-insert-change
riece-dialogue-buffer)
(concat
(riece-concat-server-name
- (format "Mode on %s by %s: %s"
+ (format (riece-mcat "Mode on %s by %s: %s")
(riece-format-identity channel-identity t)
(riece-format-identity user-identity t)
string))
- "\n"))
- (riece-redisplay-buffers)))))
+ "\n"))))))
(provide 'riece-handle)