Skip to content
This repository
Browse code

cleanup

  • Loading branch information...
commit 87d9fb75b1a0ca9afbf58c2608bb3fbf7fd6c077 1 parent 78f395b
Kevin Downey authored
14 project.clj
@@ -2,19 +2,21 @@
2 2 :repositories {"sonatype-snapshots"
3 3 "https://oss.sonatype.org/content/repositories/snapshots/"}
4 4 :description "An IRC bot written in Clojure"
  5 + :exclusions [commons-logging]
5 6 :dependencies [[org.clojure/clojure "1.2.1"]
6   - [org.clojure/tools.logging "0.1.2"]
  7 + [org.clojure/tools.logging "0.2.6"]
7 8 [conduit-irc "2.0.1-SNAPSHOT"]
8   - #_[org.clojars.thnetos/opennlp "0.0.3"]
9 9 [org.ccil.cowan.tagsoup/tagsoup "1.2"]
10   - [log4j "1.2.16"]
11 10 [org.danlarkin/clojure-json "1.1"]
12   - [clj-http "0.1.1"]
  11 + [clj-http "0.1.1"
  12 + :exclude [commons-logging]]
13 13 [swank-clojure "1.3.2"]
14 14 [com.thelastcitadel/apropos "0.0.1"]
15   - #_[conduit-xmpp "1.0.0-SNAPSHOT"]
16 15 [ring "1.1.8"]
17   - [compojure "1.1.5"]]
  16 + [compojure "1.1.5"]
  17 + ;; logging
  18 + [ch.qos.logback/logback-classic "1.0.9"]
  19 + [ch.qos.logback/logback-core "1.0.9"]]
18 20 :main clojurebot.core
19 21 :clean-non-project-classes false
20 22 :min-lein-version "2.0.0")
12 resources/log4j.properties
... ... @@ -1,12 +0,0 @@
1   -log4j.appender.C = org.apache.log4j.ConsoleAppender
2   -log4j.appender.C.layout = org.apache.log4j.PatternLayout
3   -log4j.appender.C.layout.ConversionPattern = %d | %-5p | %c | %m%n
4   -
5   -log4j.appender.F = org.apache.log4j.FileAppender
6   -log4j.appender.F.File = clojurebot.log
7   -log4j.appender.F.Append = false
8   -log4j.appender.F.layout = org.apache.log4j.PatternLayout
9   -log4j.appender.F.layout.ConversionPattern = %d | %-5p | %c | %m%n
10   -
11   -log4j.rootLogger=info, F
12   -log4j.logger.clojurebot=debug
2  setup.sh
@@ -56,3 +56,5 @@ $1
56 56
57 57 exit 0
58 58
  59 +
  60 +
8 src/clojurebot/core.clj
@@ -32,6 +32,7 @@
32 32 [compojure.core :refer [defroutes]]
33 33 [compojure.route :refer :all]
34 34 [ring.adapter.jetty :refer [run-jetty]])
  35 + (:require [clojure.tools.logging :as log])
35 36 (:gen-class))
36 37
37 38 ;; pipelines
@@ -107,7 +108,7 @@
107 108 (try
108 109 ((resolve name) msg)
109 110 (catch Exception e
110   - (.printStackTrace e))))))
  111 + (log/error e "error running logging plugin"))))))
