;; emchat-doctor.el --- Let ICQ users psycho-analize themselves ;; Copyright (C) 2005 - 2011 Steve Youngs ;; Author: Steve Youngs ;; Maintainer: Steve Youngs ;; Created: <2005-09-14> ;; Homepage: http://www.emchat.org/ ;; Keywords: ICQ ;; This file is part of EMchat. ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; ;; 3. Neither the name of the author nor the names of any contributors ;; may be used to endorse or promote products derived from this ;; software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Commentary: ;; ;; Inspired by riece-doctor.el, where much of this was stolen from. :-) ;;; Todo: ;; ;; ;;; Code: (autoload 'doctor-mode "doctor") (autoload 'doctor-read-print "doctor") (defgroup emchat-doctor nil "Let ICQ users psycho-analyze themselves." :prefix "emchat-" :group 'emchat) (defcustom emchat-doctor-enabled-flag nil "When non-nil, the doctor is in." :type 'boolean :group 'emchat-doctor) (defcustom emchat-doctor-begin-string ",,doctor" "When this is received as a msg, start the doctor." :type 'string :group 'emchat-doctor) (defcustom emchat-doctor-end-string ",,doctor quit" "When this is received as a msg, end the doctor." :type 'string :group 'emchat-doctor) (defcustom emchat-doctor-hello-string "Hello, I am your therapist. To end our session today, just say \",,doctor quit\". Now, what seems to be the problem, today?" "Initial greeting from the EMchat Doctor." :type 'string :group 'emchat-doctor) (defcustom emchat-doctor-goodbye-string "Thank you for coming to see me today. To summarise: basically, you're nuts. My invoice will arrive in the mail shortly, unless you are suffering from a split personality disorder, in that case 2 invoices will arrive. Goodbye, and please don't operate any heavy machinery for a while." "String sent when the therapy session ends." :type 'string :group 'emchat-doctor) ;;; Internal variables (defvar emchat-doctor-patients nil "List of people who are talking to the doctor.") (defun emchat-doctor-buffer-name (alias) (concat " *emchat-doctor--" alias "*")) (defun emchat-doctor-reply (message alias) (emchat-v8-send-simple-message emchat-ctx (emchat-numeric-uin (emchat-alias-uin alias)) message) (emchat-log-outgoing alias ">>> : %s" message)) (defun emchat-doctor (message alias) (if (equal message emchat-doctor-end-string) (progn (setq emchat-doctor-patients (remove alias emchat-doctor-patients)) (when (buffer-live-p (emchat-doctor-buffer-name alias)) (kill-buffer (emchat-doctor-buffer-name alias))) (emchat-doctor-reply emchat-doctor-goodbye-string alias)) (if (equal message emchat-doctor-begin-string) (emchat-doctor-reply "You are already talking to me." alias) (set-buffer (get-buffer-create (emchat-doctor-buffer-name alias))) (doctor-mode) (insert message "\n") (let ((point (point)) reply) (doctor-read-print) (setq reply (buffer-substring (1+ point) (- (point) 2))) (emchat-doctor-reply reply alias))))) (provide 'emchat-doctor) ;;; emchat-doctor.el ends here