;;; iChat Bot ;;; 5/20/05 Alexander Repenning, Unversity of Colorado (in-package :ccl) ;; (require "http://agentsheets.com/lisp/eval-apple-script.lisp") (defun GET-ICHAT-ACCOUNT-NAME-FROM-ID (Id) " in: Id symbol; Return the account name as it appears in the buddy list and as it is used in the chat window title." (eval-apple-script (format nil " tell application \"iChat\" set AccountName to name of first account where id is \"~A\" end tell" Id))) (defun ICHAT-WINDOW-TITLE (Id) (format nil "Chat with ~A" (get-ichat-account-name-from-id Id))) (defun ICHAT-FIRST-DOCUMENT-WINDOW-TITLE () (eval-apple-script (format nil " tell application \"iChat\" name of first document end tell"))) (defun GET-ICHAT-TEXT (&optional (Name 1)) (eval-apple-script (format nil " tell application \"System Events\" tell process \"iChat\" tell window \"~A\" tell scroll area 1 get value of text area 1 end tell end tell end tell end tell" Name))) (defun PARSE-LINES (String) (let ((Lines nil)) (with-input-from-string (Input String) (loop (push (with-output-to-string (Output) (loop (let ((Char (read-char Input nil nil))) (unless Char (return-from parse-lines (reverse Lines))) ;; done? (case Char (#.#\Linefeed (return)) (t (princ Char Output)))))) Lines))))) (defun RUN-ICHAT-ROBOT (Id) Ê ;; kibits while talking to ohters Ê ;; if there is some Lisp stuff - string starting with "(" - then evaluate it and send result in message (let ((Text "") (Window-Title (ichat-window-title Id))) (when (string= Window-Title "") (error "no user ~A present")) (loop (let ((New-Text (first (last (parse-lines (get-ichat-text Window-Title)))))) (unless (string= New-Text Text) (print New-Text) (when (char= (char New-Text 0) #\() (i-chat-send-message (write-to-string (eval (read-from-string New-Text))) Id)) (setq Text New-Text)) (sleep 1))))) #| Examples: ;; Example 1: make this bot talk to the AOL Yellow Pages bot ;; to make this example work ;; 1) need to have aim:aolyellowpages on your buddy list ;; 2) have universal access enabled: System preferences/Universal Access ;; check "Enable Access for Assistive Devices" ;; provide ZIP (i-chat-send-message "80301" "aim:aolyellowpages") (pprint (parse-lines (get-ichat-text (ichat-window-title "aim:aolyellowpages")))) ;; look for bike stores (i-chat-send-message "bike stores" "aim:aolyellowpages") (pprint (parse-lines (get-ichat-text (ichat-window-title "aim:aolyellowpages")))) ;; GT Bike store (i-chat-send-message "2" "aim:aolyellowpages") (pprint (parse-lines (get-ichat-text (ichat-window-title "aim:aolyellowpages")))) (pprint (parse-lines (get-ichat-text "Empty chat room"))) (pprint (parse-lines (get-ichat-text (ichat-window-title "aim:profpepita")))) (get-ichat-text "1") (ichat-first-document-window-title) (pprint (parse-lines (get-ichat-text (ichat-first-document-window-title)))) |# #| more examples: (get-ichat-account-name-from-id "aim:cyborgwriter") (ichat-window-title "aim:cyborgwriter") (get-ichat-text (ichat-window-title "aim:Aiolida")) (get-ichat-text (ichat-window-title "aim:profpepita")) (pprint (parse-lines (get-ichat-text (ichat-window-title "aim:aolyellowpages")))) (get-ichat-text "Chat with Nadia Repenning") (get-ichat-text "Chat with Chris Digiano") (get-ichat-text "Chat with Darth Vader") (run-ichat-robot "AIM:mrvetro") (i-chat-send-message "here i am" "AIM:mrvetro") (pprint (parse-lines (get-ichat-text))) (first (last (parse-lines (get-ichat-text)))) (time (get-ichat-text)) |#