home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 2 / amigaformatcd02.iso / comms / netsoftware / irchat24.lha / irchat24 / irchat.lha / elisp / irchat / irchat-hooks.el < prev    next >
Encoding:
Text File  |  1994-02-23  |  5.8 KB  |  195 lines

  1. ;;;  $Id: irchat-hooks.el,v 1.4 1993/10/07 12:53:43 tmo Exp $
  2. ;;;
  3. ;;;  Example hooks to customize irchat. These are copy-pasted from 2.2beta
  4. ;;;  and modified a bit. The might or might not work. The general idea is 
  5. ;;;  that if hook returns nil, the appropriate handler is called after the 
  6. ;;;  hook. Any other value returned causes further processing of message 
  7. ;;;  cancelled.
  8.  
  9. (provide 'irchat-hooks)
  10.  
  11. (defun string-memberp (thing list)
  12.   "Dummy case insensitive function to check if string THING is a member of
  13. LIST"
  14.   (cond ((null list) nil)
  15.         ((string-equal (downcase thing) (downcase (car list))) t)
  16.         (t (string-memberp thing (cdr list)))))
  17.  
  18. ;;;
  19. ;;;
  20. ;;;
  21. (defvar irchat-watched-nicks '("God" "Pope" "Paavi" "JuhaF|hr"))
  22.  
  23.  
  24. (defun irchat-join-hook (nick channel)
  25.   (cond
  26.    ((string= "#report" channel)
  27.     t)
  28.    ;; greet persons at current channel
  29.    ((and (string-memberp nick irchat-watched-nicks)
  30.          (string= irchat-current-channel channel))
  31.     (progn
  32.       (beep)
  33.       (irchat-Command-send-message (format "%s: et ole kuitenkaan aito" nick))
  34.       (message "%s has joined channel %s" nick channel)
  35.       nil))
  36.    (t nil)))
  37.  
  38.  
  39. (defun irchat-part-hook (prefix rest)
  40.   (if (string= "#report" rest)
  41.       t nil))
  42.  
  43.  
  44. (setq irchat-join-hook (function irchat-join-hook))
  45. (setq irchat-part-hook (function irchat-part-hook))
  46.  
  47.  
  48. ;;;
  49. ;;;
  50. ;;;
  51. (defun irchat-privmsg-hook (prefix rest)
  52.   (if (and irchat-broadcast-partner (not irchat-chat-partner))
  53.       (progn
  54.     (if (eq prefix nil)
  55.         (setq prefix "")
  56.       (setq prefix (concat "<" prefix "> ")))
  57.     (if (and (string= prefix "")
  58.          (string-match (format "^%s.*" 
  59.                        (format irchat-format-string1)) rest))
  60.         nil
  61.       (progn 
  62.         (string-match "[^ ]* :\\(.*\\)" rest)
  63.         (irchat-send "PRIVMSG %s :%s%s" irchat-broadcast-partner prefix
  64.              (matching-substring rest 1))))
  65.     nil)
  66.     nil))
  67.  
  68.  
  69. (defun irchat-msg-hook (prefix rest)
  70.   (if (and irchat-broadcast-partner (not irchat-chat-partner))
  71.       (progn
  72.     (if (eq prefix nil)
  73.         (setq prefix "")
  74.       (setq prefix (concat "<" prefix "> ")))
  75.     (if (and (string= prefix "")
  76.          (string-match (format "^%s.*" 
  77.                        (format irchat-format-string1)) rest))
  78.         nil
  79.       (progn 
  80.         (string-match "[^ ]* :\\(.*\\)" rest)
  81.         (irchat-send "PRIVMSG %s :%s%s" irchat-broadcast-partner prefix
  82.              (matching-substring rest 1))))
  83.     nil)
  84.     nil))
  85.         
  86.  
  87. (setq irchat-privmsg-hook (function irchat-privmsg-hook))
  88. (setq irchat-msg-hook (function irchat-msg-hook))
  89.  
  90. ;;;
  91. ;;; following stuff stolen from nAm (modified a bit), untested, 
  92. ;;; use on your own risk
  93. ;;;
  94. (define-key irchat-Command-mode-map "\C-c\C-a"
  95.   '(lambda (&optional private)
  96.      "Send action ctcp - if on empty line, ask for the message"
  97.      (interactive
  98.       (if current-prefix-arg
  99.       (list current-prefix-arg)
  100.     nil))
  101.      (let ((completion-ignore-case t) message start stop)
  102.        (if private
  103.        (setq irchat-privmsg-partner
  104.          (irchat-completing-default-read 
  105.           "To whom: "
  106.           (append irchat-nick-alist irchat-channel-alist)
  107.           '(lambda (s) t) 
  108.           nil irchat-privmsg-partner)))
  109.        (beginning-of-line)
  110.        (setq start (point))
  111.        (end-of-line)
  112.        (setq stop (point))
  113.        (if (eq start stop)
  114.        (setq message (read-string "Action: "))
  115.      (setq message (buffer-substring start stop))
  116.      (irchat-next-line 1))
  117.        (irchat-send "PRIVMSG %s :ACTION %s"
  118.             (if private
  119.             irchat-privmsg-partner
  120.               irchat-current-channel)
  121.             message)
  122.        (if private
  123.        (irchat-own-message (format "*** Action to %s: %s %s"
  124.                        irchat-privmsg-partner irchat-nickname
  125.                        message))
  126.      (irchat-own-message (format "*** Action: %s %s" irchat-nickname
  127.                      message))))))
  128.  
  129. (setq irchat-Startup-hook '(lambda ()
  130.                  (irchat-Command-message "eu-oper" "invite")
  131.                              (irchat-Command-message "Arska" "kutsu")
  132.                  (setq scroll-step 1)))
  133.  
  134. (setq irchat-invite-hook '(lambda (prefix rest)
  135.                             (if (string-match " \\([^ ]+\\)" rest)
  136.                                 (let ((chnl (matching-substring rest 1)))
  137.                   (cond 
  138.                    ((string= prefix "Arska")
  139.                     (irchat-Command-join chnl))
  140.                    ((string= prefix "Eu-Oper")
  141.                     (let ((curchnl irchat-current-channel))
  142.                       (irchat-Command-join chnl)
  143.                       (if curchnl
  144.                       (irchat-Command-join curchnl)))))))
  145.                 nil))
  146.  
  147. ;;;
  148. ;;;  to make a bot....
  149. ;;;
  150. (defvar irchat-arska-mode nil)
  151.  
  152. (defun irchat-ownjoin-hook (prefix rest)
  153.   (if (and (string-match "#eu-opers" rest)
  154.        (string-match irchat-nickname prefix))
  155.       (irchat-Command-message "eu-oper" "op"))
  156.   (if (string-match "kuolepois" prefix)
  157.       (setq irchat-arska-mode nil)
  158.     (if (string-match "namarska" prefix)
  159.     (setq irchat-arska-mode t)))
  160.   (if (and irchat-arska-mode
  161.        (string-match "\\(.fi\\)" irchat-userathost)
  162.        (= (match-end 0) (match-end 1)))
  163.       (irchat-send (format "mode %s +o %s" rest prefix)))
  164.   (if (and (string-match "#report" rest)
  165.        (not (string-match prefix irchat-nickname)))
  166.       (message "%s (%s) has joined this channel%s"
  167.            prefix irchat-userathost
  168.            (if (string= (or irchat-current-channel "") rest) ""
  169.          (format " (%s)" rest)))
  170.     nil))
  171.  
  172. (defun irchat-ownpart-hook (prefix rest)
  173.   (if (and (string-match "#report" rest)
  174.        (not (string-match prefix irchat-nickname)))
  175.       (message "%s has left this channel%s"
  176.            prefix
  177.            (if (string= (or irchat-current-channel "") rest) ""
  178.          (format " (%s)" rest)))
  179.     nil))
  180.  
  181. (defun irchat-ownquit-hook (prefix rest)
  182.   (if (and (string-match "#report" rest)
  183.        (not (string-match prefix irchat-nickname)))
  184.       (message "%s has left IRC%s"
  185.            prefix
  186.            (if (= 0 (length rest)) "" (format " (%s)" rest)))
  187.     nil))
  188.  
  189. (setq irchat-join-hook (function irchat-ownjoin-hook))
  190. (setq irchat-part-hook (function irchat-ownpart-hook))
  191. (setq irchat-quit-hook (function irchat-ownquit-hook))
  192.  
  193. ;;;
  194. ;;;  eof
  195. ;;;