X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Friece-doctor.el;h=ee7068b81294afd0a741583d035cd80de3aa5636;hb=c87b8b5e7dcba14804b7f0bee453a0a4093f3e85;hp=7232d1dcbf2490bd8ee2be22c4e04b79c9f24316;hpb=e0cfa2d7a8e690e22a06bdd506dcac1bf9b3a31e;p=elisp%2Friece.git diff --git a/lisp/riece-doctor.el b/lisp/riece-doctor.el index 7232d1d..ee7068b 100644 --- a/lisp/riece-doctor.el +++ b/lisp/riece-doctor.el @@ -1,4 +1,4 @@ -;;; riece-doctor.el --- "become a psychotherapist" add-on +;;; riece-doctor.el --- pretend to be a psychotherapist ;; Copyright (C) 1998-2003 Daiki Ueno ;; Author: Daiki Ueno @@ -18,15 +18,12 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Commentary: -;; This add-on allows you to become a psychotherapist. - -;; To use, add the following line to your ~/.riece/init.el: -;; (add-to-list 'riece-addons 'riece-doctor) +;; NOTE: This is an add-on module for Riece. ;;; Code: @@ -36,27 +33,34 @@ (require 'riece-server) (defgroup riece-doctor nil - "Interface to doctor.el" + "Interface to doctor.el." :prefix "riece-" :group 'riece) -(defcustom riece-doctor-hello-regexp "^, doctor" +(defcustom riece-doctor-hello-regexp "^,doctor$" "Pattern of string patients start consultation." :type 'string :group 'riece-doctor) -(defcustom riece-doctor-bye-regexp "^, bye doctor" +(defcustom riece-doctor-bye-regexp "^,doctor bye$" "Pattern of string patients end consultation." :type 'string :group 'riece-doctor) (defvar riece-doctor-patients nil) +(defconst riece-doctor-description + "Pretend to be a psychotherapist.") + +(put 'riece-doctor 'riece-addon-default-disabled t) + (autoload 'doctor-mode "doctor") (autoload 'doctor-read-print "doctor") (defun riece-doctor-buffer-name (user) - (concat " *riece-doctor*" (riece-format-identity user))) + (concat " *riece-doctor*" + (riece-format-identity + (riece-make-identity user riece-server-name)))) (defun riece-doctor-reply (target string) (riece-display-message @@ -67,56 +71,62 @@ (riece-send-string (format "NOTICE %s :%s\r\n" target string))) (defun riece-doctor-after-privmsg-hook (prefix string) - (let* ((user (riece-make-identity (riece-prefix-nickname prefix) - riece-server-name)) - (parameters (riece-split-parameters string)) - (targets (split-string (car parameters) ",")) - (message (nth 1 parameters))) - (if (string-match riece-doctor-hello-regexp message) - (if (riece-identity-member user riece-doctor-patients) - (riece-doctor-reply - (car targets) - (format "%s: You are already talking with me." - (riece-format-identity user t))) - (save-excursion - (set-buffer (get-buffer-create (riece-doctor-buffer-name user))) - (erase-buffer) - (doctor-mode)) - (setq riece-doctor-patients (cons user riece-doctor-patients)) - (riece-doctor-reply - (car targets) - (format - "%s: I am the psychotherapist. Please, describe your problems." - (riece-format-identity user t)))) - (if (string-match riece-doctor-bye-regexp message) - (let ((pointer (riece-identity-member user riece-doctor-patients))) - (when pointer - (kill-buffer (riece-doctor-buffer-name user)) - (setq riece-doctor-patients (delq (car pointer) - riece-doctor-patients)) - (riece-doctor-reply - (car targets) - (format "%s: Good bye." (riece-format-identity user t))))) - (if (riece-identity-member user riece-doctor-patients) - (let (string) + (if (get 'riece-doctor 'riece-addon-enabled) + (let* ((user (riece-prefix-nickname prefix)) + (parameters (riece-split-parameters string)) + (targets (split-string (car parameters) ",")) + (message (nth 1 parameters))) + (if (string-match riece-doctor-hello-regexp message) + (if (riece-identity-member user riece-doctor-patients t) + (riece-doctor-reply + (car targets) + (format "%s: You are already talking with me." user)) (save-excursion - (set-buffer (get-buffer (riece-doctor-buffer-name user))) - (goto-char (point-max)) - (insert message "\n") - (let ((point (point))) - (doctor-read-print) - (setq string (buffer-substring (1+ point) (- (point) 2)))) - (with-temp-buffer - (insert string) - (subst-char-in-region (point-min) (point-max) ?\n ? ) - (setq string (buffer-string)))) + (set-buffer (get-buffer-create + (riece-doctor-buffer-name user))) + (erase-buffer) + (doctor-mode)) + (setq riece-doctor-patients (cons user riece-doctor-patients)) (riece-doctor-reply (car targets) - (format "%s: %s" (riece-format-identity user t) string)))))))) + (format + "%s: I am the psychotherapist. \ +Please, describe your problems." + user))) + (if (string-match riece-doctor-bye-regexp message) + (let ((pointer (riece-identity-member user + riece-doctor-patients t))) + (when pointer + (kill-buffer (riece-doctor-buffer-name user)) + (setq riece-doctor-patients (delq (car pointer) + riece-doctor-patients)) + (riece-doctor-reply + (car targets) + (format "%s: Good bye." user)))) + (if (riece-identity-member user riece-doctor-patients t) + (let (string) + (save-excursion + (set-buffer (get-buffer (riece-doctor-buffer-name user))) + (goto-char (point-max)) + (insert message "\n") + (let ((point (point))) + (doctor-read-print) + (setq string (buffer-substring (1+ point) + (- (point) 2)))) + (with-temp-buffer + (insert string) + (subst-char-in-region (point-min) (point-max) ?\n ? ) + (setq string (buffer-string)))) + (riece-doctor-reply + (car targets) + (format "%s: %s" user string))))))))) (defun riece-doctor-insinuate () (add-hook 'riece-after-privmsg-hook 'riece-doctor-after-privmsg-hook)) +(defun riece-doctor-uninstall () + (remove-hook 'riece-after-privmsg-hook 'riece-doctor-after-privmsg-hook)) + (provide 'riece-doctor) ;;; riece-doctor.el ends here