From: <dm...@dm...> - 2002-05-05 19:41:21
|
Here is a version that you can talk to yourself. I had to add a new hook, for which the patch is: Index: erc.el =================================================================== RCS file: /cvsroot/erc/erc/erc.el,v retrieving revision 1.254 diff -u -r1.254 erc.el --- erc.el 2 May 2002 21:12:33 -0000 1.254 +++ erc.el 5 May 2002 19:37:37 -0000 @@ -529,6 +529,13 @@ :group 'erc-hooks :type 'hook) +(defcustom erc-send-completed-hook nil + "Hook called after a message has successfully been sent to the +server. The single argument to the functions is the unmodified string +which the local user typed." + :group 'erc-hooks + :type 'hook) + (defvar erc-insert-this t "Insert the text into the target buffer or not. Functions on `erc-insert-pre-hook' can set this variable to nil @@ -5124,7 +5131,8 @@ (set-buffer old-buf) (erc-display-prompt) (when (featurep 'emacspeak) - (emacspeak-auditory-icon 'select-object))))))) + (emacspeak-auditory-icon 'select-object)) + (run-hook-with-args 'erc-send-completed-hook str)))))) (defun erc-send-paragraph (&optional force) The robot code is now: (autoload 'erc-select "erc" nil t) (eval-after-load "erc" '(progn (add-hook 'erc-server-PRIVMSG-hook 'dme:erc-robot-remote t) (add-hook 'erc-send-completed-hook 'dme:erc-robot-local t) )) (if (featurep 'xemacs) (defun dme:replace-regexp-in-string (regexp rep string &optional fixedcase literal subexp start) (replace-in-string string regexp rep literal)) (defalias 'dme:replace-regexp-in-string 'replace-regexp-in-string)) (defun dme:erc-doctor (args) (let* ((dbuf "*doctor*") (docbuf (get-buffer dbuf)) outpoint res) (if (not docbuf) (progn (doctor) (setq docbuf (get-buffer dbuf)) (bury-buffer docbuf))) (save-excursion (set-buffer docbuf) (goto-char (point-max)) (insert args) (goto-char (point-max)) (setq outpoint (point)) (doctor-ret-or-read 1) (doctor-ret-or-read 1) (goto-char outpoint) (re-search-forward "^.") (setq outpoint (- (point) 1)) (re-search-forward "^$") (dme:replace-regexp-in-string "\n" " " (buffer-substring outpoint (point))) ))) (setq dme:erc-robot-commands '( ("cmds" (lambda (args) (concat "commands available: " (mapconcat (lambda (e) (car e)) dme:erc-robot-commands " ")))) ("hello" (lambda (args) "hello to you too !")) ("zippy" (lambda (args) (dme:replace-regexp-in-string "\n" " " (yow)))) ("music" (lambda (args) (concat "now playing: " (let ((track (dme:now-playing))) 2 (if track track "nothing."))))) ("echo" (lambda (args) args)) ("doctor" dme:erc-doctor) ("version" (lambda (args) (erc-version))) )) (defface dme:erc-robot-face '((t (:foreground "yellow"))) "ERC face used for your robot's output." :group 'erc-faces) (defun dme:erc-robot-remote (proc parsed) "Implements a simple robot for erc. Messages to the robot are of the form: \"nick: !command args\", where: nick - the nickname of the user who is the target of the command, command - the specific command, args - arguments to the command (optional)." (let* ((sspec (aref parsed 1)) (nick (nth 0 (erc-parse-user sspec))) (tgt (aref parsed 2)) (msg (aref parsed 3))) (dme:erc-robot-command proc nick tgt msg)) nil) (defun dme:erc-robot-local (str) "Funnel text typed by the local user to the local robot." (dme:erc-robot-command erc-process (erc-current-nick) (buffer-name) str)) (defun dme:erc-robot-command (proc from tgt msg) "Robot worker." (let ((me (erc-current-nick))) (if (and dme:erc-robot-commands (string-match (concat "^" (regexp-quote me) ": !\\([^ ]+\\) ?\\(.*\\)") msg)) ; this is a robot command to me. (let* ((cmd (substring msg (match-beginning 1) (match-end 1))) (args (substring msg (match-beginning 2))) (l (assoc cmd dme:erc-robot-commands)) reply) (setq reply (concat from ": " (if l (funcall (cadr l) args) (concat "unknown command: " cmd ": try \"cmds\"")))) (erc-log reply) (save-excursion (set-buffer (erc-get-buffer tgt proc)) (let ((inhibit-read-only t) p) (goto-char (point-max)) (setq p (re-search-backward (erc-prompt))) (insert (erc-format-timestamp) "<" me "> ") (when (string-match "[\n]+$" reply) (setq reply (substring reply 0 (match-beginning 0)))) (erc-put-text-property 0 (length reply) 'face 'dme:erc-robot-face reply) (insert reply "\n") (save-excursion (save-match-data (save-restriction (narrow-to-region p (point)) (run-hook-with-args 'erc-send-modify-hook) (run-hook-with-args 'erc-send-post-hook)))) (set-marker (process-mark erc-process) (point)) (set-marker erc-insert-marker (point)) (goto-char (point-max)) (erc-process-input-line (concat reply "\n")))))))) |