Created
February 26, 2009 06:29
-
-
Save hiredman/70696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hiredman.alfred | |
(:gen-class) | |
(:use hiredman.xmpp) | |
(:import java.text.SimpleDateFormat)) | |
(def me (ref {:xmpp (agent (connect "drone1@thelastcitadel.com" "xxxxxxx"))})) | |
(defn listfiles [] | |
(map #(apply str (drop 26 %)) | |
(map str (.listFiles (java.io.File. "/home/hiredman/tmp/alfred"))))) | |
(defmulti responder | |
(fn [type & stuff] | |
(cond | |
(and (= type :xmpp) (-> stuff last (= "ping"))) | |
::pong | |
(and (= type :xmpp) (re-find #"weather" (last stuff))) | |
::weather | |
(and (= type :xmpp) (re-find #"^avatar " (last stuff))) | |
::change-avatar | |
(and (= type :xmpp) (re-find #"^get \w" (last stuff))) | |
::get | |
(and (= type :xmpp) (re-find #"^ls?" (last stuff))) | |
::ls | |
(and (= type :xmpp) (re-find #"^@list" (last stuff))) | |
::list-notes | |
(and (= type :xmpp) (re-find #"^@" (last stuff))) | |
::make-note | |
:else | |
::print))) | |
(defchute redchin (@me :xmpp) "redchin@gmail.com" (fn [c m] | |
(responder :xmpp (.getParticipant c) (.getBody m)))) | |
(defmethod responder ::ls [type who msg] | |
(let [x (-> msg (.replaceAll "^ls" "") .trim)] | |
(redchin :send (listfiles)))) | |
(defmethod responder ::get [type who msg] | |
(let [x (-> msg (.replaceAll "^get "))])) | |
(defmethod responder ::print [& stuff] | |
(apply prn stuff)) | |
(defmethod responder ::pong [& _] | |
(redchin :send "pong")) | |
(defmethod responder ::change-avatar [type who msg] | |
(let [x (-> msg | |
(.replaceAll "^avatar " "") | |
(.replaceAll "#alfred" "public_html/images/Alfred.png"))] | |
(set-avatar (@me :xmpp) (avatar-bytes (str "/home/hiredman/" x))) | |
(await (@me :xmpp)) | |
(clear-agent-errors (@me :xmpp)))) | |
(def notes (ref '())) | |
(defmethod responder ::make-note [type who msg] | |
(dosync (alter notes conj [(java.util.Date.) (.replaceAll msg "^@" "")])) | |
(println msg)) | |
(defmethod responder ::list-notes [type who msg] | |
(dorun (map #(redchin :send (.format (SimpleDateFormat. "yyyy.MM.dd") (first %)) " " (last %)) @notes))) | |
;(def a (avatar-bytes "/home/hiredman/tmp/.a/foo.png")) | |
(update-presence (@me :xmpp) (presence :available "Ready to serve")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment