/src/hiredman/clojurebot/simplyscala.clj

http://github.com/hiredman/clojurebot · Clojure · 25 lines · 21 code · 4 blank · 0 comment · 2 complexity · 5e82b4748a00cf93f44d6ed8bb249ca9 MD5 · raw file

  1. (ns hiredman.clojurebot.simplyscala
  2. (:use [hiredman.clojurebot.core :only (defresponder2 new-send-out extract-message)])
  3. (:require [hiredman.utilities :as util])
  4. (:import (java.net URLEncoder )))
  5. (def scala-the-easy-way "http://www.simplyscala.com/interp?bot=irc&code=")
  6. (defn scala-eval [code]
  7. (-> code URLEncoder/encode ((partial str scala-the-easy-way))
  8. util/get-url (.split "res0: ") rest ((partial apply str))))
  9. (defresponder2
  10. {:priority 0
  11. :name ::scala
  12. :dispatch (fn [bot msg]
  13. (and (:addressed? (meta msg))
  14. (.startsWith (extract-message bot msg) "scala")))
  15. :body (fn [bot msg]
  16. (new-send-out bot :msg msg
  17. (scala-eval
  18. (let [m (extract-message bot msg)]
  19. (if (.startsWith m "scala")
  20. (.replaceAll m "^scala" "")
  21. (.substring m 1))))))})