fork(1) download
  1. ; Written by notostraca (tommy dot ettinger at gmail)
  2. ; Licensed under the EPL
  3. (ns lazybot.plugins.nest
  4. (:use [lazybot registry info]
  5. [clojure.string :only [join trim split]]
  6. [clojure.pprint :only [pprint]]
  7. [clojail.core :only [thunk-timeout]]
  8. [overtone.at-at]
  9. )
  10. (:import java.io.PrintWriter
  11. java.util.concurrent.TimeoutException
  12. java.io.StringWriter))
  13.  
  14. (def my-pool (mk-pool))
  15.  
  16. (defplugin
  17. (:cmd
  18. "Calls two nested commands."
  19. #{"`" "!" "nest"}
  20. (fn [{:keys [com bot nick args channel] :as com-m}]
  21. (with-open [sw (StringWriter.)]
  22. (let [
  23. get-inner #(re-find #"\[\s*(\S+)\s+([^\]]+)\]" (join " " (rest %)))]
  24.  
  25. (if (and (seq args)
  26. (find-command (:modules @bot) (first args))
  27. (seq (get-inner args))
  28. (find-command (:modules @bot) (nth (get-inner args) 1)))
  29. (do
  30. (let [inside-args (nth (get-inner args) 2)
  31. sout (get-in @com [:connection :sockout])
  32. ]
  33. (dosync (alter com assoc-in
  34. [:connection :sockout] (PrintWriter. sw))
  35. (alter com assoc :args (split inside-args #"\s"))
  36. (alter com assoc :raw-args inside-args)
  37. )
  38. (try
  39. ((:fn (find-command (:modules @bot) (nth (get-inner args) 1))) (assoc com-m :args (split inside-args #"\s")))
  40. (after 1000 (fn [] (do
  41. (.flush (get-in @com [:connection :sockout]))
  42. (.close (get-in @com [:connection :sockout]))
  43.  
  44. (let [new-args (.toString sw )]
  45.  
  46. (dosync (alter com assoc-in
  47. [:connection :sockout] sout)
  48. (alter com assoc :args (split (last (split new-args #" \:" 2)) #"\s"))
  49. (alter com assoc :raw-args (join " " (split (last (split new-args #" \:" 2)) #"\s"))))
  50. ((:fn (find-command (:modules @bot) (first args))) (assoc com-m :args (split (last (split new-args #" \:" 2)) #"\s")))
  51. ))) my-pool)
  52. (catch TimeoutException e (send-message com-m "Nested execution timeout.") ))))))))))
  53.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty