diff options
| author | sostler <sbostler@gmail.com> | 2010-04-11 16:50:40 -0400 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-04-11 16:50:40 -0400 |
| commit | 57c3298cbb88181ab2a9e2dd5309b7a5df6eb30f (patch) | |
| tree | e9ca474c5a1fa584728b152bf95ac5471943253c /src/admin.clj | |
| parent | 57be29ee7b7782830cf981d9437b18c88620f8ed (diff) | |
Initial muting implementation
Diffstat (limited to 'src/admin.clj')
| -rw-r--r-- | src/admin.clj | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/admin.clj b/src/admin.clj new file mode 100644 index 0000000..a7eced1 --- /dev/null +++ b/src/admin.clj @@ -0,0 +1,69 @@ +(ns admin + (:import java.io.File) + (:require [clojure.contrib.str-utils2 :as s]) + (:use compojure + email + utils)) + +;; Debug Page + +(defn exception-to-string [e] + (let [sw (java.io.StringWriter.) + pw (java.io.PrintWriter. sw)] + (.printStackTrace e pw) + (.toString sw))) + +(defn lookup-templates [dir selected] + (for [f (.listFiles (File. dir)) + :when (and (.isFile f) (.endsWith (.getName f) ".st"))] + (let [n (s/butlast (.getName f) 3)] + {"template" n + "selected" (= selected n)}))) + +(defn debug-page [session flash] + (if-vip + (let [st (fetch-template "debug" session)] + (.setAttribute st "flash" (:msg flash)) + (.setAttribute st "mailtemps" (lookup-templates "template/mail" "welcome")) + (.toString st)))) + +(defn debug-commmand! [session params] + (if-vip + (let [action (:action params) + msg (try + (cond (= action "regemail") + (do (send-registration-email (params :nick) (params :to) (params :template)) + (str "Sent registration mail to " (params :to))) + :else (str "Unknown action: " action)) + (catch Exception e + (str "<h2 color=\"red\">Caught Exception in " action " --" + (.getMessage e) + "</h2><br><pre>" + (exception-to-string e) + "</pre>")))] + [(flash-assoc :msg msg) + (redirect-to "/debug")]))) + +;; Muting + +(defn mute-status [session] + (if-vip + (println session))) + +(defn parse-pos-interval [time unit] + (let [t (maybe-parse-int time 0) + u (lower-case unit)] + (and (> t 0) + (#{"minute" "hour" "day"} u) + (str time " " u)))) + +(defn mute! [session params] + (if-vip + (let [nick (params :user) + user_id (:user_id (fetch-nick nick)) + interval (parse-pos-interval (params :time) (params :unit)) + reason (params :reason) + admin-user-id (session :user_id)] + (cond (not user_id) [400 "INVALID_NICK"] + (not interval) [400 "INVALID_INTERVAL"] + :else (do "OK"))))) |
