Fixed.
[riece] / lisp / riece-300.el
index 6a92ac5..8510941 100644 (file)
@@ -25,6 +25,9 @@
 ;;; Code:
 
 (require 'riece-misc)
+(require 'riece-naming)
+(require 'riece-signal)
+(require 'riece-display)
 
 (eval-when-compile
   (autoload 'riece-default-handle-numeric-reply "riece-handle"))
@@ -40,8 +43,7 @@
                               " ")))
     (while replies
       (if (string-match
-          (concat "^\\(" riece-user-regexp
-                  "\\)\\(\\*\\)?=\\([-+]\\)\\([^ ]+\\)")
+          (concat "^\\([^ ]+\\)\\(\\*\\)?=\\([-+]\\)\\([^ ]+\\)")
           (car replies))
          (let ((user (match-string 1 (car replies)))
                (operator (not (null (match-beginning 2))))
@@ -93,7 +95,7 @@
     "\n")))
 
 (defun riece-handle-301-message (prefix number name string)
-  (if (string-match (concat "^\\(" riece-user-regexp "\\) :?") string)
+  (if (string-match (concat "^\\([^ ]+\\) :?") string)
       (let ((user (match-string 1 string))
            (message (substring string (match-end 0))))
        (riece-user-toggle-away user t)
 
 (defun riece-handle-311-message (prefix number name string)
   (if (string-match
-       (concat "^\\(" riece-user-regexp
-              "\\) \\([^ ]+\\) \\([^ ]+\\) \\* :?")
+       (concat "^\\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\) \\* :?")
        string)
       (let ((user (match-string 1 string))
            (name (substring string (match-end 0)))
 
 (defun riece-handle-312-message (prefix number name string)
   (if (string-match
-       (concat "^\\(" riece-user-regexp "\\) \\([^ ]+\\) :?")
+       (concat "^\\([^ ]+\\) \\([^ ]+\\) :?")
        string)
       (riece-insert-info
        (list riece-dialogue-buffer riece-others-buffer)
        "\n"))))
 
 (defun riece-handle-313-message (prefix number name string)
-  (if (string-match (concat "^" riece-user-regexp) string)
+  (if (string-match "^[^ ]+" string)
       (let ((user (match-string 0 string)))
        (riece-insert-info
         (list riece-dialogue-buffer riece-others-buffer)
 
 (defun riece-handle-317-message (prefix number name string)
   (if (string-match
-       (concat "^\\(" riece-user-regexp "\\) \\([0-9]+\\) ")
+       (concat "^\\([^ ]+\\) \\([0-9]+\\) ")
        string)
-      (let ((user (match-string 1 string))
-           (idle (match-string 2 string)))
+      (let* ((user (match-string 1 string))
+            (seconds (string-to-number (match-string 2 string)))
+            (units (list (cons (/ seconds 60 60 24) "days")
+                         (cons (mod (/ seconds 60 60) 24) "hours")
+                         (cons (mod (/ seconds 60) 60) "minutes")
+                         (cons (mod seconds 60) "seconds"))))
        (riece-insert-info
         (list riece-dialogue-buffer riece-others-buffer)
         (concat
          (riece-concat-server-name
-          (format "%s is %s seconds idle"
+          (format "%s is %s idle"
                   (riece-format-identity
                    (riece-make-identity user riece-server-name)
                    t)
-                  idle))
+                  (mapconcat #'identity
+                             (delq nil
+                                   (mapcar
+                                    (lambda (unit)
+                                      (if (/= (car unit) 0)
+                                          (format "%d %s"
+                                                  (car unit) (cdr unit))))
+                                    units))
+                             " ")))
          "\n")))))
 
 (defun riece-handle-319-message (prefix number name string)
-  (if (string-match (concat "^\\(" riece-user-regexp "\\) :?") string)
+  (if (string-match (concat "^\\([^ ]+\\) :?") string)
       (let ((user (match-string 1 string))
            (channels
             (mapconcat
   (make-local-variable 'riece-353-message-alist)      
   (if (string-match "^[=\*@] *\\([^ ]+\\) +:?" string)
       (let* ((channel (match-string 1 string))
-            (entry (assoc channel riece-353-message-alist)))
+            (entry (riece-identity-assoc channel riece-353-message-alist t)))
        (if entry
            (setcdr entry
                    (concat (cdr entry)
                (cons (cons channel (substring string (match-end 0)))
                      riece-353-message-alist))))))
 
-(defun riece-handle-322-message (prefix number name string)
-  (if (string-match "^\\([^ ]+\\) \\([0-9]+\\) :?" string)
-      (let* ((channel (match-string 1 string))
-            (visible (match-string 2 string))
-            (topic (substring string (match-end 0))))
-       (riece-channel-set-topic (riece-get-channel channel) topic)
-       (let* ((channel-identity (riece-make-identity channel
-                                                     riece-server-name))
-              (buffer (riece-channel-buffer channel-identity)))
-         (riece-insert-info buffer (concat visible " users, topic: "
-                                           topic "\n"))
-         (riece-insert-info
-          (if (and riece-channel-buffer-mode
-                   (not (eq buffer riece-channel-buffer)))
-              (list riece-dialogue-buffer riece-others-buffer)
-            riece-dialogue-buffer)
-          (concat
-           (riece-concat-server-name
-            (format "%s: %s users, topic: %s"
-                    (riece-format-identity channel-identity t) visible topic))
-           "\n"))))))
+(defun riece-handle-322-message (prefix number name decoded)
+  (let* ((parameters (riece-split-parameters (riece-decoded-string decoded)))
+        (channel (car parameters))
+        (visible (nth 1 parameters))
+        (channel-identity (riece-make-identity channel riece-server-name))
+        (buffer (riece-channel-buffer channel-identity))
+        topic)
+    (setq parameters (riece-split-parameters
+                     (riece-decoded-string-for-identity decoded
+                                                        channel-identity))
+         topic (nth 2 parameters))
+    (riece-channel-set-topic (riece-get-channel channel) topic)
+    (riece-insert-info buffer (concat visible " users, topic: " topic "\n"))
+    (riece-insert-info
+     (if (and riece-channel-buffer-mode
+             (not (eq buffer riece-channel-buffer)))
+        (list riece-dialogue-buffer riece-others-buffer)
+       riece-dialogue-buffer)
+     (concat
+      (riece-concat-server-name
+       (format "%s: %s users, topic: %s"
+              (riece-format-identity channel-identity t) visible topic))
+      "\n"))))
 
 (defun riece-handle-324-message (prefix number name string)
   (if (string-match "^\\([^ ]+\\) \\([^ ]+\\) " string)
                     mode-string))
            "\n"))))))
 
-(defun riece-handle-set-topic (prefix number name string remove)
-  (if (string-match "^\\([^ ]+\\) :?" string)
-      (let* ((channel (match-string 1 string))
-            (message (substring string (match-end 0)))
-            (channel-identity (riece-make-identity channel riece-server-name))
-            (buffer (riece-channel-buffer channel-identity)))
-       (if remove
-           (riece-channel-set-topic (riece-get-channel channel) nil)
-         (riece-channel-set-topic (riece-get-channel channel) message)
-         (riece-insert-info buffer (concat "Topic: " message "\n"))
-         (riece-insert-info
-          (if (and riece-channel-buffer-mode
-                   (not (eq buffer riece-channel-buffer)))
-              (list riece-dialogue-buffer riece-others-buffer)
-            riece-dialogue-buffer)
-          (concat
-           (riece-concat-server-name
-            (format "Topic for %s: %s"
-                    (riece-format-identity channel-identity t)
-                    message))
-           "\n")))
-       (riece-emit-signal 'channel-topic-changed
-                           channel-identity
-                           (unless remove
-                             message)))))
+(defun riece-handle-set-topic (prefix number name decoded remove)
+  (let* ((parameters (riece-split-parameters (riece-decoded-string decoded)))
+        (channel (car parameters))
+        topic
+        (channel-identity (riece-make-identity channel riece-server-name))
+        (buffer (riece-channel-buffer channel-identity)))
+    (if remove
+       (riece-channel-set-topic (riece-get-channel channel) nil)
+      (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)
+      (riece-insert-info buffer (concat "Topic: " topic "\n"))
+      (riece-insert-info
+       (if (and riece-channel-buffer-mode
+               (not (eq buffer riece-channel-buffer)))
+          (list riece-dialogue-buffer riece-others-buffer)
+        riece-dialogue-buffer)
+       (concat
+       (riece-concat-server-name
+        (format "Topic for %s: %s"
+                (riece-format-identity channel-identity t)
+                topic))
+       "\n")))
+    (riece-emit-signal 'channel-topic-changed channel-identity topic)))
 
 (defun riece-handle-331-message (prefix number name string)
   (riece-handle-set-topic prefix number name string t))
             (channel-identity (riece-make-identity channel
                                                    riece-server-name))
             (buffer (riece-channel-buffer channel-identity))
-            (entry (assoc channel riece-353-message-alist))
+            (entry (riece-identity-assoc channel riece-353-message-alist t))
             (string (cdr entry))
             (start 0)
             users)
            (setq riece-353-message-alist
                  (delq entry riece-353-message-alist)))
        (while (string-match
-               (concat "\\([@+]\\)?\\(" riece-user-regexp "\\) *")
+               (concat "\\([@+]\\)?\\([^ ]+\\) *")
                string start)
          (put-text-property (match-beginning 2) (match-end 2)
                             'riece-identity