Skip to content

Instantly share code, notes, and snippets.

@alandipert
Forked from hiredman/xmpp.clj
Created October 29, 2009 12:16
Show Gist options
  • Save alandipert/221392 to your computer and use it in GitHub Desktop.
Save alandipert/221392 to your computer and use it in GitHub Desktop.
(import '(org.jivesoftware.smack XMPPConnection))
(use '[clojure.set :only (difference)])
(defn connect [jid pass]
(doto (XMPPConnection. (last (.split jid "@")))
.connect
(.login (first (.split jid "@")) pass)))
(defn ls []
(-> (Runtime/getRuntime) (.exec "ncftpls -1R ftp://ftp-server/pub/")
.getInputStream java.io.InputStreamReader. java.io.BufferedReader.
line-seq set))
(def files (atom #{}))
(-> (connect "jid@host" "password")
((fn [x]
(future
(-> x .getChatManager (.createChat "otherjid@host" nil)
((fn [chat]
(let [lst (ls)
added-files (difference lst @files)
removed-files (difference @files lst)]
(when (not (empty? added-files)) (.sendMessage chat (format "+ %s" (str added-files))))
(when (not (empty? removed-files)) (.sendMessage chat (format "- %s" (str removed-files))))
(swap! files (constantly lst)))
(Thread/sleep 60000)
(recur chat))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment