Permalink
Browse files

cleanup

  • Loading branch information...
1 parent 78f395b commit 87d9fb75b1a0ca9afbf58c2608bb3fbf7fd6c077 @hiredman committed Feb 23, 2013
View
@@ -2,19 +2,21 @@
:repositories {"sonatype-snapshots"
"https://oss.sonatype.org/content/repositories/snapshots/"}
:description "An IRC bot written in Clojure"
+ :exclusions [commons-logging]
:dependencies [[org.clojure/clojure "1.2.1"]
- [org.clojure/tools.logging "0.1.2"]
+ [org.clojure/tools.logging "0.2.6"]
[conduit-irc "2.0.1-SNAPSHOT"]
- #_[org.clojars.thnetos/opennlp "0.0.3"]
[org.ccil.cowan.tagsoup/tagsoup "1.2"]
- [log4j "1.2.16"]
[org.danlarkin/clojure-json "1.1"]
- [clj-http "0.1.1"]
+ [clj-http "0.1.1"
+ :exclude [commons-logging]]
[swank-clojure "1.3.2"]
[com.thelastcitadel/apropos "0.0.1"]
- #_[conduit-xmpp "1.0.0-SNAPSHOT"]
[ring "1.1.8"]
- [compojure "1.1.5"]]
+ [compojure "1.1.5"]
+ ;; logging
+ [ch.qos.logback/logback-classic "1.0.9"]
+ [ch.qos.logback/logback-core "1.0.9"]]
:main clojurebot.core
:clean-non-project-classes false
:min-lein-version "2.0.0")
View
@@ -1,12 +0,0 @@
-log4j.appender.C = org.apache.log4j.ConsoleAppender
-log4j.appender.C.layout = org.apache.log4j.PatternLayout
-log4j.appender.C.layout.ConversionPattern = %d | %-5p | %c | %m%n
-
-log4j.appender.F = org.apache.log4j.FileAppender
-log4j.appender.F.File = clojurebot.log
-log4j.appender.F.Append = false
-log4j.appender.F.layout = org.apache.log4j.PatternLayout
-log4j.appender.F.layout.ConversionPattern = %d | %-5p | %c | %m%n
-
-log4j.rootLogger=info, F
-log4j.logger.clojurebot=debug
View
@@ -56,3 +56,5 @@ $1
exit 0
+
+
View
@@ -32,6 +32,7 @@
[compojure.core :refer [defroutes]]
[compojure.route :refer :all]
[ring.adapter.jetty :refer [run-jetty]])
+ (:require [clojure.tools.logging :as log])
(:gen-class))
;; pipelines
@@ -107,7 +108,7 @@
(try
((resolve name) msg)
(catch Exception e
- (.printStackTrace e))))))
+ (log/error e "error running logging plugin"))))))
pass-through)
(a-arr last) ;we only want the passed through value
@@ -167,7 +168,7 @@
(a-comp (a-arr #(dissoc % :config :bot))
null)
))
- (a-arr (comp #(doto % .printStackTrace) first))))
+ (a-arr (comp #(log/error %) first))))
;;/pipelines
@@ -211,8 +212,7 @@
{:status 200
:headers {"Content-Type" "application/edn; charset=utf-8"}
:body (let [x (hiredman.clojurebot.core/befuddled)]
- (prn x)
- (println x)
+ (log/debug "/befuddled ·" x)
(pr-str x))})
(GET "/ok" []
{:status 200
@@ -1,40 +0,0 @@
-;; posts lines containing urls to a delicious account
-(ns clojurebot.delicious
- (:require [clj-http.client :as http]))
-
-(def url-reg #"[A-Za-z]+://[^ ^/]+\.[^ ^/]+[^ ]+")
-
-(def pastebins
- #"(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)")
-
-;;#"(\w+://.*?)[.>]*(?: |$)"
-
-(defn post
- "posts a url to the delicious account of [user pass]"
- [[user pass] url descr tag]
- (http/get "https://api.del.icio.us/v1/posts/add"
- {:query-params
- {"url" url
- "description" descr
- "tags" tag}
- :basic-auth [user pass]}))
-
-(defn contains-url? [{:keys [message channel config]}]
- (and message
- (re-find url-reg message)
- channel
- (:delicious config)))
-
-(defn delicious [{:keys [message channel sender config]}]
- (try
- (let [url (re-find url-reg message)
- desc message
- tag (str sender " " channel
- (when (re-find #"lisppaste" sender)
- (str " " (first (.split desc " ")))))
- tag (if (re-find pastebins url)
- (str tag " pastbin")
- tag)]
- (post (:delicious config) url desc tag))
- (catch Exception e
- (println e))))
@@ -1,79 +0,0 @@
-(ns hiredman.clojurebot
- (:require (hiredman.clojurebot core dice sb seenx google delicious noise
- stock-quote factoids translate
- code-lookup javadoc ticket github xmpp
- simplyscala clojars tao)
- [hiredman.clojurebot.xmpp :as xmpp]
- [hiredman.utilities :as util]
- [hiredman.twitter :as twitter])
- (:import (org.jibble.pircbot PircBot)))
-
-(set! *warn-on-reflection* true)
-
-(import '(sun.misc Signal SignalHandler))
-
-(defn install [sig handler]
- (Signal/handle (Signal. (name sig))
- (proxy [SignalHandler] []
- (handle [sig] (handler sig)))))
-
-(defn props []
- (let [properties (java.util.Properties.)]
- (with-open [properties-file (-> (fn []) class
- (.getResourceAsStream
- "/clojurebot.properties"))]
- (.load properties properties-file)
- (into {} properties))))
-
-;;set up sandbox namespace for evaling code
-(binding [*ns* (create-ns 'sandbox)]
- (clojure.core/refer 'clojure.core)
- (import '(java.util Date))
- (intern *ns* 'Thread (fn [& _] (throw (Exception. "DENIED"))))
- (intern *ns* 'java.lang.Thread (fn [& _] (throw (Exception. "DENIED")))))
-
-(defn connect [bot]
- (.connect (:this bot) (:network bot))
- bot)
-
-(defn join [bot]
- (doseq [channel (cons (:channel bot) (:channels bot))]
- (.joinChannel (:this bot) channel))
- bot)
-
-(defn -main []
- (-> (let [p (props)]
- {:nick "clojurebot"
- :network "irc.freenode.net"
- :channel "#clojurebot"
- :tweet true
- :delicious [(p "delicious.user") (p "delicious.password")]
- :twitter [(p "twitter.user") (p "twitter.password")]
- :sandbox-ns 'sandbox
- :store (agent {})
- :factoid-server-port 4444
- :xmpp-connection (xmpp/connect (p "xmpp.jid") (p "xmpp.password"))
- ;; must include final slash
- :dict-dir (.concat (System/getProperty "user.dir") "/")})
- ((fn [attrs]
- (let [bot (pircbot attrs)]
- (wall-hack-method PircBot :setName [String] (:this bot) (:nick bot))
- bot)))
- connect
- join
- ((fn [bot]
- (doto bot
- load-dicts
- load-store
- watch-store
- start-dump-thread
- xmpp/setup-listener
- (xmpp/connect-to-muc "clojure@thelastcitadel.com")
- ((fn [bot] (factoid-server (:factoid-server-port bot) bot)))
- hiredman.clojurebot.clojars/go
- (hiredman.clojurebot.tao/go "#clojurebot" 5))))
- ((fn [bot]
- (intern (create-ns 'hiredman.clojurebot)
- (with-meta 'bot {:private true})
- bot))))
- (println "Done loading!"))
@@ -1,72 +0,0 @@
-; Subversion announcements
-
-(ns hiredman.clojurebot.svn
- (:require [hiredman.clojurebot.core :as core]
- [hiredman.utilities :as util]
- [hiredman.twitter :as twitter])
- (:import (java.util.concurrent TimeUnit)))
-
-(defn summary
- "takes output of clojure.xml/parse on svn's xml log, returns
- a vector of [rev-number commit-message]"
- [tag-map]
- (map (fn [x]
- [(Integer/parseInt (:revision (:attrs x)))
- (first
- (:content
- (first
- (filter #(= (:tag %) :msg)
- (:content x)))))
- (-> x :content ((partial filter #(= (:tag %) :author))) first :content first)])
- (:content tag-map)))
-
-(def latest-revisions
- (comp summary
- clojure.xml/parse
- #(.getInputStream %)
- util/shell
- (partial str "svn -v --xml --limit 5 log ")))
-
-(def revision
- (comp first
- summary
- clojure.xml/parse
- #(.getInputStream %)
- util/shell
- #(str "svn -v --xml -r " %2 " log " %)))
-
-(def revision-cached (memoize revision))
-
-(def latest (atom {}))
-
-(defn start-svn-watcher [bot name url callback]
- (.scheduleAtFixedRate core/task-runner
- (fn []
- (try
- (println name " checking SVN revs")
- (when-let [revs (seq (filter #(> (first %) (get @latest name 0)) (latest-revisions url)))]
- (swap! latest assoc name (first (last (sort-by first revs))))
- (callback bot (reverse revs)))
- (catch Exception e
- (.printStackTrace e))))
- (long 1)
- (long 5)
- TimeUnit/MINUTES))
-
-;;(defn clojure-channel-helper-callback
-;; [bot revs]
-;; (doseq [r revs]
-;; (doseq [c (.getChannels (:this bot))]
-;; (core/send-out :notice bot c (str "r" (first r) " " (second r)))
-;; (when (:tweet bot)
-;; (twitter/send (first (:twitter bot)) (second (:twitter bot)) (str "r" (first r) " " (second r))))))
-;; (core/is! "latest" (.toString (first (last (sort-by first revs))))))
-
-(def default-repo (atom ""))
-
-(defmethod core/responder ::svn-rev-lookup [bot pojo]
- (let [r (Integer/parseInt (re-find #"[0-9]+" (:message pojo)))]
- (core/send-out :notice bot (core/who pojo) (let [x (revision-cached @default-repo r)]
- (str "r" (first x) " " (second x))))))
-
-(core/add-dispatch-hook (core/dfn (re-find #"^r[0-9]+$" (:message msg))) ::svn-rev-lookup)
@@ -1,58 +0,0 @@
-(ns hiredman.clojurebot.tweet
- (:require [hiredman.clojurebot.core :as core]
- [hiredman.clojurebot.seenx :as seenx])
- (:use (hiredman horizon))
- (:import (java.util.concurrent TimeUnit)
- (java.util Date)))
-
-(def urlx "http://search.twitter.com/search.atom?q=")
-
-(def nex (atom {}))
-
-(def next-url
- (comp :href
- :attrs
- first
- (partial filter #(and (= (:rel (:attrs %)) "refresh" ) (= :link (:tag %))))
- :content))
-
-(def xml
- (comp clojure.xml/parse
- #(.getContent %)
- #(java.net.URL. %)))
-
-(defn url [term]
- (if-let [u (@nex term)]
- u
- (str urlx term)))
-
-(defn interesting-tag? [x]
- (some #(= (:tag x) %) [:title :author]))
-
-(def entries
- (comp (partial filter #(= :entry (:tag %)))
- :content))
-
-(defn entry [t]
- (let [[content author] (map (comp first :content) (filter interesting-tag? (:content t)))
- author (first (re-find #"([^ ]+)" (first (:content author))))]
- [content author]))
-
-(defn get-tweets [term]
- (let [xml (xml (url term))]
- (swap! nex #(assoc % term (next-url xml)))
- (seq (map entry (entries xml)))))
-
-(defn get-latest-tweets [bot term channel]
- (let [ts (reverse (get-tweets "clojure"))]
- (when (seq ts)
- (core/send-out :notice bot channel "Tweets:")
- (doseq [t ts]
- (core/send-out :notice bot channel (str (first t) " --" (second t)))))))
-
-(defn watch [bot term channel]
- (.scheduleAtFixedRate core/task-runner
- #(get-latest-tweets bot term channel)
- (long 0)
- (long 60)
- TimeUnit/MINUTES))
Oops, something went wrong.

0 comments on commit 87d9fb7

Please sign in to comment.