* riece-300.el (riece-handle-366-message): Don't use riece-user-regexp.
[riece] / lisp / riece-300.el
index 9c528a2..2f758dc 100644 (file)
@@ -40,8 +40,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 +92,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
                 (substring string (match-end 0))))
        "\n"))))
 
-(defvar riece-353-users nil)
+(defvar riece-353-message-alist nil)
 (defun riece-handle-353-message (prefix number name string)
   "RPL_NAMREPLY        \"[=\*@] <channel> :[[@|+]<nick> [[@|+]<nick> [...]]]\"."
+  (make-local-variable 'riece-353-message-alist)      
   (if (string-match "^[=\*@] *\\([^ ]+\\) +:?" string)
-      (let ((channel (match-string 1 string))
-           (start 0)
-           user)
-       (make-local-variable 'riece-353-users)
-       (setq string (substring string (match-end 0)))
-       (while (string-match
-               (concat "\\([@+]\\)?\\(" riece-user-regexp "\\) *")
-               string start)
-         (put-text-property (match-beginning 2) (match-end 2)
-                            'riece-identity
-                            (riece-make-identity (match-string 2 string)
-                                                 riece-server-name)
-                            string)
-         (setq start (match-end 0)
-               user (if (match-beginning 1)
-                        (if (eq (aref string (match-beginning 1)) ?@)
-                            (list (match-string 2 string) ?o)
-                          (if (eq (aref string (match-beginning 1)) ?+)
-                              (list (match-string 2 string) ?v)))
-                      (list (match-string 2 string)))
-               riece-353-users (cons user riece-353-users)))
-       (let* ((channel-identity (riece-make-identity channel
-                                                     riece-server-name))
-              (buffer (riece-channel-buffer channel-identity)))
-         (riece-insert-info buffer (concat "Users: " string "\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 "Users on %s: %s"
-                    (riece-format-identity channel-identity t) string))
-           "\n"))))))
+      (let* ((channel (match-string 1 string))
+            (entry (riece-identity-assoc channel riece-353-message-alist t)))
+       (if entry
+           (setcdr entry
+                   (concat (cdr entry)
+                           (substring string (match-end 0))))
+         (setq riece-353-message-alist
+               (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)
 (defun riece-handle-366-message (prefix number name string)
   "RPL_ENDOFNAMES \"<channel> :End of NAMES list\""
   (if (string-match "^\\([^ ]+\\) " string)
-      (let ((channel (match-string 1 string)))
-       (riece-naming-assert-channel-users (nreverse riece-353-users)
-                                          channel)))
-  (setq riece-353-users nil))
+      (let* ((channel (match-string 1 string))
+            (channel-identity (riece-make-identity channel
+                                                   riece-server-name))
+            (buffer (riece-channel-buffer channel-identity))
+            (entry (riece-identity-assoc channel riece-353-message-alist t))
+            (string (cdr entry))
+            (start 0)
+            users)
+       (if entry
+           (setq riece-353-message-alist
+                 (delq entry riece-353-message-alist)))
+       (while (string-match
+               (concat "\\([@+]\\)?\\([^ ]+\\) *")
+               string start)
+         (put-text-property (match-beginning 2) (match-end 2)
+                            'riece-identity
+                            (riece-make-identity (match-string 2 string)
+                                                 riece-server-name)
+                            string)
+         (setq start (match-end 0)
+               users (cons (if (match-beginning 1)
+                               (if (eq (aref string (match-beginning 1)) ?@)
+                                   (list (match-string 2 string) ?o)
+                                 (if (eq (aref string (match-beginning 1)) ?+)
+                                     (list (match-string 2 string) ?v)))
+                             (list (match-string 2 string)))
+                           users)))
+       (setq users (nreverse users))
+       (riece-naming-assert-channel-users users channel)
+       (riece-insert-info
+        buffer
+        (concat (format "%d users: " (length users)) string "\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
+          (concat (format "%d users on %s: "
+                          (length users)
+                          (riece-format-identity channel-identity t))
+                  string))
+         "\n")))))
 
 (provide 'riece-300)