84 lines
3.3 KiB
JavaScript
84 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
require('./dotenv-module');
|
|
|
|
var _https = require('https');
|
|
|
|
var _https2 = _interopRequireDefault(_https);
|
|
|
|
var _request = require('request');
|
|
|
|
var _request2 = _interopRequireDefault(_request);
|
|
|
|
var _express = require('express');
|
|
|
|
var _express2 = _interopRequireDefault(_express);
|
|
|
|
var _bodyParser = require('body-parser');
|
|
|
|
var _bodyParser2 = _interopRequireDefault(_bodyParser);
|
|
|
|
var _moment = require('moment');
|
|
|
|
var _moment2 = _interopRequireDefault(_moment);
|
|
|
|
var _strategies = require('./strategies');
|
|
|
|
var _strategies2 = _interopRequireDefault(_strategies);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
var app = (0, _express2.default)();
|
|
|
|
app.use(_bodyParser2.default.urlencoded({ extended: false }));
|
|
app.use(_bodyParser2.default.json());
|
|
|
|
app.get('/', function (req, res) {
|
|
var theStrategy = _strategies2.default[Math.floor(Math.random() * _strategies2.default.length)];
|
|
var theTree = '<!doctype html>\n <html lang=\'en\'>\n <head>\n <meta name=\'viewport\' content=\'width=device-width, initial-scale=1\'>\n <link rel=\'apple-touch-icon\' href=\'./touch_icon.png\'>\n <title>\n ' + theStrategy.toLowerCase() + '\n </title>\n <meta charset=\'utf-8\'>\n </head>\n <body style=\'background-color:#111; margin:0; padding:0; display:flex;align-items:center;justify-content:center;min-height:24em;\'>\n <div style=\'color:#eee;margin:0 auto; max-width:80%;flex:1;text-align:center;font-family:Futura;font-size:30px;line-height:40px\'>\n ' + theStrategy.toLowerCase() + '\n </div>\n </body>\n </html>';
|
|
|
|
res.write(theTree);
|
|
console.log('\non ' + (0, _moment2.default)().format('dddd, MMMM Do YYYY, h:mma').toLowerCase() + ' a card was drawn');
|
|
res.end();
|
|
});
|
|
|
|
app.post('/', function (req, res, next) {
|
|
if (req.body.type === 'url_verification') {
|
|
return res.status(200).json(req.body.challenge);
|
|
}
|
|
|
|
// slash command
|
|
if (req.body.command) {
|
|
var channel = req.body.channel_id;
|
|
|
|
res.sendStatus(200);
|
|
var theResponse = {
|
|
hostname: 'slack.com',
|
|
path: '/api/chat.postMessage?token=' + process.env.BOTACCESSTOKEN,
|
|
port: 443,
|
|
method: 'POST',
|
|
channel: channel,
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
};
|
|
|
|
var theStrategy = encodeURIComponent(_strategies2.default[Math.floor(Math.random() * _strategies2.default.length)].toLowerCase());
|
|
|
|
var theResponseRequest = _https2.default.request({
|
|
host: 'slack.com',
|
|
path: '/api/chat.postMessage?token=' + process.env.BOTACCESSTOKEN + '&channel=' + channel + '&text=' + theStrategy
|
|
}, function (response) {
|
|
return response.on('data', function (b) {
|
|
console.log('\non ' + (0, _moment2.default)().format('dddd, MMMM Do YYYY, h:mma').toLowerCase() + ' a card was drawn');
|
|
console.log(' via slack: ' + b);
|
|
});
|
|
}).end();
|
|
|
|
return res.status(200).end();
|
|
}
|
|
});
|
|
|
|
app.listen(4242, function () {
|
|
console.log('oblique strategies are being served');
|
|
}); |