Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
45 lines (41 sloc) 1.64 KB
(ns lazybot.plugins.debug
(:require [clojure.string :as string]
[clojure.pprint :as pprint]
[lazybot.registry :as registry]
[lazybot.plugins.login :refer [when-privs]]))
(defn get-mode [old-mode user-arg]
(case user-arg
:on :on
:off nil
:-v :verbose
:? old-mode
(when-not old-mode ; toggle
(defn debug-mode-str [mode]
(if mode
(name mode)
(def debug-keypath [:configs :debug-mode])
"Toggle debug mode, causing full stacktraces to be printed to the console/log when an exception goes uncaught, as well as permitting evaluation of arbitrary clojure code to inspect the running bot. Use the -v flag to print more debug information to the log."
(fn [{:keys [bot nick channel args] :as com-m}]
(when-privs com-m :admin
(registry/send-message com-m
(let [arg (keyword (first args))]
(alter bot update-in debug-keypath get-mode arg)
(str "Debug mode: "
(get-in @bot debug-keypath)))))))))
"Evaluate code in an un-sandboxed context. Prints the result to stdout, does not send it to any irc channel."
(fn [{:keys [bot nick channel args] :as com-m}]
(when (get-in @bot debug-keypath)
(when-privs com-m :admin
(let [code (string/join " " args)]
(println (str code " evaluates to:\n"
(pprint/pprint (eval (read-string code))))))))))))