 
 (defn debug-print-message
   [_session msg]
-  #_(println msg))
+  (let [oops (select-keys msg [:error :throttled :throttled_reason])]
+    (if (every? (some-fn nil? false?) (keys oops))
+      (do ;; successful event/reply
+        #_(println msg))
+      (do ;; something's wrong
+        (println msg)))))
 
 (defn log-messages
   "Log message datas to file."

                                        :data m}))))
    (.flush w)))

(defn log-send-event
  "Log a single new message to file."
  [session send-msg]
  (log-messages session [(get-in send-msg [:data])]))

(defn log-snapshot-event
  "Log an entire snapshot to file."
  [session snapshot-msg]
  (log-messages session (get-in snapshot-msg [:data :log])))

(def logger-dispatch
  "Reactive dispatch overlay for logger."
  (merge
   (base-dispatch "hillbot")
   {"send-event"
    #'log-send-event

    "snapshot-event"
    #'log-snapshot-event

    :unknown-type
    ;; (fn [session msg]

            [clojure.java.io :as io]
            [clojure.string :as str]
            [manifold.stream :as s]))

;; Consider exporting to org.timmc/handy
(defn max-1
  "Find the largest element in coll with respect to the comparator,
yielding it as the single element of a collection. When coll is
empty, yields nil."
  [comparator coll]
  (when (seq coll)
    (reduce (fn [accum item]
              (if (neg? (comparator accum item))
                item
                accum))
            (first coll)
            (rest coll))))

(defn pencode
  "Percent-encode for URLs (conservatively.)"
