home *** CD-ROM | disk | FTP | other *** search
/ ftp.madoka.org / 2014.12.ftp.madoka.org.tar / ftp.madoka.org / pub / irchat-pj / irchat-pj-2.4.24.22.tar.gz / irchat-pj-2.4.24.22.tar / irchat-pj-2.4.24.22 / irchat-handle.el < prev    next >
Lisp/Scheme  |  2002-07-20  |  60KB  |  1,644 lines

  1. ;;; see file irchat-copyright.el for change log and copyright info
  2.  
  3. (require 'irchat-inlines)
  4. (require 'irchat-globals)
  5. (require 'irchat-pj-action)
  6.  
  7. (defsubst irchat-scan-channels (str)
  8.   (setq irchat-channel-alist (cons (list str) irchat-channel-alist)))
  9.  
  10. (defsubst irchat-user-on-this-channel (nick chan)
  11.   "return T if NICK is on channel CHAN"
  12.   (if (null nick) nil
  13.     (let ((n (intern nick)))
  14.       (string-list-ci-memberp chan (get n 'chnl)))))
  15.  
  16. (defun irchat-greet-user (nick chan)
  17.   (let ((n (intern nick)))
  18.     ;; modified by simm@irc.fan.gr.jp, Mon, 20 Dec 1999 21:35:11 +0900
  19.     (funcall irchat-pj-sound-join-function)
  20.     (message "IRCHAT: %s has entered! (%s)" nick
  21.          (if (string= chan "0") "on no channel yet"
  22.            (concat "on channel " (irchat-chan-virtual chan))))
  23.     (if (get n 'irchat-greeting)
  24.     (irchat-send "PRIVMSG %s :%s" nick (get n 'irchat-greeting)))
  25.     (put n 'irchat-waited-for nil)
  26.     (put n 'irchat-greeting nil)))
  27.  
  28.  
  29. (defun irchat-change-nick-of (old new)
  30.   (let ((pair (assoc old irchat-nick-alist)))
  31.     (if pair
  32.     (setcar pair new)
  33.       (setq irchat-nick-alist (cons (cons new nil) irchat-nick-alist)))
  34.     (if (null new) ;; maybe quit
  35.     (put (intern old) 'chnl nil))))
  36.  
  37. (defun irchat-Command-debug-user ()
  38.   "for debugging."
  39.   (interactive)
  40.   (let (rest str chan oper (nick (read-string (format "NICK: "))))
  41.     (setq rest (get (intern nick) 'chnl))
  42.     (setq str (format "%s =" nick))
  43.     (while rest
  44.       (setq chan (car rest))
  45.       (setq rest (cdr rest))
  46.       (setq oper (cdr (assoc nick (get (intern chan) 'nicka))))
  47.       (setq str (format "%s %s%s" str (or oper "")
  48.             (irchat-chan-virtual chan))))
  49.     (irchat-insert0 (format "%s (shared channels)\n" str))
  50.     (irchat-insert0 (format "%s = [%s] to %s last seen\n" nick
  51.                 (irchat-convert-seconds2
  52.                  (get (intern nick) 'lasttime))
  53.                 (irchat-chan-virtual
  54.                  (or (get (intern nick) 'lastchan) "(not yet)"))))
  55.     (irchat-insert0 (format "%s = <%s>\n" nick
  56.                 (or (get (intern nick) 'userhost) "not yet")))))
  57.  
  58.  
  59. (defsubst irchat-remove-from-channel (nick chan)
  60.   "Remove users info from his channel"
  61.   (let (chans (u (intern nick)))
  62.     (setq chans (string-list-ci-delete chan (get u 'chnl)))
  63.     (put u 'chnl chans)
  64.     (if (null chans)  ;; no more shared chanel
  65.     nil)))
  66.  
  67. (defun irchat-add-to-channel (nicks chan)
  68.   "Update our copy of NICKS on channel CHAN."
  69.   (let ((nicka (get (intern chan) 'nicka)))
  70.     (while (string-match "^\\([@+]?\\)\\([^ ]+\\) ?\\(.*\\)" nicks)
  71.       (let ((oper (matching-substring nicks 1))
  72.         (nick (matching-substring nicks 2))
  73.         chans)
  74.     (setq nicks (matching-substring nicks 3))
  75.     (setq nicka (cons (cons nick oper) nicka))
  76.     (setq chans (get (intern nick) 'chnl))
  77.     (if (not (string-list-ci-memberp chan chans))
  78.         (put (intern nick) 'chnl (nconc chans (list chan))))
  79.     (if (get (intern nick) 'irchat-waited-for)
  80.         (irchat-greet-user nick chan))
  81.     (if (null (assoc nick irchat-nick-alist))
  82.         (setq irchat-nick-alist (cons (list nick) irchat-nick-alist)))))
  83.     (put (intern chan) 'nicka nicka)))
  84.  
  85. (defun irchat-channel-operator (nick chan)
  86.   (cdr (assoc nick (get (intern chan) 'nicka))))
  87.  
  88. (defun irchat-channel-operator-set (nick chan oper)
  89.   (let ((nicka (assoc nick (get (intern chan) 'nicka))))
  90.     (and nicka
  91.      (setcdr nicka oper))))
  92.  
  93. (defun irchat-channel-newnick-set (nick chan newnick)
  94.   (let ((nicka (assoc nick (get (intern chan) 'nicka))))
  95.     (and nicka
  96.      (setcar nicka newnick))))
  97.  
  98. (defun irchat-user-last-privmsg (nick)
  99.   (get (intern nick) 'lastchan))
  100.  
  101. (defun irchat-user-last-privmsg-time (nick)
  102.   (let ((time (get (intern nick) 'lasttime)))
  103.     (if time (- (irchat-current-time) time) nil)))
  104.  
  105. ;; begin: add by simm@irc.fan.gr.jp, Tue, 20 Jul 1999
  106. (defsubst irchat-pj-make-verbose-nick (nick userhost flag)
  107.   (if flag
  108.       (concat nick "(" userhost ")")
  109.     nick))
  110. ;; end
  111.  
  112.  
  113. (defun irchat-handle-error (prefix msg)
  114.   (if (not irchat-no-configure-windows)
  115.       (irchat-insert-allchan (format "ERROR: %s\n" msg) nil))
  116.   (setq irchat-fatal-error-message msg)
  117.   (message "IRC ERROR: %s" msg))
  118.  
  119. (defun irchat-handle-482 (prefix me chan msg)
  120.   (message "IRCHAT: You are not a channel operator on %s"
  121.        (irchat-chan-virtual chan)))
  122.  
  123. (defun irchat-handle-464 (prefix me msg)
  124.   (irchat-insert0 (format 
  125.        "*** Password incorrect from %s. Try again with password.\n" prefix))
  126.   (setq irchat-reconnect-with-password t))
  127.  
  128. (defun irchat-handle-nick (prefix userhost nick)
  129.   (irchat-insert (concat
  130.                   (irchat-pj-make-verbose-nick prefix userhost irchat-pj-handle-nick-verbose)
  131.                   " is now known as " nick "\n")
  132.          (get (intern prefix) 'chnl))
  133.   (irchat-change-nick-of prefix nick)
  134.   (put (intern nick) 'chnl (get (intern prefix) 'chnl))
  135.   (put (intern prefix) 'chnl nil)
  136.   (mapcar
  137.    '(lambda (chan)
  138.       (irchat-channel-newnick-set prefix chan nick))
  139.    (get (intern nick) 'chnl))
  140.   (if (string= prefix irchat-nickname)
  141.       (progn
  142.     (setq irchat-nickname nick)
  143.     (if (string= prefix irchat-current-chat-partner)
  144.         (setq irchat-current-chat-partner nick))
  145.     (irchat-insert-special
  146.          (concat
  147.           (irchat-pj-make-verbose-nick prefix userhost irchat-pj-handle-nick-verbose)
  148.           " is now known as " nick "\n")))))
  149.  
  150. (defun irchat-handle-notice (prefix chan msg)
  151.   ;; begin: add by simm@irc.fan.gr.jp, Mon, 18 Jan 1999
  152.   (and irchat-pj-rewrite-server-notice
  153.        (string= prefix irchat-server)
  154.        (setq prefix nil msg (concat "=== " msg)))
  155.   ;; end
  156.   (cond 
  157.    ((null prefix)
  158.     (if (string-match "ERROR" msg)
  159.     (irchat-insert-allchan (format "%s\n" msg))
  160.       (irchat-insert-special (format "%s\n" msg))))
  161.    ((string-match "\001\\(.*\\)\001" msg)
  162.     (irchat-ctcp-notice prefix msg))
  163.    ((string-match "^\\*\\*\\* Notice -- \\(.*\\)" msg)
  164.     (let ((notice (matching-substring msg 1)))
  165.       (cond
  166.        ((and irchat-ignore-fakes
  167.          (string-match "^Fake" notice))
  168.     t)
  169.        ((and irchat-ignore-noauths
  170.          (string-match "^No Authorization" notice))
  171.     t)
  172.        ((and irchat-ignore-kills
  173.          (string-match "^Received KILL" notice))
  174.     t)
  175.        ((and irchat-shorten-kills
  176.          (string-match 
  177.           "^Received KILL message for \\([^.]*\\)\\. From \\([^ ]*\\) Path: \\([^ ]*\\) ?\\(.*\\)" notice))
  178.     (let ((killed (matching-substring notice 1))
  179.           (killer (matching-substring notice 2))
  180.           (reason (matching-substring notice 4))
  181.           (cbuf (current-buffer)))
  182.       (set-buffer irchat-KILLS-buffer)
  183.       (goto-char (point-max))
  184.       (insert (format "%s\n" notice))
  185.       (set-buffer cbuf)
  186.       (irchat-insert0 (format "%s KILLed %s %s\n" killer killed
  187.                   (if (= (length reason) 0)
  188.                       "-No reason supplied-"
  189.                     reason)))))
  190.        (t
  191.     (irchat-insert0 (format "%s: %s\n" prefix notice))))))
  192.    (t
  193.     (irchat-handle-privmsg2 prefix chan msg))))
  194.  
  195. (defun irchat-handle-ping (prefix msg)
  196.   (irchat-send-pong msg)
  197.   (irchat-maybe-poll))
  198.  
  199. ;; modified by simm@irc.fan.gr.jp, Sat, 13 Jun 1999
  200. (defun irchat-handle-pong (prefix he &optional msg)
  201.   (cond
  202.    ((and msg (string= msg "irchat-polling"))
  203.     (setq irchat-polling t))
  204.    ((string-match he ":irchat-polling$")
  205.     (setq irchat-polling t))
  206.    (t
  207.     ;;(irchat-insert0 (format "[%s]\n" (matching-substring rest 1)))
  208.     nil)))
  209.  
  210. (defun irchat-handle-privmsg (prefix chan msg)
  211.   (or (null prefix)
  212.       (and prefix
  213.        (memq (intern prefix) irchat-ignore-nickname)
  214.        (irchat-msg-from-ignored prefix chan msg))
  215.       (let ((temp msg)
  216.         (case-fold-search t))
  217.     ;; begin sound extension: modified by kaoru@kaisei.org
  218.     (cond ((and (string-match "\007" temp) irchat-beep-on-bells)
  219.            (funcall irchat-pj-sound-bell-function))
  220.           ((consp irchat-pj-sound-words-list)
  221.            (let ((re irchat-pj-sound-words-list))
  222.          (while (consp re)
  223.            (save-match-data
  224.              (cond ((string-match (car re) temp)
  225.                 (funcall irchat-pj-sound-words-function)
  226.                 (setq re nil))
  227.                (t (setq re (cdr re)))))))))
  228.     ;; end
  229.     (if (and (string-match "\001\\(.*\\)\001" temp)
  230.          (or (not (string= irchat-nickname prefix))
  231.              (irchat-match-me chan)))
  232.         (setq temp (irchat-ctcp-msg prefix chan temp)))
  233.     (if (not (string= temp ""))
  234.         (irchat-handle-privmsg2 prefix chan temp))
  235.     ;; add by mikami@nk.hcs.ts.fujitsu.co.jp, Tue, 31 Aug 1999 10:48:12 +0900
  236.     (run-hooks 'irchat-privmsg-exit-hook))))
  237.  
  238. (defun irchat-handle-privmsg2 (prefix chan xmsg)
  239.   (or (not (irchat-match-me chan))
  240.       (get-buffer-window irchat-Dialogue-buffer)
  241.       (get-buffer-window irchat-Others-buffer)
  242.       (get-buffer-window irchat-Private-buffer)
  243.       (message "IRCHAT: A private message has arrived from %s" prefix))
  244.   ;; only private messages to us get time-stamp
  245.   (if (irchat-match-me chan)
  246.       (irchat-insert-private t prefix xmsg)
  247.     (if (string= irchat-nickname prefix)
  248.     ;; my message to channel/partner
  249.     (irchat-insert-private nil chan xmsg)
  250.       (if (irchat-user-on-this-channel prefix chan) 
  251.       ;; user on this channel
  252.       (irchat-insert (format "%s %s\n"
  253.                  (format "<%s:%s>"
  254.                      (irchat-chan-virtual chan)
  255.                      prefix) xmsg)
  256.              chan 'privmsg)
  257.     ;; user not on this channel
  258.     (irchat-insert (format "%s %s\n"
  259.                    (format "(%s:%s)"
  260.                        (irchat-chan-virtual chan)
  261.                        prefix) xmsg)
  262.                chan 'privmsg))))
  263.   (put (intern prefix) 'lastchan chan)
  264.   (put (intern prefix) 'lasttime (irchat-current-time)))
  265.  
  266. (defun irchat-match-me (dest)
  267.   (or (string-ci-equal dest irchat-nickname)
  268.       (string-ci-equal dest (format "%s@%s" irchat-my-user
  269.                     irchat-my-server))
  270.       (string-ci-equal dest (format "%s%%%s@%s" irchat-my-user
  271.                     irchat-my-host irchat-my-server))))
  272.  
  273. (defun irchat-handle-wallops (prefix msg)
  274.   "Handle the WALLOPS message."
  275.   (if irchat-show-wallops
  276.       (irchat-insert0 (format "*** Wallops: %s %s\n" prefix msg)))
  277.   (let ((buf (current-buffer)))
  278.     (set-buffer irchat-WALLOPS-buffer)
  279.     (goto-char (point-max))
  280.     (insert (format "%s %s\n"
  281.             (if prefix (concat "from " prefix) "") msg))
  282.     (set-buffer buf)))
  283.  
  284.  
  285. (defun irchat-handle-quit (prefix userhost reason)
  286.   "Handle the QUIT message."
  287.   (irchat-insert (concat
  288.                   (irchat-pj-make-verbose-nick prefix userhost irchat-pj-handle-quit-verbose)
  289.                   " has left IRC (" reason ")\n")
  290.          (get (intern prefix) 'chnl)
  291.          (concat "has left IRC (" reason ")")
  292.          t
  293.                  (concat
  294.                   (irchat-pj-make-verbose-nick prefix userhost irchat-pj-handle-quit-verbose)
  295.                   ","))
  296.   ;; begin sound extension: modified by kaoru@kaisei.org
  297.   (and irchat-pj-sound-when-part
  298.        (not irchat-ignore-changes)
  299.        (funcall irchat-pj-sound-part-function))
  300.   ;; end sound extension:
  301.   (put (intern prefix) 'chnl nil)
  302.   (irchat-change-nick-of prefix nil))
  303.  
  304. (defun irchat-handle-topic (prefix chan topic)
  305.   "Handle the TOPIC message."
  306.   (if (not irchat-ignore-changes)
  307.       (irchat-insert (format "New topic on %s set by %s: %s\n"
  308.                  (irchat-chan-virtual chan) prefix topic)
  309.              chan t)))
  310.  
  311. (defun irchat-handle-mode (prefix chan &rest args)
  312.   "Handle the MODE message."
  313.   (let ((str ""))
  314.     (while args
  315.       (cond ((string-match "\\+ooo" (car args))
  316.          (irchat-channel-operator-set (nth 1 args) chan "@")
  317.          (irchat-channel-operator-set (nth 2 args) chan "@")
  318.          (irchat-channel-operator-set (nth 3 args) chan "@"))
  319.         ((string-match "\\+oo-o" (car args))
  320.          (irchat-channel-operator-set (nth 1 args) chan "@")
  321.          (irchat-channel-operator-set (nth 2 args) chan "@")
  322.          (irchat-channel-operator-set (nth 3 args) chan nil))
  323.         ((string-match "\\+o-o\\+o" (car args))
  324.          (irchat-channel-operator-set (nth 1 args) chan "@")
  325.          (irchat-channel-operator-set (nth 2 args) chan nil)
  326.          (irchat-channel-operator-set (nth 3 args) chan "@"))
  327.         ((string-match "-o\\+oo" (car args))
  328.          (irchat-channel-operator-set (nth 1 args) chan nil)
  329.          (irchat-channel-operator-set (nth 2 args) chan "@")
  330.          (irchat-channel-operator-set (nth 3 args) chan "@"))
  331.         ((string-match "-oo\\+o" (car args))
  332.          (irchat-channel-operator-set (nth 1 args) chan nil)
  333.          (irchat-channel-operator-set (nth 2 args) chan nil)
  334.          (irchat-channel-operator-set (nth 3 args) chan "@"))
  335.         ((string-match "-o\\+o-o" (car args))
  336.          (irchat-channel-operator-set (nth 1 args) chan nil)
  337.          (irchat-channel-operator-set (nth 2 args) chan "@")
  338.          (irchat-channel-operator-set (nth 3 args) chan nil))
  339.         ((string-match "\\+o-oo" (car args))
  340.          (irchat-channel-operator-set (nth 1 args) chan "@")
  341.          (irchat-channel-operator-set (nth 2 args) chan nil)
  342.          (irchat-channel-operator-set (nth 3 args) chan nil))
  343.         ((string-match "-ooo" (car args))
  344.          (irchat-channel-operator-set (nth 1 args) chan nil)
  345.          (irchat-channel-operator-set (nth 2 args) chan nil)
  346.          (irchat-channel-operator-set (nth 3 args) chan nil))
  347.         ((string-match "\\+oo" (car args))
  348.          (irchat-channel-operator-set (nth 1 args) chan "@")
  349.          (irchat-channel-operator-set (nth 2 args) chan "@"))
  350.         ((string-match "\\+o-o" (car args))
  351.          (irchat-channel-operator-set (nth 1 args) chan "@")
  352.          (irchat-channel-operator-set (nth 2 args) chan nil))
  353.         ((string-match "-o\\+o" (car args))
  354.          (irchat-channel-operator-set (nth 1 args) chan nil)
  355.          (irchat-channel-operator-set (nth 2 args) chan "@"))
  356.         ((string-match "-oo" (car args))
  357.          (irchat-channel-operator-set (nth 1 args) chan nil)
  358.          (irchat-channel-operator-set (nth 2 args) chan nil))
  359.         ((string-match "\\+o" (car args))
  360.          (irchat-channel-operator-set (nth 1 args) chan "@"))
  361.         ((string-match "-o" (car args))
  362.          (irchat-channel-operator-set (nth 1 args) chan nil)))
  363.       (setq str (format "%s %s" str (car args)))
  364.       (setq args (cdr args)))
  365.     (if (string= chan irchat-nickname)
  366.     (if (not irchat-ignore-changes)
  367.         (irchat-insert (format "Your new mode is set:%s\n" str)
  368.                irchat-Private-buffer
  369.                (format "Your new mode is set:")
  370.                nil
  371.                (format "%s" str)))
  372.       (if (not irchat-ignore-changes)
  373.       (irchat-insert (format "New mode for %s set by %s:%s\n"
  374.                  (irchat-chan-virtual chan) prefix str)
  375.              chan
  376.              (format "New mode for %s set by %s:"
  377.                  (irchat-chan-virtual chan) prefix)
  378.              nil
  379.              (format "%s" str))))))
  380.  
  381.  
  382. (defun irchat-handle-kick (prefix chan nick reason)
  383.   "Handle the KICK message."
  384.   (irchat-remove-from-channel nick chan)
  385.   (if (string= nick irchat-nickname)
  386.       (progn
  387.     (irchat-insert (format
  388.             "You were kicked off channel %s by %s. (%s)\n"
  389.             (irchat-chan-virtual chan) prefix reason)
  390.                (list chan irchat-Private-buffer) t)
  391.     (setq irchat-current-channels
  392.           (string-list-ci-delete chan irchat-current-channels))
  393.     (put (intern chan) 'nicka nil)
  394.     (irchat-Channel-part chan))
  395.     (irchat-insert (format
  396.             "%s has kicked %s out from channel %s (%s)\n"
  397.             prefix nick (irchat-chan-virtual chan) reason)
  398.            chan t)))
  399.  
  400. (defun irchat-handle-invite (prefix nick chan)
  401.   (irchat-insert-special
  402.    (format "*** %s invites you to channel %s\n"
  403.        prefix (irchat-chan-virtual chan)) t)
  404.   ;; begin sound extension: modified by kaoru@kaisei.org
  405.   (if irchat-pj-sound-when-invited
  406.       (funcall irchat-pj-sound-invited-function))
  407.   ;; end sound extension:
  408.   (setq irchat-invited-channel chan))
  409.  
  410. (defun irchat-handle-kill (prefix me path)
  411.   (irchat-insert-special
  412.    (format "*** IRCHAT: You were killed by %s. Path: %s\n" 
  413.        prefix path) t)
  414.   (irchat-insert-allchan (format "ERROR: You were Killed.\n") nil)
  415.   (irchat-Channel-part nil))
  416.  
  417. (defun irchat-handle-join (nick userhost chan)
  418.   "Handle the JOIN message."
  419.   (let ((oper "") (voice "") (xnick nick))
  420.     (if (string-match "^\\([^\007]+\\)\007\\(o*\\)\\(v*\\)$" chan)
  421.     (setq voice (matching-substring chan 3)
  422.           oper (matching-substring chan 2)
  423.           chan (matching-substring chan 1)))
  424.     (if (string= oper "o")
  425.     (setq xnick (format "@%s" xnick))
  426.       (if (string= voice "v")
  427.       (setq xnick (format "+%s" xnick))))
  428.     (if (string= nick irchat-nickname)
  429.     (progn
  430.       (setq irchat-current-channels
  431.         (cons chan irchat-current-channels))
  432.       (irchat-Channel-join chan)
  433.       (put (intern chan) 'init t)
  434.       (put (intern chan) 'nicka nil))
  435.       ;; add by simm@irc.fan.gr.jp, Sat, 18 Dec 1999 01:26:35 +0900
  436.       (and irchat-pj-auto-oper-list
  437.        (irchat-pj-action-auto-oper nick userhost chan))
  438.       (irchat-add-to-channel nick chan))
  439.     (if (not irchat-ignore-changes)
  440.     (irchat-insert (concat
  441.                         (irchat-pj-make-verbose-nick xnick userhost
  442.                              irchat-pj-handle-join-verbose)
  443.                         " has joined channel "
  444.                         (irchat-chan-virtual chan)
  445.                         "\n")
  446.                (if (string= nick irchat-nickname)
  447.                (list chan irchat-Private-buffer) chan)
  448.                (concat "has joined channel " (irchat-chan-virtual chan))
  449.                        t
  450.                        (concat
  451.                         (irchat-pj-make-verbose-nick xnick userhost
  452.                              irchat-pj-handle-join-verbose)
  453.                         ",")))
  454.     ;; begin sound extension: modified by kaoru@kaisei.org
  455.     (and irchat-pj-sound-when-join
  456.      (not irchat-ignore-changes)
  457.      (funcall irchat-pj-sound-join-function))
  458.     ;; end sound extension:
  459.     (irchat-change-nick-of nick nick)))
  460.  
  461. (defun irchat-handle-part (prefix userhost chan &optional reason)
  462.   "Handle the PART message."
  463.   (if (null reason) (setq reason ""))
  464.   (if (string= prefix irchat-nickname)
  465.       (progn
  466.     (setq irchat-current-channels
  467.           (string-list-ci-delete chan irchat-current-channels))
  468.     (put (intern chan) 'nicka nil)))
  469.   (if (not irchat-ignore-changes)
  470.       (irchat-insert (concat
  471.                       (irchat-pj-make-verbose-nick prefix userhost
  472.                            irchat-pj-handle-part-verbose)
  473.                       " has left channel "
  474.                       (irchat-chan-virtual chan)
  475.                       " (" reason ")\n")
  476.              (if (string= prefix irchat-nickname)
  477.              (list chan irchat-Private-buffer) chan)
  478.              (concat "has left channel "
  479.                              (irchat-chan-virtual chan)
  480.                              " (" reason ")")
  481.              t
  482.                      (concat
  483.                       (irchat-pj-make-verbose-nick prefix userhost
  484.                            irchat-pj-handle-part-verbose)
  485.                       ",")))
  486.   (if (not (string= prefix irchat-nickname))
  487.       ;; begin sound extension: modified by kaoru@kaisei.org
  488.       (and irchat-pj-sound-when-part
  489.        (not irchat-ignore-changes)
  490.        (funcall irchat-pj-sound-part-function))
  491.       ;; end sound extension:
  492.     (irchat-Channel-part chan)
  493.     (if (null irchat-invited-channel)
  494.     (setq irchat-invited-channel chan)))
  495.   (irchat-remove-from-channel prefix chan)
  496.   (irchat-change-nick-of prefix prefix))
  497.  
  498. ;;;
  499. ;;;  000 replies -- what the fuck is the author of ircd thinking.
  500. ;;;
  501. (defun irchat-handle-000s (number prefix me &rest args)
  502.   (cond
  503.    ((= (length args) 1)
  504.     (irchat-insert0 (format "*** %s\n" (car args))))
  505.    ((= (length args) 2)
  506.     (irchat-insert0 (format "*** %s %s\n" (car args) (nth 1 args))))
  507.    ((= (length args) 3)
  508.     (irchat-insert0 (format "*** %s %s (%s)\n"
  509.                 (car args) (nth 2 args) (nth 1 args))))
  510.    (t
  511.     (message "IRCHAT: Strange %s reply" number))))
  512.  
  513.  
  514. (defun irchat-handle-001 (prefix nick msg)
  515.   (setq irchat-my-server prefix)
  516.   (if (string-match ".*!\\([^!]*\\)" msg)
  517.       (setq irchat-pj-my-userhost (matching-substring msg 1)))
  518.   (if irchat-no-configure-windows
  519.       (irchat-configure-windows))
  520.   (or (string= irchat-nickname nick)
  521.       (irchat-insert-special (format "%s is now known as %s\n" irchat-nickname nick) t))
  522.   (irchat-insert-special
  523.    (format "*** Welcome to the Internet Relay Chat world. Your nick is %s.\n" nick))
  524.   (setq irchat-servername prefix)
  525.   (setq irchat-nickname nick)
  526.   (irchat-send "USERHOST %s" irchat-nickname)
  527.   (setq irchat-my-userhost nil))
  528.  
  529. (defun irchat-handle-002 (prefix me msg)
  530.   (if (string-match "running version \\(.*\\)" msg)
  531.       (irchat-insert-special
  532.        (format "*** Your server is %s (version %s).\n"
  533.            irchat-servername (matching-substring msg 1))))
  534.   (irchat-insert0
  535.    (format "*** Your client version is %s.\n" irchat-pj-version-string)))
  536.  
  537. (defun irchat-handle-003 (prefix me msg)
  538.   (irchat-insert0 (format "*** %s \n" msg)))
  539.  
  540. ;;(defun irchat-handle-004 (prefix me server version mode1 mode2)
  541. (defun irchat-handle-004 (prefix me server &optional version mode1 mode2)
  542.   ;;(irchat-insert0
  543.    ;;(format "*** %s %s %s %s\n" server version mode1 mode2))
  544.   (irchat-maybe-poll))
  545.  
  546.  
  547. ;;;
  548. ;;;  200 replies
  549. ;;;
  550. (defun irchat-handle-200s (number prefix me &rest args)
  551.   (cond
  552.    ((= (length args) 1)
  553.     (irchat-insert0 (format "*** %s\n" (car args))))
  554.    ((= (length args) 2)
  555.     (irchat-insert0 (format "*** %s %s\n" (car args) (nth 1 args))))
  556.    ((= (length args) 3)
  557.     (irchat-insert0
  558.      (format "*** %s %s (%s)\n" (car args) (nth 2 args) (nth 1 args))))
  559.    (t
  560.     (message "IRCHAT: Strange %s reply" number))))
  561.  
  562. (defun irchat-handle-200 (prefix me status version dest next &optional ver sec q1 q2)
  563.   "200 RPL_TRACELINK Link <version & debug level> <destination> <next server>"
  564.   (irchat-insert0 (format "*** Link %s (%s%s) ==> %s (%s)%s\n"
  565.               prefix version
  566.               (if ver (format " %s" ver) "")
  567.               next dest
  568.               (if sec (format " [%s] %s/%s"
  569.                       (irchat-convert-seconds sec)
  570.                       q1 q2) ""))))
  571.  
  572. (defun irchat-handle-201 (prefix me status class who)
  573.   "201 RPL_TRACECONNECTING Try. <class> <server>"
  574.   (irchat-insert0 (format "*** %s %s (%s) ==> %s\n"
  575.               status prefix class who)))
  576.  
  577. (defun irchat-handle-202 (prefix me status class who)
  578.   "202 RPL_TRACEHANDSHAKE H.S. <class> <server>"
  579.   (irchat-insert0 (format "*** %s %s (%s) ==> %s\n"
  580.               status prefix class who)))
  581.  
  582. (defun irchat-handle-203 (prefix me status class who)
  583.   "203 RPL_TRACEUNKNOWN ???? <class> [<client IP address in dot form>]"
  584.   (irchat-insert0 (format "*** %s %s (%s) ==> %s\n"
  585.               status prefix class who)))
  586.  
  587. (defun irchat-handle-204 (prefix me status class who)
  588.   "204 RPL_TRACEOPERATOR Oper <class> <nick>"
  589.   (irchat-insert0 (format "*** %s %s (%s) ==> %s\n"
  590.               status prefix class who)))
  591.  
  592. (defun irchat-handle-205 (prefix me status class who &optional dummy time)
  593.   (irchat-insert0 (format "*** %s %s (%s) ==> %s%s\n"
  594.               status prefix class who
  595.               (if time (format " (%s)" time) ""))))
  596.  
  597. (defun irchat-handle-206 (prefix me status class Nserver Nclient name how &optional version)
  598.   "206 RPL_TRACELINK Serv 200 3S 15C irc.other *!*@other.host :V3"
  599.   (irchat-insert0 (format "*** Server %s (%s) ==> %s {%s,%s} %s %s\n"
  600.               prefix class name Nserver Nclient how
  601.               (if version (format "[%s]" version) ""))))
  602.  
  603. (defun irchat-handle-209 (prefix me status class entries)
  604.   (irchat-insert0 (format "*** Class %s (%s entries)\n"
  605.                 class entries)))
  606.  
  607. (defvar irchat-stats-now nil)
  608.  
  609. (defun irchat-handle-211 (prefix me link sndq sndm sndb rcvm rcvb time)
  610.   "NOTICE %s :%-15.15s%5u%7u%10u%7u%10u %s"
  611.   (setq    time (string-to-int time))
  612.   (if (not irchat-stats-now)
  613.       (progn
  614.     (irchat-insert0 (format "STATS L %s\n" prefix))
  615.     (irchat-insert0 
  616.    "    Time             Send-Q   Send-Msg    Send-KB   Recv-Msg    Recv-KB\n")
  617.     (setq irchat-stats-now prefix)))
  618.   (irchat-insert0 (format "%s\n" link))
  619.   (irchat-insert0
  620.    (format "%5ddays %02d:%02d:%02d %8s %10s %10s %10s %10s\n"
  621.        (/ (/ (/ time 60) 60) 24)
  622.        (mod (/ (/ time 60) 60) 24)
  623.        (mod (/ time 60) 60)
  624.        (mod time 60)
  625.        sndq sndm sndb rcvm rcvb)))
  626.  
  627. (defun irchat-handle-213 (prefix me cmd host pass server port class)
  628.   (if (not irchat-stats-now)
  629.       (progn
  630.     (irchat-insert0 (format "STATS C %s\n" prefix))
  631.     (setq irchat-stats-now prefix)))
  632.   (irchat-insert0 (format "%s:%s:%s:%s:%s:%s\n"
  633.               cmd host pass server port class)))
  634.  
  635. (defun irchat-handle-214 (prefix me cmd host pass server port class)
  636.   (if (not irchat-stats-now)
  637.       (progn
  638.     (irchat-insert0 (format "STATS C %s\n" prefix))
  639.     (setq irchat-stats-now prefix)))
  640.   (irchat-insert0 (format "%s:%s:%s:%s:%s:%s\n"
  641.               cmd host pass server port class)))
  642.  
  643. (defun irchat-handle-212 (prefix me cmd times bytes &optional rtimes)
  644.   (if (not irchat-stats-now)
  645.       (progn
  646.     (irchat-insert0 (format "STATS M %s\n" prefix))
  647.     (setq irchat-stats-now prefix)))
  648.   (if rtimes
  649.       (irchat-insert0
  650.        (format "%s has been used %s times (remote: %s times) after startup (%s bytes)\n"
  651.            cmd times rtimes bytes))
  652.     (irchat-insert0
  653.      (format "%s has been used %s times after startup (%s bytes)\n"
  654.          cmd times bytes))))
  655.  
  656. (defun irchat-handle-215 (prefix me cmd ip passwd domain port class)
  657.   ":server.name 215 me I ip * domain port class"
  658.   (if (not irchat-stats-now)
  659.       (progn
  660.     (irchat-insert0 (format "STATS I %s\n" prefix))
  661.     (setq irchat-stats-now prefix)))
  662.   (irchat-insert0 (format "*** %s:%s:%s:%s:%s:%s\n"
  663.               cmd ip passwd domain port class)))
  664.  
  665. (defun irchat-handle-216 (prefix me cmd domain &rest args)
  666.   ":servernameirc 216 me K domain ..."
  667.   (if (not irchat-stats-now)
  668.       (progn
  669.     (irchat-insert0 (format "STATS K %s\n" prefix))
  670.     (setq irchat-stats-now prefix)))
  671.   (irchat-insert0 (format "*** %s:%s:%s\n"
  672.               cmd domain
  673.               (let ((str ""))
  674.                 (while args
  675.                   (setq str (format "%s %s" str (car args))
  676.                     args (cdr args)))
  677.                 str))))
  678.  
  679. (defun irchat-handle-217 (prefix me cmd reason star host stuff)
  680.   (if (not irchat-stats-now)
  681.       (progn
  682.     (irchat-insert0 (format "STATS Q %s\n" prefix))
  683.     (setq irchat-stats-now prefix)))
  684.   (irchat-insert0 (format "*** %s:%s:%s:%s:%s\n"
  685.               cmd reason star host stuff)))
  686.  
  687. (defun irchat-handle-218 (prefix me cmd class pfreq cfreq mlinks msendq &optional local global)
  688.   ":server.name 218 me Y class 120 600 1 3000000"
  689.   (if (not irchat-stats-now)
  690.       (progn
  691.     (irchat-insert0 (format "STATS Y %s\n" prefix))
  692.     (setq irchat-stats-now prefix)))
  693.   (irchat-insert0 (format 
  694.        "*** Class %s: PingFreq %s, ConFreq %s, MaxLinks %s, MaxSendQ %s%s%s\n"
  695.          class pfreq cfreq mlinks msendq
  696.          (if local (format ", LocalLimit %s" local) "")
  697.          (if global (format ", GlobalLimit %s" global) ""))))
  698.  
  699. (defun irchat-handle-219 (prefix me type msg)
  700.   "RPL_ENDOFSTATS"
  701.   (if (not irchat-stats-now)
  702.       (irchat-insert0 (format "*** Nothing (STATS %s %s)\n"
  703.                   type prefix)))
  704.   (setq irchat-stats-now nil))
  705.  
  706. (defun irchat-handle-221 (prefix me str) ;;; RPL_USERMODEIS?
  707.   "Handle the MODE message."
  708.   (irchat-insert-special (format "*** Mode for you is %s\n" str) t))
  709.  
  710. (defun irchat-handle-241 (prefix me cmd hostmask star server maxdepth etc)
  711.   ":irc.tokyo.wide.ad.jp 241 nick L * * irc.leaf.server 0 -1"
  712.   (if (not irchat-stats-now)
  713.       (progn
  714.     (irchat-insert0 (format "STATS H %s\n" prefix))
  715.     (setq irchat-stats-now prefix)))
  716.   (irchat-insert0 (format "*** %s:%s:%s:%s:%s:%s\n"
  717.               cmd hostmask star server maxdepth etc)))
  718.  
  719. (defun irchat-handle-242 (prefix me msg)
  720.   (if (not irchat-stats-now)
  721.       (progn
  722.     (irchat-insert0 (format "STATS U %s\n" prefix))
  723.     (setq irchat-stats-now prefix)))
  724.   (irchat-insert0 (format "*** %s\n" msg)))
  725.  
  726. (defun irchat-handle-243 (prefix me cmd hostname password user nazo class)
  727.   ":server.name 243 me O hostname password user nazo class"
  728.   (if (not irchat-stats-now)
  729.       (progn
  730.     (irchat-insert0 (format "STATS O %s\n" prefix))
  731.     (setq irchat-stats-now prefix)))
  732.   (irchat-insert0 (format "*** %s:%s:%s:%s:%s:%s\n"
  733.               cmd hostname password user nazo class)))
  734.  
  735. (defun irchat-handle-244 (prefix me cmd hostmask star server maxdepth etc)
  736.   ":irc.tokyo.wide.ad.jp 244 nick H * * irc.tokai-ic.or.jp 0 -1"
  737.   (if (not irchat-stats-now)
  738.       (progn
  739.     (irchat-insert0 (format "STATS H %s\n" prefix))
  740.     (setq irchat-stats-now prefix)))
  741.   (irchat-insert0 (format "*** %s:%s:%s:%s:%s:%s\n"
  742.               cmd hostmask star server maxdepth etc)))
  743.  
  744. (defun irchat-handle-246 (prefix me server p1 p2 p3 p4)
  745.   ":server0.jp 246 nick server1.jp[*@server1.hostname] 26 26 50 15"
  746.   (if (not irchat-stats-now)
  747.       (progn
  748.     (irchat-insert0 (format "STATS P %s\n" prefix))
  749.     (irchat-insert0 (format "*** %32s %5s %5s %5s %5s\n"
  750.                 "<server name>" "snd#" "rcv#" "ping" "pref"))
  751.     (setq irchat-stats-now prefix)))
  752.   (if (string-match "\\([^[]+\\)\\[[^]]+\\]" server)
  753.       (setq server (matching-substring server 1)))
  754.   (irchat-insert0 (format "*** %32s %5s %5s %5s %5s\n" server p1 p2 p3 p4)))
  755.  
  756. (defun irchat-handle-248 (prefix me msg)
  757.   "RPL_STATSDEFINE"
  758.   (if (not irchat-stats-now)
  759.       (progn
  760.     (irchat-insert0 (format "STATS D %s\n" prefix))
  761.     (setq irchat-stats-now prefix)))
  762.   (irchat-insert0 (format "*** %s\n" msg)))
  763.  
  764. (defun irchat-handle-249 (prefix me msg)
  765.   (if (not irchat-stats-now)
  766.       (progn
  767.     (irchat-insert0 (format "STATS T/Z %s\n" prefix))
  768.     (setq irchat-stats-now prefix)))
  769.   (irchat-insert0 (format "*** %s\n" msg)))
  770.  
  771. (defun irchat-handle-250 (prefix me msg)
  772.   "RPL_STATSDLINE"
  773.   (irchat-insert0 (format "*** %s\n" msg)))
  774.  
  775. (defun irchat-handle-251 (prefix me msg)
  776.   "RPL_LUSERCLIENT"
  777.   (irchat-insert0 (format "*** %s\n" msg)))
  778.  
  779. (defun irchat-handle-252 (prefix me count msg)
  780.   "RPL_LUSEROP"
  781.   (irchat-insert0 (format "*** %s %s\n" count msg)))
  782.  
  783. (defun irchat-handle-253 (prefix me count msg)
  784.   "RPL_LUSERUNKNOWN"
  785.   (irchat-insert0 (format "*** %s %s\n" count msg)))
  786.  
  787. (defun irchat-handle-254 (prefix me count msg)
  788.   "RPL_LUSERCHANNELS"
  789.   (irchat-insert0 (format "*** %s %s\n" count msg)))
  790.  
  791. (defun irchat-handle-255 (prefix me msg)
  792.   "RPL_LUSERME"
  793.   (irchat-insert0 (format "*** %s\n" msg)))
  794.  
  795. (defun irchat-handle-256 (prefix me msg)
  796.   "RPL_ADMINME"
  797.   (irchat-insert0 (format "*** %s\n" msg)))
  798.  
  799. (defun irchat-handle-257 (prefix me msg)
  800.   "RPL_ADMINLOC1"
  801.   (if (not (string= msg ""))
  802.       (irchat-insert0 (format "*** %s\n" msg))))
  803.  
  804. (defun irchat-handle-258 (prefix me msg)
  805.   "RPL_ADMINLOC2"
  806.   (if (not (string= msg ""))
  807.       (irchat-insert0 (format "*** %s\n" msg))))
  808.  
  809. (defun irchat-handle-259 (prefix me msg)
  810.   "RPL_ADMINEMAIL"
  811.   (if (not (string= msg ""))
  812.       (irchat-insert0 (format "*** %s\n" msg))))
  813.  
  814. (defun irchat-handle-261 (prefix me status filename port)  ; RPL_TRACELOG
  815.   (irchat-insert0 (format "*** LogFile %s => %s (%s)\n"
  816.               prefix filename port)))
  817.  
  818. (defun irchat-handle-262 (prefix me mask version msg)  ; RPL_ END TRACE
  819.   "262 RPL_TRACEEND *.jp 2.9.5. :End of TRACE"
  820.   (irchat-insert0 (format "*** END of TRACE to (%s) %s [%s]\n"
  821.               mask prefix version)))
  822.  
  823. ;;;
  824. ;;; 300 replies
  825. ;;;
  826. (defun irchat-handle-300s (number prefix me &rest args)
  827.   (cond
  828.    ((= (length args) 1)
  829.     (irchat-insert0 (format "*** %s\n" (car args))))
  830.    ((= (length args) 2)
  831.     (irchat-insert0 (format "*** %s %s\n" (car args) (nth 1 args))))
  832.    ((= (length args) 3)
  833.     (irchat-insert0
  834.      (format "*** %s %s (%s)\n" (car args) (nth 2 args) (nth 1 args))))
  835.    (t
  836.     (message "IRCHAT: Strange %s reply" number))))
  837.  
  838. (defun irchat-handle-301 (prefix me nick iswhat) ; RPL_AWAY
  839.   (if (not (string= nick irchat-auto-whois-nick))
  840.       (if irchat-while-whois-reply
  841.       (irchat-insert0 (format "AWAY: %s\n" iswhat))
  842.     (irchat-insert0 (format "%s is AWAY: %s\n" nick iswhat)))))
  843.  
  844. (defun irchat-handle-302 (prefix me data) ; RPL_USERHOST
  845.   "Handle the 302 reply, USERHOST reply"
  846.   (while (string-match 
  847.       "\\([^*=]+\\)\\([*]*\\)=\\([+-]\\)\\([^@]+\\)@\\([^ ]+\\) *\\(.*\\)" data)
  848.     (let ((nick (matching-substring data 1))
  849.       (oper (matching-substring data 2))
  850.       (away (matching-substring data 3))
  851.       (user (matching-substring data 4))
  852.       (host (matching-substring data 5))
  853.       userhost)
  854.       (setq data (matching-substring data 6))
  855.       (setq userhost (format "%s@%s" user host))
  856.       (put (intern nick) 'userhost userhost)
  857.       (if (and (string= nick irchat-nickname)
  858.            (null irchat-my-userhost))
  859.       (progn
  860.         (setq irchat-my-userhost userhost)
  861.         (setq irchat-my-user user)
  862.         (setq irchat-my-host host)
  863.         (irchat-insert-special
  864.          (format "*** You are %s.\n" irchat-my-userhost))
  865.         (and irchat-pj-first-channel
  866.          irchat-pj-initialize-p
  867.          (irchat-Command-join irchat-pj-first-channel))
  868.         (setq irchat-pj-initialize-p nil))
  869.     (irchat-insert0 (format "%s is <%s> [%s, %s]\n"
  870.                 nick userhost
  871.                 (concat 
  872.                  (if (string= oper "")
  873.                      "Not ")
  874.                  "Operator")
  875.                 (concat 
  876.                  (if (string= away "+")
  877.                      "Not ")
  878.                  "AWAY")))))))
  879.  
  880. (defun irchat-handle-303 (prefix me nicks) ; RPL_ISON
  881.   "Handle the 303 reply, ISON reply"
  882.   (if (string= nicks "")
  883.       (irchat-insert0 "No one you requested is on now.\n")
  884.     (irchat-insert0 (format "Following people(s) are on: %s\n" nicks))))
  885.  
  886. (defun irchat-handle-305 (prefix me msg) ; RPL_UNAWAY
  887.   "Handle the 305 reply, UNAWAY reply"
  888.   (if irchat-pj-away-p
  889.       (progn
  890.     (setq irchat-pj-away-p nil)
  891.     (irchat-maybe-poll)
  892.     (irchat-insert0 (format "*** %s (%s)\n"
  893.                 msg (current-time-string))))))
  894.  
  895. (defun irchat-handle-306 (prefix me msg) ; RPL_NOWAWAY
  896.   "Handle the 306 reply, NOWAWAY reply"
  897.   (setq irchat-pj-away-p t)
  898.   (irchat-insert0 (format "*** %s (%s)\n"
  899.               msg (current-time-string))))
  900.  
  901. (defun irchat-handle-311 (prefix me nick user host dummy name) ;; RPL_WHOISUSER
  902.   "Handle the 311 reply (from WHOIS)."
  903.   (setq irchat-while-whois-reply t)
  904.   (if (not (string= nick irchat-auto-whois-nick))
  905.       (irchat-insert0 (format "%s is <%s@%s> %s\n"
  906.                   nick user host name))))
  907.  
  908. (defun irchat-handle-312 (prefix me nick server info) ; RPL_WHOISSERVER
  909.   ":server.name 312 me her server.name2 :server info"
  910.   (if (not (string= nick irchat-auto-whois-nick))
  911.       (irchat-insert0 (format "on via server %s (%s)\n" server info))))
  912.  
  913. (defun irchat-handle-313 (prefix me nick iswhat) ; RPL_WHOISOPERATOR
  914.   (if (not (string= nick irchat-auto-whois-nick))
  915.       (irchat-insert0 (format "STATUS: %s\n" iswhat))))
  916.  
  917. (defun irchat-handle-314 (prefix me nick user host star name) ;; RPL_WHOWASUSER
  918.   "Handle the 314 reply (msa's WHOWAS)."
  919.   (message "")
  920.   (irchat-insert0 (format "%s was <%s@%s> %s\n"
  921.               nick user host name)))
  922.  
  923. (defun irchat-handle-315 (prefix ms chan msg) ; RPL_ENDOFWHO
  924.   (setq irchat-long-reply-count 0))
  925.  
  926. (defun irchat-handle-317 (prefix me nick sec &optional time msg) ;RPL_WHOISIDLE
  927.   ":server.name 317 me her 38 :seconds idle or\
  928.    :server.name 317 me her 38 839678551 :seconds idle, signon time"
  929.   (let (fun sec2)
  930.     (if (not (string= nick irchat-auto-whois-nick))
  931.     (irchat-insert0 (format "IDLE for %s %s\n"
  932.                 (irchat-convert-seconds sec)
  933.                 (if (setq sec2 (irchat-past-time sec))
  934.                     (format "(%s)" sec2)
  935.                   "")))
  936.       (if (fboundp (setq fun (intern "irchat-whois-idle")))
  937.       (apply fun (list nick (string-to-int sec)))))))
  938.  
  939. (defun irchat-handle-318 (prefix me nick msg) ; RPL_ENDOFWHOIS
  940.   ":server.name 318 me her :End of /WHOIS list."
  941.   (setq irchat-while-whois-reply nil)
  942.   (if (string= nick irchat-auto-whois-nick)
  943.       (setq irchat-auto-whois-nick "")))
  944.  
  945. (defun irchat-handle-319 (prefix me nick rest) ; RPL_????
  946.   ":server.name 319 me her :chan1 chan2 chan3"
  947.   (let ((str "") oper chan)
  948.     (while (string-match "^\\([@+]?\\)\\([^ ]+\\) +\\(.*\\)$" rest)
  949.       (setq oper (matching-substring rest 1))
  950.       (setq chan (matching-substring rest 2))
  951.       (setq rest (matching-substring rest 3))
  952.       (if (not (irchat-ischannel chan))
  953.       (setq chan (concat oper chan)
  954.         oper ""))
  955.       (setq str (format "%s %s%s" str oper (irchat-chan-virtual chan))))
  956.     (if (not (string= nick irchat-auto-whois-nick))
  957.     (irchat-insert0 (format "channels:%s\n" str)))))
  958.  
  959. (defun irchat-handle-321 (prefix me chan msg) ;;; RPL_LISTSTART
  960.   "Handle the 321 reply (first line from LIST)."
  961.   nil)
  962.  
  963. (defun irchat-handle-322 (prefix &optional me chan users topic bug) ; RPL_LIST
  964.   "Handle the 322 reply (from LIST)."
  965.   (setq irchat-long-reply-count (1+ irchat-long-reply-count))
  966.   (if (> irchat-long-reply-count 38)
  967.       (progn
  968.     (setq irchat-long-reply-count 0)
  969.     (irchat-send-pong)))
  970.   (if topic
  971.       (irchat-insert (format "Topic for %s (%s users): %s\n"
  972.                  (if (string= chan "*") "Private"
  973.                    (irchat-chan-virtual chan))
  974.                  users topic)
  975.              chan t)
  976.     (irchat-insert (format "*** Error 322: %s %s %s %s %s" prefix me chan users topic))))
  977.  
  978. (defun irchat-handle-323 (prefix me msg) ; RPL_LISTEND
  979.   (setq irchat-channel-filter "")
  980.   (setq irchat-long-reply-count 0))
  981.  
  982.  
  983. (defun irchat-handle-324 (prefix me chan &rest args) ; RPL_CHANNELMODEIS
  984.   "Handle the MODE message."
  985.   (let ((str ""))
  986.     (while args
  987.       (setq str (format "%s %s" str (car args)))
  988.       (setq args (cdr args)))
  989.     (irchat-insert (format "Mode for %s:%s\n"
  990.                (irchat-chan-virtual chan) str) chan t)))
  991.  
  992. (defun irchat-handle-331 (prefix me chan msg) ; RPL_NOTOPIC
  993.   (irchat-insert (format "No topic is set for %s\n"
  994.              (irchat-chan-virtual chan))
  995.          chan t))
  996.  
  997. (defun irchat-handle-332 (prefix me chan topic) ; RPL_TOPIC
  998.   (irchat-insert (format "Topic for %s: %s\n"
  999.              (irchat-chan-virtual chan) topic) chan t))
  1000.  
  1001. (defun irchat-handle-341 (prefix me nick chan) ; RPL_INVITING
  1002.   (irchat-insert (format "*** Inviting user %s to channel %s\n"
  1003.               nick (irchat-chan-virtual chan))
  1004.          chan t))
  1005.  
  1006. (defun irchat-handle-351 (prefix me ver server mode) ; RPL_VERSION
  1007.   (irchat-insert0 (format "*** %s is running IRC version %s (%s)\n"
  1008.               server ver mode)))
  1009.  
  1010. (defun irchat-handle-352 (prefix me chan user host serv nick oper name)
  1011.   "Handle the WHOREPLY message (352)"
  1012.   (setq irchat-long-reply-count (1+ irchat-long-reply-count))
  1013.   (if (> irchat-long-reply-count 38)
  1014.       (progn
  1015.     (setq irchat-long-reply-count 0)
  1016.     (irchat-send-pong)))
  1017.   (if (string-match "[0-9]* *\\(.*\\)" name)
  1018.       (setq name (matching-substring name 1)))
  1019.   (irchat-insert (format "%3s %9s %9s %30s %s\n"
  1020.              (add-space 3 oper)
  1021.              (add-space 9 (if (or (string= chan "*")
  1022.                           (string= chan "0"))
  1023.                       "Private"
  1024.                     (irchat-chan-virtual chan)))
  1025.              (add-space 9 nick)
  1026.              (add-space 30
  1027.                     (format "<%s@%s>" user host))
  1028.              name) chan t))
  1029.  
  1030. (defun irchat-handle-353 (prefix me flag chan nicks) ; RPL_NAMREPLY
  1031.   "Handle the 353 (NAMREPLY) message.   If we are just polling the server,
  1032. don't display anything.  Check if someone we are waiting for has entered."
  1033.   (setq irchat-long-reply-count (1+ irchat-long-reply-count))
  1034.   (if (> irchat-long-reply-count 38)
  1035.       (progn
  1036.     (setq irchat-long-reply-count 0)
  1037.     (irchat-send-pong)))
  1038.   (if irchat-polling
  1039.       nil
  1040.     (irchat-insert (format "%s = %s\n"
  1041.                (if (string= chan "*") "Private"
  1042.                  (irchat-chan-virtual chan))
  1043.                nicks) chan t))
  1044.   (irchat-scan-channels chan)
  1045.   (if (get (intern chan) 'init)
  1046.       (irchat-add-to-channel nicks chan)))
  1047.  
  1048. (defun irchat-handle-361 (prefix me who msg) ; RPL_KILLDONE
  1049.   ;; modified by simm@irc.fan.gr.jp, Sun, 27 Jun 1999
  1050.   (irchat-insert0 (format "You just KILLED %s. %s\n" who msg)))
  1051.  
  1052. (defun irchat-handle-364 (prefix me server next msg)
  1053.   (setq irchat-links-reply-count (1+ irchat-links-reply-count))
  1054.   (if (string-match "^\\([^ ]+\\) \\(\\[[^]]+\\]\\)? *\\(.*\\)" msg)
  1055.       (let ((hop (matching-substring msg 1))
  1056.         (comment (matching-substring msg 3)))
  1057.     (if irchat-how-to-show-links-reply
  1058.         (irchat-insert0 (format "%2s %30s <== %30s\n" hop
  1059.                     (add-space 30 server) 
  1060.                     (add-space 30 next)))
  1061.       (irchat-insert0 (format "%30s %s\n"
  1062.                   (add-space 30 server) comment))))))
  1063.  
  1064. (defun irchat-handle-365 (prefix me mask msg) ; RPL_ENDOFLINKS
  1065.   (if (= 0 irchat-links-reply-count)
  1066.       (irchat-insert0 (format "*** No match server. (%s)\n" mask)))
  1067.   (setq irchat-links-reply-count 0))
  1068.  
  1069. (defun irchat-handle-366 (prefix me chan msg) ; RPL_ENDOFNAMES
  1070.   (setq irchat-long-reply-count 0)
  1071.   (setq irchat-polling nil)
  1072.   (if (get (intern chan) 'init)
  1073.       (put (intern chan) 'init nil)))
  1074.  
  1075. (defun irchat-handle-367 (prefix me chan ban)
  1076.   (irchat-insert (format "Banned on %s: %s\n"
  1077.              (irchat-chan-virtual chan) ban) chan t))
  1078.  
  1079. (defun irchat-handle-368 (prefix me chan msg) ; BAN END
  1080.   nil)
  1081.  
  1082. (defun irchat-handle-369 (prefix me nick msg) ; WHOWAS
  1083.   nil)
  1084.  
  1085. (defun irchat-handle-371 (prefix me msg) ; RPL_INFO
  1086.   (irchat-insert0 (format "*** %s\n" msg)))
  1087.  
  1088. (defun irchat-handle-372 (prefix me msg) ; RPL_MOTD
  1089.   (irchat-insert0 (format "*** %s\n" msg)))
  1090.  
  1091. (defun irchat-handle-374 (prefix me msg) ; RPL_INFO END
  1092.   nil)
  1093.  
  1094. (defun irchat-handle-375 (prefix me msg) ; RPL_MOTD START
  1095.   nil)
  1096.  
  1097. (defun irchat-handle-376 (prefix me msg) ; RPL_MOTD END
  1098.   nil)
  1099.  
  1100. (defun irchat-handle-381 (prefix me msg) ; RPL_YOUREOPER
  1101.   ":server.name 381 me :Good afternoon, gentleman. I am a HAL 9000 computer."
  1102.   (irchat-insert0 (format "OPER: %s\n" msg)))
  1103.  
  1104. (defun irchat-handle-382 (prefix name file msg) ; RPL_REHASHING
  1105.   (irchat-insert0 (format "*** %s: %s %s\n" name msg file)))
  1106.  
  1107. (defun irchat-handle-391 (prefix me server time) ; RPL_TIME
  1108.   ":server.name 391 me server.name :Monday August 5 1996 -- 01:39 +09:00"
  1109.   (irchat-insert0 (format "Time: %s (%s)\n" time server)))
  1110.  
  1111. ;;;
  1112. ;;;  400 replies -- ERRORS
  1113. ;;; 
  1114. (defun irchat-handle-400s (number prefix me &rest args)
  1115.   "Generic handler for 4?? messages. This is called if no specific handler exists"
  1116.   (cond
  1117.    ((= (length args) 1)
  1118.     (irchat-insert0 (format "*** %s\n" (car args))))
  1119.    ((= (length args) 2)
  1120.     (irchat-insert0 (format "*** %s (%s)\n" (nth 1 args)
  1121.                 (irchat-chan-virtual (car args)))))
  1122.    ((= (length args) 3)
  1123.     (irchat-insert0 (format "*** %s %s (%s)\n" (car args) (nth 2 args)
  1124.                 (irchat-chan-virtual (nth 1 args)))))
  1125.    (t
  1126.     (message "IRCHAT: Strange %s reply" number))))
  1127.  
  1128. (defun irchat-handle-401 (prefix me nick msg) ; ERR_NOSUCHNICK
  1129.   ":server.name 401 me nick :No such nick/channel"
  1130.   (if (not (string= nick irchat-auto-whois-nick))
  1131.       (irchat-send "WHOWAS %s" nick)
  1132.     (setq irchat-auto-whois-nick "")))
  1133.  
  1134. (defun irchat-handle-402 (prefix me nick msg) ; ERR_NOSUCHSERVER
  1135.   ":server.name 402 me servername :No such server"
  1136.   (if (string-match "^[^.*]+$" nick)
  1137.       (if (not (string= nick irchat-auto-whois-nick))
  1138.       (irchat-insert0
  1139.        (format "*** Error: No such nick. (%s)\n" nick))
  1140.     (setq irchat-auto-whois-nick ""))
  1141.     (irchat-insert0
  1142.      (format "*** Error: No such server. (%s)\n" nick))))
  1143.  
  1144. (defun irchat-handle-403 (prefix me chan msg)
  1145.   (irchat-insert0 (format "*** %s (%s)\n" msg (irchat-chan-virtual chan))))
  1146.  
  1147. (defun irchat-handle-404 (prefix me chan msg)
  1148.   (irchat-insert0 (format "*** %s (%s)\n" msg (irchat-chan-virtual chan))))
  1149.  
  1150. (defun irchat-handle-405 (prefix me chan msg)
  1151.   (irchat-insert0 (format "*** %s (%s)\n" msg (irchat-chan-virtual chan))))
  1152.  
  1153. (defun irchat-handle-406 (prefix me nick msg)
  1154.   (irchat-insert0 (format "*** %s (%s)\n" msg nick)))
  1155.  
  1156. (defun irchat-handle-407 (prefix me nick msg)
  1157.   (irchat-insert0 (format "*** %s (%s)\n" msg nick)))
  1158.  
  1159. (defun irchat-handle-412 (prefix me msg)
  1160.   (message "IRCHAT: No text to send"))
  1161.  
  1162. (defun irchat-handle-421 (prefix me cmd msg)
  1163.   (irchat-insert0 (format "*** Unknown command (%s)\n" cmd)))
  1164.  
  1165. (defun irchat-handle-422 (prefix me msg)
  1166.   (irchat-insert0 (format "*** No message of the day in %s\n" prefix)))
  1167.  
  1168. (defun irchat-handle-432 (prefix me nick msg) ;;; ERR_ERRONICK?
  1169.   "Handle the 432 reply (erroneus nickname)"
  1170.   (save-excursion
  1171.     (set-buffer irchat-Command-buffer)
  1172.     ;; modified by simm@irc.fan.gr.jp, Mon, 20 Dec 1999 21:44:10 +0900
  1173.     (funcall irchat-pj-sound-error-function)
  1174.     (if irchat-no-configure-windows
  1175.     (setq irchat-nickname-erroneus t)
  1176.       (message
  1177.        "IRCHAT: Erroneus Nickname.  Choose a new one with %s."
  1178.        (substitute-command-keys "\\[irchat-Command-nickname]")))))
  1179.  
  1180. (defun irchat-handle-433 (prefix me nick msg) ;;; ERR_NICKNAMEINUSE
  1181.   "Handle the 433 reply (nickname already in use)"
  1182.   (save-excursion
  1183.     (set-buffer irchat-Command-buffer)
  1184.     (if irchat-no-configure-windows
  1185.     (setq irchat-nickname-already-in-use t)
  1186.       ;; modified by simm@irc.fan.gr.jp, Mon, 20 Dec 1999 21:44:10 +0900
  1187.       (funcall irchat-pj-sound-error-function)
  1188.       (message
  1189.        "IRCHAT: Nickname %s already in use.  Choose a new one with %s." nick
  1190.        (substitute-command-keys "\\[irchat-Command-nickname]")))))
  1191.  
  1192. (defun irchat-handle-437 (prefix me chan msg)
  1193.   "437 ERR_UNAVAILRESOURCE nick|chan :Nick/channel is temporarily unavailable"
  1194.   (irchat-insert0 (format "*** %s (%s)\n" msg (irchat-chan-virtual chan))))
  1195.  
  1196. (defun irchat-handle-441 (prefix me nick chan msg)
  1197.   "441 ERR_USERNOTINCHANNEL nick chan :They aren't on that channel"
  1198.   (irchat-insert0 (format "*** %s (%s/%s)\n"
  1199.               msg nick (irchat-chan-virtual chan))))
  1200.  
  1201. (defun irchat-handle-442 (prefix me chan msg)
  1202.   "442 ERR_NOTONCHANNEL chan :You're not on that channel"
  1203.   (irchat-insert0 (format "*** %s (%s)\n" msg (irchat-chan-virtual chan))))
  1204.  
  1205. (defun irchat-handle-451 (prefix &rest args)
  1206.   (if irchat-after-registration
  1207.       (irchat-insert0 (format "*** You have not registered.\n"))))
  1208.  
  1209. (defun irchat-handle-471 (prefix me chan msg) ; ERR_CHANNELISFULL
  1210.   ":server.name 471 me chan :Sorry, cannot join channel."
  1211.   (setq irchat-invited-channel chan)
  1212.   (irchat-insert0
  1213.    (format "*** Error: Sorry, channel %s is full.\n"
  1214.        (irchat-chan-virtual chan))))
  1215.  
  1216. (defun irchat-handle-472 (prefix me char msg) ; ERR_UNKNOWNMODE
  1217.   ":server.name 472 me char :is unknown mode char to me"
  1218.   (irchat-insert0
  1219.    (format "*** Error: '%s' %s.\n" char msg)))
  1220.  
  1221. (defun irchat-handle-473 (prefix me chan msg) ; ERR_INVITEONLYCHAN
  1222.   ":server.name 473 me chan :Sorry, cannot join channel."
  1223.   (setq irchat-invited-channel chan)
  1224.   (irchat-insert0
  1225.    (format "*** Error: Sorry, channel %s is invited only.\n"
  1226.        (irchat-chan-virtual chan))))
  1227.  
  1228. (defun irchat-handle-474 (prefix me chan msg) ; ERR_BANNEDFROMCHAN
  1229.   ":server.name 474 me chan :Sorry, cannot join channel."
  1230.   (setq irchat-invited-channel chan)
  1231.   (irchat-insert0
  1232.    (format "*** Error: Sorry, you are banned from channel %s.\n"
  1233.        (irchat-chan-virtual chan))))
  1234.  
  1235. (defun irchat-handle-475 (prefix me chan msg) ; ERR_BADCHANNELKEY
  1236.   ":server.name 475 me chan :Sorry, cannot join channel."
  1237.   (setq irchat-invited-channel chan)
  1238.   (irchat-insert0
  1239.    (format "*** Error: Sorry, incorrect key for channel %s.\n"
  1240.        (irchat-chan-virtual chan))))
  1241.  
  1242. (defun irchat-handle-477 (prefix me chan msg)
  1243.   ":server.name 477 me chan :Channel doesn't support modes"
  1244.   (irchat-insert0 (format "*** %s (%s)\n" msg
  1245.               (irchat-chan-virtual chan))))
  1246.  
  1247. (defun irchat-handle-484 (prefix me msg)
  1248.   ":server.name 484 me :Your connection is restricted!"
  1249.   (irchat-insert0 (format "*** %s\n" msg)))
  1250.  
  1251. ;;;
  1252. ;;;  500 replies -- ERRORS
  1253. ;;;
  1254. (defun irchat-handle-500s (number prefix me &rest args)
  1255.   "Generic handler for 5?? messages. This is called if no specific handler exists"
  1256.   (cond
  1257.    ((= (length args) 1)
  1258.     (irchat-insert0 (format "*** %s\n" (car args))))
  1259.    ((= (length args) 2)
  1260.     (irchat-insert0 (format "*** %s (%s)\n" (nth 1 args)
  1261.                 (irchat-chan-virtual (car args)))))
  1262.    ((= (length args) 3)
  1263.     (irchat-insert0 (format "*** %s %s (%s)\n" (car args) (nth 2 args)
  1264.                 (irchat-chan-virtual (nth 1 args)))))
  1265.    (t
  1266.     (message "IRCHAT: Strange %s reply" number))))
  1267.  
  1268. ;;;
  1269. ;;; answer to CTCP messages, no postprocessing
  1270. ;;;
  1271. (defun irchat-ctcp-msg (from to rest)
  1272.   "It's CTCP request, act on it."
  1273.   (let* (left now right message rest-of-line hook)
  1274.     (if (string-match "^\\([^\001]*\\)\001\\([^\001]*\\)\001\\(.*\\)" rest)
  1275.     ;; modified by simm@irc.fan.gr.jp, Sat, 18 Dec 1999 00:41:09 +0900
  1276.     ;; progn -> save-excursion
  1277.     (save-excursion
  1278.       ;; add by simm@irc.fan.gr.jp, Sat, 18 Dec 1999 00:54:18 +0900
  1279.       ;; for irchat-pj-sound
  1280.       (if irchat-pj-sound-when-ctcp
  1281.           (funcall irchat-pj-sound-ctcp-function))
  1282.       (setq left (matching-substring rest 1))
  1283.       (setq now (matching-substring rest 2))
  1284.       (setq right (matching-substring rest 3))
  1285.       (setq rest (concat left right))
  1286.       (if (string-match "^\\([^ ]*\\) \\(.*\\)" now)
  1287.           (progn
  1288.         (setq message (downcase (matching-substring now 1)))
  1289.         (setq rest-of-line (matching-substring now 2)))
  1290.         (if (string-match "^\\([^ ]*\\)" now)
  1291.         (progn
  1292.           (setq message (downcase (matching-substring now 1)))
  1293.           (setq rest-of-line nil))
  1294.           (progn
  1295.         (setq message "errmsg")
  1296.         (setq rest-of-line "Couldn't figure out what was said."))))
  1297.       (if (and (boundp (setq hook
  1298.                  (intern 
  1299.                   (concat "irchat-ctcp-" message "-hook"))))
  1300.            (eval hook)
  1301.            (eq (eval (list hook from to rest-of-line)) t))
  1302.           ;; If we have a hook, and it returns T, do nothing more
  1303.           nil
  1304.         ;; else call the handler
  1305.         (if (fboundp (setq fun (intern
  1306.                     (concat "irchat-ctcp-" message "-msg"))))
  1307.         (progn
  1308.           (eval (list fun from to rest-of-line))
  1309.           (if (not irchat-freeze)
  1310.               (irchat-scroll-if-visible
  1311.                (get-buffer-window (current-buffer)))))
  1312.           (progn
  1313.         (if (string-ci-equal to irchat-nickname)
  1314.             ;; return unknown error if it's sended to only me.
  1315.             (irchat-ctcp-reply from (format "ERRMSG %s :%s"
  1316.                             (upcase message)
  1317.                             (format irchat-ctcp-error-msg (upcase message)))))
  1318.         (irchat-insert (format "*** Unknown CTCP %s from %s to %s %s\n"
  1319.                        (upcase message) from to
  1320.                        (if rest-of-line
  1321.                        (if (string= rest-of-line "")
  1322.                            ""
  1323.                          (format "[%s]" rest-of-line))
  1324.                      ""))
  1325.                    to t))))))
  1326.     rest))
  1327.  
  1328. (defun irchat-ctcp-reply (receiver message)
  1329.   (irchat-send "NOTICE %s :\001%s\001" receiver message))
  1330.  
  1331. (defun irchat-ctcp-message (command from to)
  1332.   (message "CTCP %s from %s to %s" command from (irchat-chan-virtual to)))
  1333.  
  1334. ;; begin: modified by simm@irc.fan.gr.jp, Mon, 14 Jun 1999
  1335. ;;        move to irchat-pj-version-string.el, Tue, 12 Oct 1999
  1336. (defun irchat-ctcp-version-msg (from to rest)
  1337.   (irchat-ctcp-reply from (irchat-pj-set-version-string))
  1338.   (irchat-ctcp-message "VERSION" from to))
  1339. ;; end
  1340.  
  1341. (defun irchat-ctcp-userinfo-msg (from to rest)
  1342.   (irchat-ctcp-reply from (format "USERINFO :%s" irchat-ctcp-userinfo))
  1343.   (irchat-ctcp-message "USERINFO" from to))
  1344.  
  1345. (defun irchat-ctcp-action-msg (from to rest)
  1346.   (if rest
  1347.       (irchat-handle-privmsg2 from to (format "*** %s %s" from rest))
  1348.     (irchat-handle-privmsg2 from to (format "*** %s (nil)" from)))
  1349.   (irchat-ctcp-message "ACTION" from to))
  1350.  
  1351. ;; add by simm@irc.fan.gr.jp, Sun, 29 Aug 1999 22:56:28 +0900
  1352. (defun irchat-ctcp-caesar-msg (from to rest)
  1353.   (if rest
  1354.       (irchat-handle-privmsg2 from to (format "*** %s %s" from (irchat-pj-caesar-string rest)))
  1355.     (irchat-handle-privmsg2 from to (format "*** %s (nil)" from)))
  1356.   (irchat-ctcp-message "CAESAR" from to))
  1357.  
  1358. (defun irchat-ctcp-dcc-msg (from to rest)
  1359.   (irchat-dcc-request from to rest)
  1360.   (irchat-ctcp-message "DCC" from to))
  1361.  
  1362. (defun irchat-ctcp-time-msg (from to rest)
  1363.   (irchat-ctcp-reply from (format "TIME %s" (current-time-string)))
  1364.   (irchat-ctcp-message "TIME" from to))
  1365.  
  1366. (defun irchat-ctcp-ping-msg (from to rest)
  1367.   (irchat-ctcp-reply from (if rest (format "PING %s" rest) "PING"))
  1368.   (irchat-ctcp-message "PING" from to))
  1369.  
  1370. (defun irchat-ctcp-echo-msg (from to rest)
  1371.   (irchat-ctcp-reply from (if rest (format "ECHO %s" rest) "ECHO"))
  1372.   (irchat-ctcp-message "ECHO" from to))
  1373.  
  1374. (defun irchat-ctcp-clientinfo-msg (from to rest)
  1375.   (if (null rest)
  1376.       (irchat-ctcp-reply from
  1377.        (format "CLIENTINFO :%s :%s"
  1378.            (irchat-ctcp-list-string)
  1379.            "Use CLIENTINFO <COMMAND> to get more specific information"))
  1380.     (setq rest (upcase rest))
  1381.     (let (info)
  1382.       (setq info (get (intern rest) 'info))
  1383.       (if info
  1384.       (irchat-ctcp-reply from (concat "CLIENTINFO " rest " " info))
  1385.     (irchat-ctcp-reply from (concat "ERRMSG :CLIENTINFO: "
  1386.                     rest
  1387.                     " is not a valid command")))))
  1388.   (if (null rest)
  1389.       (irchat-ctcp-message "CLIENTINFO" from to)
  1390.     (irchat-ctcp-message (format "CLIENTINFO %s" rest) from to)))
  1391.     
  1392.  
  1393. (defvar irchat-ctcp-list nil)
  1394.  
  1395. (defun irchat-ctcp-list-string ()
  1396.   (let ((str "") (rest irchat-ctcp-list))
  1397.     (while rest
  1398.       (setq str (concat str (car rest) " "))
  1399.       (setq rest (cdr rest)))
  1400.     str))
  1401.  
  1402. (defsubst irchat-ctcp-add-clientinfo (command info)
  1403.   (setq command (upcase command))
  1404.   (setq irchat-ctcp-list (append irchat-ctcp-list (list command)))
  1405.   (put (intern command) 'info info))
  1406.  
  1407. (irchat-ctcp-add-clientinfo "ACTION"
  1408.                 "contains action descriptions for atmosphere")
  1409. (irchat-ctcp-add-clientinfo "CLIENTINFO"
  1410.                 "gives available CTCP commands")
  1411. (irchat-ctcp-add-clientinfo "CAESAR"
  1412.                 "sends message with X-ROT-5-13-47-48 encoding")
  1413. (irchat-ctcp-add-clientinfo "DCC"
  1414.                 "requests a Direct-Client-Connection")
  1415. (irchat-ctcp-add-clientinfo "ECHO"
  1416.                 "returns the arguments it receives")
  1417. (irchat-ctcp-add-clientinfo "ERRMSG"
  1418.                 "returns error messages")
  1419. (irchat-ctcp-add-clientinfo "PING"
  1420.                 "returns the arguments it receives")
  1421. (irchat-ctcp-add-clientinfo "TIME"
  1422.                 "tells you the time on the user's host")
  1423. (irchat-ctcp-add-clientinfo "USERINFO"
  1424.                 "returns user settable information")
  1425. (irchat-ctcp-add-clientinfo "VERSION"
  1426.                 "shows client type, version and environment")
  1427.  
  1428. ;;;
  1429. ;;; read CTCP messages from notice, no postprocessing done
  1430. ;;;
  1431.  
  1432. (defun irchat-ctcp-notice (prefix rest)
  1433.   "CTCP notice."
  1434.   (let* (message rest-of-line hook to) 
  1435.     (if (string-match "\\([^ ]+\\) :" rest)
  1436.     (setq to (matching-substring rest 1)))
  1437.     (if (string-match "\001\\([^ ]*\\) :?\\(.*\\)\001" rest)
  1438.       (setq message (downcase (matching-substring rest 1))
  1439.         rest-of-line (matching-substring rest 2))
  1440.       (if (string-match "\001\\([^ ]*\\)\001" rest)
  1441.       (setq message (downcase (matching-substring rest 1))
  1442.         rest-of-line nil)
  1443.     (setq message "errmsg"
  1444.           rest-of-line "Couldn't figure out what was said.")))
  1445.     (if (and (boundp (setq hook
  1446.                (intern (concat "irchat-ctcp-" message "-notice-hook"))))
  1447.          (eval hook)
  1448.          (eq (eval (list hook prefix rest-of-line)) t))
  1449.     ;; If we have a hook, and it returns T, do nothing more
  1450.     nil
  1451.       ;; else call the handler
  1452.       (if (fboundp (setq fun (intern
  1453.                   (concat "irchat-ctcp-" message "-notice"))))
  1454.       (progn
  1455.         (eval (list fun prefix rest-of-line))
  1456.         (if (not irchat-freeze)
  1457.         (irchat-scroll-if-visible
  1458.          (get-buffer-window (current-buffer)))))
  1459.     (irchat-insert0 (format "*** Unknown CTCP Reply %s from %s to %s %s\n"
  1460.                 (upcase message) prefix to
  1461.                 (if rest-of-line
  1462.                     (format "[%s]" rest-of-line)
  1463.                   "")))))))
  1464.  
  1465.  
  1466. (defun irchat-ctcp-version-notice (prefix rest)  
  1467.   (if rest
  1468.       (if (string-match "^\\(.*\\)\\s *:[^:]*$" rest)
  1469.       (irchat-insert0 (format "VERSION@%s: %s\n" prefix (matching-substring rest 1)))
  1470.     (irchat-insert0 (format "VERSION@%s: %s\n" prefix rest)))
  1471.     (message (format "Empty CTCP version notice from \"%s\"." prefix))))
  1472.  
  1473. (defun irchat-ctcp-version-notice-old (prefix rest)  
  1474.   (if rest
  1475.       (if (string-match "^\\([^:]*\\):\\(.*\\)" rest)
  1476.       (irchat-insert0 (format "VERSION@%s: %s\n" prefix 
  1477.                  (matching-substring rest 1)))
  1478.     (if (string-match "^\\([^ ]*\\) \\([^ ]*\\) \\([^ ]*\\) \\(.*\\)" rest)
  1479.         (irchat-insert0 (format "VERSION@%s: %s\n" prefix
  1480.                     (format "%s %s for %s: %s" 
  1481.                         (matching-substring rest 1)
  1482.                         (matching-substring rest 2)
  1483.                         (matching-substring rest 3)
  1484.                         (matching-substring rest 4))))
  1485.       (irchat-insert0 (format "VERSION@%s: %s\n" prefix rest))))
  1486.     (message (format "Empty CTCP version notice from \"%s\"." prefix))))
  1487.  
  1488. (defun irchat-ctcp-clientinfo-notice (prefix rest)
  1489.   (irchat-insert0 (format "CLIENTINFO@%s: %s\n" prefix rest)))
  1490.  
  1491. (defun irchat-ctcp-userinfo-notice (prefix rest)  
  1492.   (irchat-insert0 (format "USERINFO@%s: %s\n" prefix rest)))
  1493.  
  1494. (defun irchat-ctcp-finger-notice (prefix rest)
  1495.   (irchat-insert0 (format "FINGER@%s: %s\n" prefix rest)))
  1496.  
  1497. (defun irchat-ctcp-time-notice (prefix rest)  
  1498.   (irchat-insert0 (format "TIME@%s: %s\n" prefix rest)))
  1499.  
  1500. (defun irchat-ctcp-echo-notice (prefix rest)
  1501.   (irchat-insert0 (format "ECHO@%s: %s\n" prefix rest)))
  1502.  
  1503. (defun irchat-ctcp-ping-notice (prefix rest)
  1504.   (let (to (time rest))
  1505.     (if (string-match "\\([^ ]+\\) \\(.*\\)" rest)
  1506.     (progn
  1507.       (setq time (matching-substring rest 1))
  1508.       (setq to (matching-substring rest 2))))
  1509.     (if (= 0 (string-to-int (or time "0")))
  1510.     (irchat-insert0 (format "PING@%s: %s\n" prefix (or time "nothing")))
  1511.       (let ((diff (- (irchat-current-time) (string-to-int time))))
  1512.     (while (< diff 0)
  1513.       (setq diff (+ diff 86400)))
  1514.     (irchat-insert (format "PING@%s: %s second%s\n" prefix diff
  1515.                    (if (< diff 2) "" "s"))
  1516.                to t)))))
  1517.  
  1518. (defun irchat-ctcp-errmsg-notice (prefix rest)  
  1519.   (irchat-insert0 (format "ERRMSG@%s: %s\n" prefix rest)))
  1520.  
  1521. (defun irchat-ctcp-comment-notice (from rest)  
  1522.   (message (format "CTCP COMMENT query from %s." from)))
  1523.  
  1524.  
  1525. ;;;
  1526. ;;; decode and encode of binary data
  1527. ;;;
  1528. (defun irchat-quote-decode (string-to-decode)
  1529.   (interactive)
  1530.   (save-excursion
  1531.     (set-buffer (get-buffer-create "*IRC DECODE*"))
  1532.     (delete-region (point-min) (point-max))
  1533.     (insert string-to-decode)
  1534.     (goto-char (point-min))
  1535.     (replace-string "\\\\" "\\")
  1536.     (goto-char (point-min))
  1537.     (replace-string "\\a" "\001")
  1538.     (goto-char (point-min))
  1539.     (replace-string "\\n" "\n")
  1540.     (goto-char (point-min))
  1541.     (replace-string "\\r" "\r")
  1542.     (setq string-to-decode (buffer-substring (point-min) (point-max)))
  1543.     string-to-decode))
  1544.  
  1545. (defun irchat-quote-encode (string)
  1546.   (interactive)
  1547.   (save-excursion
  1548.     (set-buffer (get-buffer-create "*IRC ENCODE*"))
  1549.     (delete-region (point-min) (point-max))
  1550.     (insert string)
  1551.     (goto-char (point-min))
  1552.     (while (search-forward "\\" nil 1)
  1553.       (insert "\\"))
  1554.     (goto-char (point-min))
  1555.     (while (search-forward "\001" nil 1)
  1556.       (delete-char -1)
  1557.       (insert "\\a"))
  1558.     (goto-char (point-min))
  1559.     (while (search-forward "\000" nil 1)
  1560.       (delete-char -1)
  1561.       (insert "\\0"))
  1562.     (goto-char (point-min))
  1563.     (while (search-forward "\n" nil 1)
  1564.       (delete-char -1)
  1565.       (insert "\\n"))
  1566.     (goto-char (point-min))
  1567.     (while (search-forward "\r" nil 1)
  1568.       (delete-char -1)
  1569.       (insert "\\r"))
  1570.     (setq string (buffer-substring (point-min) (point-max)))
  1571.     string))
  1572.  
  1573.  
  1574. (defun irchat-current-time ()
  1575.   (let* ((string (current-time-string))
  1576.          (day (string-to-int (substring string 8 10)))
  1577.          (hour (string-to-int (substring string 11 13)))
  1578.          (min  (string-to-int (substring string 14 16)))
  1579.          (sec  (string-to-int (substring string 17 19))))
  1580.     (+ sec (* 60 min) (* 3600 hour) (* 86400 day))))
  1581.  
  1582. (defun irchat-past-time (second)
  1583.   (let* ((string (current-time-string))
  1584.          (day (string-to-int (substring string 8 10)))
  1585.          (hour (string-to-int (substring string 11 13)))
  1586.          (min  (string-to-int (substring string 14 16)))
  1587.          (sec  (string-to-int (substring string 17 19))))
  1588.     (if (stringp second)
  1589.     (setq second (string-to-int second)))
  1590.     (setq second (- (+ sec (* 60 min) (* 3600 hour) (* 86400 day)) second))
  1591.     (if (< second 0) nil (irchat-convert-seconds2 second))))
  1592.  
  1593.  
  1594. (defun irchat-convert-seconds (time)
  1595.   "Convert seconds to printable string."
  1596.   (if (null time) (setq time 0))
  1597.   (let* ((seconds (if (stringp time) (string-to-int time) time))
  1598.      (minutes (/ seconds 60))
  1599.      (seconds (if minutes (% seconds 60) seconds))
  1600.      (hours (/ minutes 60))
  1601.      (minutes (if hours (% minutes 60) minutes))
  1602.      (days (/ hours 24))
  1603.      (hours (if days (% hours 24) hours))
  1604.      (ds (and (/= 0 days)
  1605.           (format "%d day%s, " days
  1606.               (if (> days 1) "s" ""))))
  1607.      (hs (and (/= 0 hours)
  1608.           (format "%d hour%s, " hours
  1609.               (if (> hours 1) "s" ""))))
  1610.      (ms (and (/= 0 minutes)
  1611.           (format "%d minute%s " minutes
  1612.               (if (> minutes 1) "s" ""))))
  1613.      (ss (format "%d seconds" seconds)))
  1614.     (concat ds hs ms (if seconds ss ""))))
  1615.  
  1616.  
  1617. (defun irchat-convert-seconds2 (time)
  1618.   "Convert seconds to printable string."
  1619.   (if (null time) (setq time 0))
  1620.   (let* ((seconds (if (stringp time) (string-to-int time) time))
  1621.      (minutes (/ seconds 60))
  1622.      (seconds (if minutes (% seconds 60) seconds))
  1623.      (hours (/ minutes 60))
  1624.      (minutes (if hours (% minutes 60) minutes))
  1625.      (days (/ hours 24))
  1626.      (hours (if days (% hours 24) hours)))
  1627.     (format "%d%s %02d:%02d:%02d" days
  1628.         (if (= days 1) "st"
  1629.           (if (= days 2) "nd"
  1630.         (if (= days 3) "rd" "th")))
  1631.         hours minutes seconds)))
  1632.  
  1633.  
  1634. (defun irchat-msg-from-ignored (prefix chan msg)
  1635.   (save-excursion
  1636.     (let ((buf (current-buffer)))
  1637.       (set-buffer irchat-IGNORED-buffer)
  1638.       (goto-char (point-max))
  1639.       (insert (format "%s::%s %s\n" prefix chan msg))
  1640.       (set-buffer buf)
  1641.       t)))
  1642.  
  1643. (provide 'irchat-handle)
  1644.