111 112 pass-through)
112 113
113 114 (a-arr last) ;we only want the passed through value
@@ -167,7 +168,7 @@
167 168 (a-comp (a-arr #(dissoc % :config :bot))
168 169 null)
169 170 ))
170   - (a-arr (comp #(doto % .printStackTrace) first))))
  171 + (a-arr (comp #(log/error %) first))))
171 172
172 173 ;;/pipelines
173 174
@@ -211,8 +212,7 @@
211 212 {:status 200
212 213 :headers {"Content-Type" "application/edn; charset=utf-8"}
213 214 :body (let [x (hiredman.clojurebot.core/befuddled)]
214   - (prn x)
215   - (println x)
  215 + (log/debug "/befuddled ·" x)
216 216 (pr-str x))})
217 217 (GET "/ok" []
218 218 {:status 200
40 src/clojurebot/delicious.clj
... ... @@ -1,40 +0,0 @@
1   -;; posts lines containing urls to a delicious account
2   -(ns clojurebot.delicious
3   - (:require [clj-http.client :as http]))
4   -
5   -(def url-reg #"[A-Za-z]+://[^ ^/]+\.[^ ^/]+[^ ]+")
6   -
7   -(def pastebins
8   - #"(fpaste\.org|dpaste\.*|gist\.github\.com|paste.lisp.org/display|.*pastebin\.com|p\.hagelb\.org|pastebin\.org|paste\.pocoo\.org/show|pastie\.org|sprunge\.us)")
9   -
10   -;;#"(\w+://.*?)[.>]*(?: |$)"
11   -
12   -(defn post
13   - "posts a url to the delicious account of [user pass]"
14   - [[user pass] url descr tag]
15   - (http/get "https://api.del.icio.us/v1/posts/add"
16   - {:query-params
17   - {"url" url
18   - "description" descr
19   - "tags" tag}
20   - :basic-auth [user pass]}))
21   -
22   -(defn contains-url? [{:keys [message channel config]}]
23   - (and message
24   - (re-find url-reg message)
25   - channel
26   - (:delicious config)))
27   -
28   -(defn delicious [{:keys [message channel sender config]}]
29   - (try
30   - (let [url (re-find url-reg message)
31   - desc message
32   - tag (str sender " " channel
33   - (when (re-find #"lisppaste" sender)
34   - (str " " (first (.split desc " ")))))
35   - tag (if (re-find pastebins url)
36   - (str tag " pastbin")
37   - tag)]
38   - (post (:delicious config) url desc tag))
39   - (catch Exception e
40   - (println e))))
79 src/hiredman/clojurebot.clj
... ... @@ -1,79 +0,0 @@
1   -(ns hiredman.clojurebot
2   - (:require (hiredman.clojurebot core dice sb seenx google delicious noise
3   - stock-quote factoids translate
4   - code-lookup javadoc ticket github xmpp
5   - simplyscala clojars tao)
6   - [hiredman.clojurebot.xmpp :as xmpp]
7   - [hiredman.utilities :as util]
8   - [hiredman.twitter :as twitter])
9   - (:import (org.jibble.pircbot PircBot)))
10   -
11   -(set! *warn-on-reflection* true)
12   -
13   -(import '(sun.misc Signal SignalHandler))
14   -
15   -(defn install [sig handler]
16   - (Signal/handle (Signal. (name sig))
17   - (proxy [SignalHandler] []
18   - (handle [sig] (handler sig)))))
19   -
20   -(defn props []
21   - (let [properties (java.util.Properties.)]
22   - (with-open [properties-file (-> (fn []) class
23   - (.getResourceAsStream
24   - "/clojurebot.properties"))]
25   - (.load properties properties-file)
26   - (into {} properties))))
27   -
28   -;;set up sandbox namespace for evaling code
29   -(binding [*ns* (create-ns 'sandbox)]
30   - (clojure.core/refer 'clojure.core)
31   - (import '(java.util Date))
32   - (intern *ns* 'Thread (fn [& _] (throw (Exception. "DENIED"))))
33   - (intern *ns* 'java.lang.Thread (fn [& _] (throw (Exception. "DENIED")))))
34   -
35   -(defn connect [bot]
36   - (.connect (:this bot) (:network bot))
37   - bot)
38   -
39   -(defn join [bot]
40   - (doseq [channel (cons (:channel bot) (:channels bot))]
41   - (.joinChannel (:this bot) channel))
42   - bot)
43   -
44   -(defn -main []
45   - (-> (let [p (props)]
46   - {:nick "clojurebot"
47   - :network "irc.freenode.net"
48   - :channel "#clojurebot"
49   - :tweet true
50   - :delicious [(p "delicious.user") (p "delicious.password")]
51   - :twitter [(p "twitter.user") (p "twitter.password")]
52   - :sandbox-ns 'sandbox
53   - :store (agent {})
54   - :factoid-server-port 4444
55   - :xmpp-connection (xmpp/connect (p "xmpp.jid") (p "xmpp.password"))
56   - ;; must include final slash
57   - :dict-dir (.concat (System/getProperty "user.dir") "/")})
58   - ((fn [attrs]
59   - (let [bot (pircbot attrs)]
60   - (wall-hack-method PircBot :setName [String] (:this bot) (:nick bot))
61   - bot)))
62   - connect
63   - join
64   - ((fn [bot]
65   - (doto bot
66   - load-dicts
67   - load-store
68   - watch-store
69   - start-dump-thread
70   - xmpp/setup-listener
71   - (xmpp/connect-to-muc "clojure@thelastcitadel.com")
72   - ((fn [bot] (factoid-server (:factoid-server-port bot) bot)))
73   - hiredman.clojurebot.clojars/go
74   - (hiredman.clojurebot.tao/go "#clojurebot" 5))))
75   - ((fn [bot]
76   - (intern (create-ns 'hiredman.clojurebot)
77   - (with-meta 'bot {:private true})
78   - bot))))
79   - (println "Done loading!"))
72 src/hiredman/clojurebot/svn.clj
... ... @@ -1,72 +0,0 @@
1   -; Subversion announcements
2   -
3   -(ns hiredman.clojurebot.svn
4   - (:require [hiredman.clojurebot.core :as core]
5   - [hiredman.utilities :as util]
6   - [hiredman.twitter :as twitter])
7   - (:import (java.util.concurrent TimeUnit)))
8   -
9   -(defn summary
10   - "takes output of clojure.xml/parse on svn's xml log, returns
11   - a vector of [rev-number commit-message]"
12   - [tag-map]
13   - (map (fn [x]
14   - [(Integer/parseInt (:revision (:attrs x)))
15   - (first
16   - (:content
17   - (first
18   - (filter #(= (:tag %) :msg)
19   - (:content x)))))
20   - (-> x :content ((partial filter #(= (:tag %) :author))) first :content first)])
21   - (:content tag-map)))
22   -
23   -(def latest-revisions
24   - (comp summary
25   - clojure.xml/parse
26   - #(.getInputStream %)
27   - util/shell
28   - (partial str "svn -v --xml --limit 5 log ")))
29   -
30   -(def revision
31   - (comp first
32   - summary
33   - clojure.xml/parse
34   - #(.getInputStream %)
35   - util/shell
36   - #(str "svn -v --xml -r " %2 " log " %)))
37   -
38   -(def revision-cached (memoize revision))
39   -
40   -(def latest (atom {}))
41   -
42   -(defn start-svn-watcher [bot name url callback]
43   - (.scheduleAtFixedRate core/task-runner
44   - (fn []
45   - (try
46   - (println name " checking SVN revs")
47   - (when-let [revs (seq (filter #(> (first %) (get @latest name 0)) (latest-revisions url)))]
48   - (swap! latest assoc name (first (last (sort-by first revs))))
49   - (callback bot (reverse revs)))
50   - (catch Exception e
51   - (.printStackTrace e))))
52   - (long 1)
53   - (long 5)
54   - TimeUnit/MINUTES))
55   -
56   -;;(defn clojure-channel-helper-callback
57   -;; [bot revs]
58   -;; (doseq [r revs]
59   -;; (doseq [c (.getChannels (:this bot))]
60   -;; (core/send-out :notice bot c (str "r" (first r) " " (second r)))
61   -;; (when (:tweet bot)
62   -;; (twitter/send (first (:twitter bot)) (second (:twitter bot)) (str "r" (first r) " " (second r))))))
63   -;; (core/is! "latest" (.toString (first (last (sort-by first revs))))))
64   -
65   -(def default-repo (atom ""))
66   -
67   -(defmethod core/responder ::svn-rev-lookup [bot pojo]
68   - (let [r (Integer/parseInt (re-find #"[0-9]+" (:message pojo)))]
69   - (core/send-out :notice bot (core/who pojo) (let [x (revision-cached @default-repo r)]
70   - (str "r" (first x) " " (second x))))))
71   -
72   -(core/add-dispatch-hook (core/dfn (re-find #"^r[0-9]+$" (:message msg))) ::svn-rev-lookup)
58 src/hiredman/clojurebot/tweet.clj
... ... @@ -1,58 +0,0 @@
1   -(ns hiredman.clojurebot.tweet
2   - (:require [hiredman.clojurebot.core :as core]
3   - [hiredman.clojurebot.seenx :as seenx])
4   - (:use (hiredman horizon))
5   - (:import (java.util.concurrent TimeUnit)
6   - (java.util Date)))
7   -
8   -(def urlx "http://search.twitter.com/search.atom?q=")
9   -
10   -(def nex (atom {}))
11   -
12   -(def next-url
13   - (comp :href
14   - :attrs
15   - first
16   - (partial filter #(and (= (:rel (:attrs %)) "refresh" ) (= :link (:tag %))))
17   - :content))
18   -
19   -(def xml
20   - (comp clojure.xml/parse
21   - #(.getContent %)
22   - #(java.net.URL. %)))
23   -
24   -(defn url [term]
25   - (if-let [u (@nex term)]
26   - u
27   - (str urlx term)))
28   -
29   -(defn interesting-tag? [x]
30   - (some #(= (:tag x) %) [:title :author]))
31   -
32   -(def entries
33   - (comp (partial filter #(= :entry (:tag %)))
34   - :content))
35   -
36   -(defn entry [t]
37   - (let [[content author] (map (comp first :content) (filter interesting-tag? (:content t)))
38   - author (first (re-find #"([^ ]+)" (first (:content author))))]
39   - [content author]))
40   -
41   -(defn get-tweets [term]
42   - (let [xml (xml (url term))]
43   - (swap! nex #(assoc % term (next-url xml)))
44   - (seq (map entry (entries xml)))))
45   -
46   -(defn get-latest-tweets [bot term channel]
47   - (let [ts (reverse (get-tweets "clojure"))]
48   - (when (seq ts)
49   - (core/send-out :notice bot channel "Tweets:")
50   - (doseq [t ts]
51   - (core/send-out :notice bot channel (str (first t) " --" (second t)))))))
52   -
53   -(defn watch [bot term channel]
54   - (.scheduleAtFixedRate core/task-runner
55   - #(get-latest-tweets bot term channel)
56   - (long 0)
57   - (long 60)
58   - TimeUnit/MINUTES))
81 src/hiredman/clojurebot/xmpp.clj
... ... @@ -1,81 +0,0 @@
1   -;; DEPENDS smack
2   -(ns hiredman.clojurebot.xmpp
3   - (:require [hiredman.clojurebot.core :as core])
4   - (:import (org.jivesoftware.smack XMPPConnection ConnectionConfiguration
5   - RosterListener PrivacyListManager
6   - PacketListener MessageListener)
7   - (org.jivesoftware.smack.packet Message Message$Type IQ IQ$Type Presence Presence$Type)
8   - (org.jivesoftware.smackx.muc MultiUserChat)
9   - (org.jivesoftware.smack.filter PacketFilter MessageTypeFilter OrFilter)
10   - (org.jivesoftware.smackx.packet VCard)
11   - (org.jivesoftware.smackx.filetransfer FileTransferManager)
12   - (java.io File)))
13   -
14   -
15   -(defn connect [jid pass]
16   - (doto (XMPPConnection. (last (.split jid "@")))
17   - .connect
18   - (.login (first (.split jid "@")) pass)))
19   -
20   -(defn muc [connection room]
21   - (doto (MultiUserChat. connection room)
22   - (.join (first (.split (.getUser connection) "@")))))
23   -
24   -(declare msg->junks)
25   -
26   -(defn packet-processor [bot p]
27   - (when (not (nil? (.getBody p)))
28   - (trampoline core/responder
29   - (assoc bot :xmpp-message p)
30   - (let [g (msg->junks bot p)]
31   - (vary-meta g assoc :addressed? (core/addressed? bot g)
32   - :xmpp-message p)))))
33   -
34   -
35   -(defn msg->junks [bot msg]
36   - (struct core/junks
37   - (when (= (.getType msg) (Message$Type/fromString "groupchat"))
38   - (muc (:con bot) (first (.split (.getFrom msg) "/"))))
39   - (first (.split (.getFrom msg) "@"))
40   - nil
41   - nil
42   - (.getBody msg)))
43   -
44   -(defn packet-listener [bot]
45   - (proxy [PacketListener] []
46   - (processPacket [p]
47   - (try
48   - (binding [core/random-person #(do % "foo")]
49   - (packet-processor bot p))
50   - (catch Exception e
51   - (prn e))))))
52   -
53   -(defn clone-message [msg]
54   - (doto (Message.)
55   - (.setSubject (.getSubject msg))
56   - (.setThread (.getThread msg))
57   - (.setType (.getType msg))))
58   -
59   -(defmethod core/new-send-out :xmpp [bot msg-type r w]
60   - (when-not (= w "")
61   - (if (= (.getType (:xmpp-message bot)) (Message$Type/fromString "groupchat"))
62   - (.sendMessage (:channel r r) w)
63   - (.sendPacket (:con bot)
64   - (doto (clone-message (:xmpp-message bot))
65   - (.setFrom (.getTo (:xmpp-message bot)))
66   - (.setTo (.getFrom (:xmpp-message bot)))
67   - (.setBody w))))))
68   -
69   -;(def chat (muc con "clojure@conference.thelastcitadel.com"))
70   -
71   -(defn connect-to-muc [bot mu]
72   - (muc (:xmpp-connection bot) mu)
73   - bot)
74   -
75   -(defn setup-listener [bot]
76   - (.addPacketListener (:xmpp-connection bot)
77   - (packet-listener #^{:type :xmpp} {:con (:xmpp-connection bot) :nick "clojurebot"})
78   - (OrFilter.
79   - (MessageTypeFilter. (Message$Type/fromString "groupchat"))
80   - (MessageTypeFilter. (Message$Type/fromString "chat"))))
81   - bot)
50 src/hiredman/factoid_server.clj
... ... @@ -1,50 +0,0 @@
1   -(ns hiredman.factoid-server
2   - (:use [hiredman.http-server :only (http-server put)]
3   - [org.danlarkin.json :only (decode-from-str encode-to-str)]
4   - [hiredman.triples :only (derby query)]
5   - [hiredman.clojurebot.storage :only (db-name)])
6   - (:import (java.io BufferedReader StringReader)))
7   -
8   -(defn handle [request bot]
9   - (-> request StringReader. BufferedReader. line-seq
10   - ((partial map #(.trim %)))
11   - ((partial drop-while #(not= "" %)))
12   - rest
13   - ((partial apply str))
14   - decode-from-str
15   - ((fn [x]
16   - (query (derby (db-name bot))
17   - (:s x :x)
18   - (:p x :y)
19   - (:o x :z))))
20   - ((partial sort-by :upper_subject))
21   - ((partial map #(update-in % [:created_at] (fn [x] (.toString x)))))
22   - ((fn [x]
23   - (try
24   - (encode-to-str x)
25   - (catch Exception e
26   - (print e)))))
27   - ((fn [x]
28   - {:status "200 OK"
29   - :content-type "application/json"
30   - :body x}))))
31   -
32   -(defn f [r bot]
33   - (if (zero? (.available r)) (Thread/sleep 100))
34   - (let [l (.available r)
35   - buf (make-array Byte/TYPE l)]
36   - (.read r buf)
37   - (let [request (String. buf)]
38   - (prn request)
39   - (cond
40   - (.startsWith request "PUT")
41   - (handle request bot)
42   - :else
43   - {:status "404 Not Found" :content-type "text/plain" :body "hello world"}))))
44   -
45   -(defn factoid-server-fn [bot]
46   - (fn [r] (f r bot)))
47   -
48   -(defn factoid-server [port bot]
49   - (http-server (factoid-server-fn bot) port)
50   - bot)
49 src/hiredman/http_server.clj
... ... @@ -1,49 +0,0 @@
1   -(ns hiredman.http-server
2   - (:import (java.io InputStreamReader PrintWriter BufferedReader)
3   - (java.net ServerSocket URL)))
4   -
5   -(def running true)
6   -
7   -(defn- client-action [fn reader writer]
8   - (let [result (fn reader)]
9   - (binding [*out* writer]
10   - (println "HTTP/1.0" (:status result))
11   - (println "Server: a Simple Server")
12   - (println "Content-type:" (:content-type result))
13   - (println "Content-length:" (-> result :body .getBytes count))
14   - (println "")
15   - (println (:body result))))
16   - (doseq [x [reader writer]] (.close x)))
17   -
18   -(defn- handle-client [fn client-socket]
19   - (future
20   - (client-action fn
21   - (-> client-socket .getInputStream)
22   - (-> client-socket .getOutputStream PrintWriter.))))
23   -
24   -(defn- server-action [fn server-socket]
25   - (when running (send-off *agent* server-action server-socket))
26   - (try
27   - (handle-client fn (.accept server-socket))
28   - (catch Exception e
29   - (prn e)))
30   - fn)
31   -
32   -(defn http-server
33   - "fn is a fn that is passed the InputStream from the socket
34   - should return a map containing the keys :status :content-type :body"
35   - [fn portn]
36   - (send-off (agent fn)
37   - server-action
38   - (ServerSocket. portn)))
39   -
40   -(defn put
41   - "url is a string url and stuff is stuff to PUT to the url"
42   - [stuff url]
43   - (let [con (doto (.openConnection (URL. url))
44   - (.setDoInput true)
45   - (.setDoOutput true))]
46   - (with-open [wtr (-> con .getOutputStream PrintWriter.)]
47   - (binding [*out* wtr] (print stuff) (flush)))
48   - (with-open [rdr (-> con .getInputStream InputStreamReader. BufferedReader.)]
49   - (apply str (line-seq rdr)))))
83 src/hiredman/twitter.clj
... ... @@ -1,83 +0,0 @@
1   -(ns hiredman.twitter
2   - (:refer-clojure :exclude [send])
3   - (:require [org.danlarkin.json :as json]
4   - [clojure.core :as cc]
5   - [hiredman.clojurebot.core :as core]
6   - [hiredman.sandbox :as sb])
7   - (:import (java.net URL URLEncoder)
8   - (java.io BufferedReader InputStreamReader OutputStreamWriter)
9   - (sun.misc BASE64Encoder)))
10   -
11   -(def #^{:private true} twit (java.util.concurrent.LinkedBlockingQueue.))
12   -
13   -(def #^{:private true} twitter-urls {:update (URL. "http://twitter.com/statuses/update.xml")
14   - :messages (URL. "http://twitter.com/direct_messages.json")
15   - :mentions (URL. "http://twitter.com/statuses/mentions.json")})
16   -
17   -(defstruct account :username :password)
18   -
19   -(defn- base64encode [string] (.trim (.encode (BASE64Encoder.) (.getBytes string))))
20   -
21   -(def tweet-a false)
22   -
23   -(defn send [username password text]
24   - (when tweet-a
25   - (let [creds (base64encode (str username ":" password))
26   - con (doto (.openConnection (:update twitter-urls))
27   - (.setDoInput true) (.setDoOutput true) (.setUseCaches false)
28   - (.setRequestProperty "Authorization" (str "Basic " creds))
29   - (.setRequestProperty "User-Agent" "clojurebot 10/10"))
30   - status (str "status=" (URLEncoder/encode text "UTF-8"))]
31   - (with-open [wrt (-> con .getOutputStream OutputStreamWriter.)]
32   - (.write wrt status))
33   - (with-open [rdr (-> con .getInputStream InputStreamReader. BufferedReader.)]
34   - (apply str (line-seq rdr))))))
35   -
36   -(defn get-api [call username password]
37   - (let [creds (base64encode (str username ":" password))
38   - con (doto (.openConnection (call twitter-urls))
39   - (.setUseCaches false)
40   - (.setRequestProperty "Authorization" (str "Basic " creds))
41   - (.setRequestProperty "User-Agent" "clojurebot 10/10"))]
42   - (with-open [rdr (-> con .getInputStream InputStreamReader. BufferedReader.)]
43   - (json/decode-from-str (apply str (line-seq rdr))))))
44   -
45   -(defn open-connection [url creds]
46   - (doto (.openConnection url)
47   - (.setDoInput true) (.setDoOutput true) (.setUseCaches false)
48   - (.setRequestProperty "Authorization" (str "Basic " creds))
49   - (.setRequestProperty "User-Agent" "clojurebot 10/10")))
50   -
51   -(defn get-mentions [username password & id]
52   - (let [creds (base64encode (str username ":" password))
53   - con (open-connection (if (nil? id)
54   - (:mentions twitter-urls)
55   - (URL. (str (:mentions twitter-urls) "?since_id=" (first id)))) creds)]
56   - (with-open [rdr (-> con .getInputStream InputStreamReader. BufferedReader.)]
57   - ;(take-while identity (repeatedly #(.readLine rdr)))
58   - (json/decode-from-str (apply str (line-seq rdr))))))
59   -
60   -
61   -(defn login [username password]
62   - (vary-meta (struct account username password) assoc :type ::twitter))
63   -
64   -(defmethod core/new-send-out ::twitter [acct _ thing message]
65   - (when (not= "" message)
66   - (send (:username acct) (:password acct) (str "@" (:sender thing) " " message))))
67   -
68   -(defn tweet [x]
69   - (vary-meta (struct core/junks nil (-> x :user :screen_name) nil nil
70   - (.replaceAll (:text x) "^@clojurebot " ""))
71   - assoc :addressed? true))
72   -
73   -(def running true)
74   -
75   -(defn twitter-loop [_ acct]
76   - (let [m (get-mentions (:username acct) (:password acct) (:x (meta acct)))]
77   - (doseq [i m]
78   - (try (trampoline core/responder acct (tweet i))
79   - (catch Exception e
80   - (.printStackTrace e))))
81   - (when running
82   - (send-off *agent* twitter-loop (vary-meta acct assoc :x (:id (last (sort-by :id m)))))
83   - (Thread/sleep 100000))))

0 comments on commit 87d9fb7

Please sign in to comment.
Something went wrong with that request. Please try again.