Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
Created August 13, 2016 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennethkalmer/6aa50499da446ecc77c4f7b4f5e01ca4 to your computer and use it in GitHub Desktop.
Save kennethkalmer/6aa50499da446ecc77c4f7b4f5e01ca4 to your computer and use it in GitHub Desktop.
Simple clojure code used to invite all the members of the ZA Developer slack team into a specific channel to discuss amendments to the code-of-conduct :)
(require 'clj-slack.users)
(require 'clj-slack.channels)
(def connection {:api-url "https://slack.com/api" :token "TOKEN"})
;; Get all the users and channels
(def users (clj-slack.users/list connection))
(def channels (clj-slack.channels/list connection))
;; Find the channel we care about
(def channel (first (filter #(= "code-of-conduct" (:name %)) (:channels channels))))
;; Find the existing members in the channel
(def existing-members (:members channel))
;; Get all the active, non-bot team members
(def candidates (->> (:members users) (remove :deleted) (remove :is_bot) (map :id)))
;; Now get the ones to be invited
(def to-be-invited (clojure.set/difference (set candidates) (set existing-members)))
;; Partial functions FTW
(def invite-fn (partial clj-slack.channels/invite connection (:id channel)))
;; Invite each member
(doseq [id to-be-invited] (invite-fn id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment