Created
August 13, 2016 15:02
-
-
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 :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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