-
-
Save alandipert/221392 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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