Created
June 22, 2017 22:35
-
-
Save adam8810/a25aed6eb5621af221d0c3a36c527e24 to your computer and use it in GitHub Desktop.
Revisions
-
adam8810 created this gist
Jun 22, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ var Slack = require('slack-node'), T = require ('data.task'), R = require ('ramda'), M = require ('control.monads'), logI = function (x) { console.log (x); return x; }, id = function (x) { return x; }, konst = R.curry (function (a, b) { return a; }), du = function (M) { return function () { return R.apply (R.pipe, arguments)(M.of ({})); }; }, bind = function (a) { return R.chain (konst (a)); }, chain = R.chain, map = R.map, ap = R.curry (function (ma, mf) { return mf.ap (ma); }), random = R.curry (function (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }), runTaskIO = R.curry (function (rej, res, t) { return IO (function () { t.fork (rej, res); }); }), apiToken = "xoxp-TOKEN", getFileIds = function (slack, channel) { return new T (function (reject, resolve) { slack.api("files.list", { channel: channel }, function(err, response) { if (err) { return reject (err); } return resolve (map (R.prop ('id'), R.prop ('files', response))); }); }); }, deleteFile = R.curry (function (slack, fileId) { return new T (function (reject, resolve) { slack.api ('files.delete', { file: fileId }, function (err, res) { if (err) { return reject (err); } return resolve (res); }); }); }), main = function () { const slack = new Slack(apiToken), channel = "CHANNEL_NAME"; du (T) ( bind (getFileIds (slack, channel)) , map (map (deleteFile (slack))) , chain (M.sequence (T)) , id ).fork (logI, logI); }, nil = null; main ();