   (filter #((-> % :members set) user-id) chans-or-grps))
 
 (defn reset-users-from-conn []
-  (let [groups (-> @conn :start :groups)
-        channels (-> @conn :start :channels)
-        users (-> @conn :start :users)]
+  (let [groups (-> @*conn* :start :groups)
+        channels (-> @*conn* :start :channels)
+        users (-> @*conn* :start :users)]
     (dorun
       (map
         (fn [{:keys [id] :as user}]

    [yetibot.core.chat :refer [chat-data-structure send-msg-for-each
                               register-chat-adapter] :as chat]))

(defn config [] (get-config :yetibot :adapters :slack))

(defonce conn (atom nil))

(defn self
  "Slack acount for yetibot from `rtm.start` (represented at (-> @conn :start)).
   You must call `start` in order to define `conn`."
  []
  (-> @conn :start :self))

(defn slack-config []
  (let [c (config)]
    {:api-url (:endpoint c) :token (:token c)}))

(def ^{:dynamic true
       :doc "the channel or user that a message came from"} *target*)

(defn rooms [] (:rooms (config)))

;;;;


;; start/stop

(defn stop []
  (when @*conn*
    (log/info "Closing" @*conn*)
    (slack/send-event (:dispatcher @*conn*) :close))
  (reset! *conn* nil))

(defn start []
  (stop)
  (let [ac (all-config)
        ; make it a vector if it isn't already
        configs (if (map? ac) [ac] ac)]
    (dorun
      (map
        (fn [config]
          (binding [*config* config
                    *conn* (atom nil)]
            (log/info "setting up" *config*)
            (reset! *conn* (slack/connect (slack-config)
                                          :on-connect on-connect
                                          :on-error on-error
                                          :on-close on-close
                                          :presence_change on-presence-change
                                          :channel_joined on-channel-joined
                                          :group_joined on-channel-joined
                                          :channel_left on-channel-left
                                          :group_left on-channel-left
                                          :manual_presence_change on-manual-presence-change
                                          :message on-message
                                          :hello on-hello))
            (reset-users-from-conn)))
        configs))))

(defn list-channels [] (channels/list (slack-config)))

