Transpile down to ES2015.

This commit is contained in:
nicholas 2019-03-18 22:45:12 -04:00
parent c500fb953a
commit 3aac94feb2
12 changed files with 3572 additions and 208 deletions

3
.babelrc Normal file
View File

@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}

9
lib/dotenv-module.js Normal file
View File

@ -0,0 +1,9 @@
'use strict';
var _dotenv = require('dotenv');
var _dotenv2 = _interopRequireDefault(_dotenv);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_dotenv2.default.config();

84
lib/index.js Normal file
View File

@ -0,0 +1,84 @@
'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');
});

5
lib/strategies.js Normal file

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

3270
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
"description": "Slack bot who responds to mentions with a random card from Brian Eno's Oblique Strategies deck",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel --presets es2015 -d lib/ src"
},
"author": "Nicholas Warzin",
"repository": "https://nickwarzin.com:4243/nicholas/oblique-strategies",
@ -16,5 +17,9 @@
"helmet": "^3.15.1",
"moment": "^2.23.0",
"request": "^2.88.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1"
}
}

3
src/dotenv-module.js Normal file
View File

@ -0,0 +1,3 @@
import dotenv from 'dotenv';
dotenv.config();

View File

@ -1,33 +1,18 @@
require('dotenv').config();
const https = require('https');
const request = require('request');
const express = require('express');
const bodyParser = require('body-parser');
const moment = require('moment');
const { Console } = require('console');
const fs = require('fs');
const strategies = require('./strategies');
import './dotenv-module';
import https from 'https';
import request from 'request';
import express from 'express';
import bodyParser from 'body-parser';
import moment from 'moment';
import strategies from './strategies';
const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
const output = fs.createWriteStream('./access.log', {flags: 'a'});
const errorOutput = fs.createWriteStream('./error.log', {flags: 'a'});
const fileLog = new Console(output, errorOutput);
const logger = {
log: message => {
console.log(message);
fileLog.log(message);
},
error: message => {
console.error(message);
fileLog.error(message);
}
}
app.get('/', (req, res) => {
const theStrategy = strategies[ Math.floor(Math.random()*strategies.length) ];
const theTree =
@ -49,7 +34,7 @@ app.get('/', (req, res) => {
</html>`;
res.write(theTree);
logger.log('\non '+moment().format('dddd, MMMM Do YYYY, h:mma').toLowerCase()+' a card was drawn');
console.log('\non '+moment().format('dddd, MMMM Do YYYY, h:mma').toLowerCase()+' a card was drawn');
res.end();
});
@ -82,8 +67,8 @@ app.post('/', (req, res, next) => {
path: `/api/chat.postMessage?token=${process.env.BOTACCESSTOKEN}&channel=${channel}&text=${theStrategy}`,
},
response => response.on('data', b => {
logger.log('\non '+moment().format('dddd, MMMM Do YYYY, h:mma').toLowerCase()+' a card was drawn');
logger.log(' via slack: '+b);
console.log('\non '+moment().format('dddd, MMMM Do YYYY, h:mma').toLowerCase()+' a card was drawn');
console.log(' via slack: '+b);
})
).end();
@ -93,5 +78,5 @@ app.post('/', (req, res, next) => {
});
app.listen(4242, () => {
console.log('oblique strategies are being served')
console.log(`oblique strategies are being served`)
});

179
src/strategies.js Normal file
View File

@ -0,0 +1,179 @@
const strategies = [
`(Organic) machinery`,
`A line has two sides`,
`A very small object... its center`,
`Abandon desire`,
`Abandon normal instructions`,
`Accept advice`,
`Accretion`,
`Adding on`,
`Allow an easement (an easement is the abandonment of a stricture)`,
`Always first steps`,
`Always give yourself credit for having more than personality`,
`Always the first steps`,
`Are there sections? Consider transitions`,
`Ask people to work against their better judgement`,
`Ask your body`,
`Assemble some of the elements in a group and treat the group`,
`Balance the consistency principle with the inconsistency principle`,
`Be dirty`,
`Be extravagant`,
`Be less critical`,
`Breathe more deeply`,
`Bridges: build, burn`,
`Cascades`,
`Change ambiguities to specifics`,
`Change instrument roles`,
`Change nothing and continue with immaculate consistency`,
`Change specifics to ambiguities`,
`Children: speaking, singing`,
`Cluster analysis`,
`Consider different fading systems`,
`Consider transitions`,
`Consult other sources: promising, unpromising`,
`Convert a melodic element into a rhythmic element`,
`Courage!`,
`Cut a vital connection`,
`Decorate, decorate`,
`Define an area as 'safe' and use it as an anchor`,
`Destroy nothing; Destroy the most important thing`,
`Discard an axiom`,
`Disciplined self-indulgence`,
`Disconnect from desire`,
`Discover the recipes you are using and abandon them`,
`Distort time`,
`Do nothing for as long as possible`,
`Do something boring`,
`Do something sudden, destructive, and unpredictable`,
`Do the last thing first`,
`Do the washing up`,
`Do the words need changing?`,
`Do we need holes?`,
`Don't avoid what is easy`,
`Don't be frightened of cliches`,
`Don't break the silence`,
`Don't stress one thing more than another`,
`Dont be afraid of things because they're easy to do`,
`Dont be frightened to display your talents`,
`Emphasize differences`,
`Emphasize repetitions`,
`Emphasize the flaws`,
`Faced with a choice, do both`,
`Feed the recording back out of the medium`,
`Fill every beat with something`,
`Find a safe part and use it as an anchor`,
`Get your neck massaged`,
`Ghost echoes`,
`Give the game away`,
`Give the name away`,
`Give way to your worst impulse`,
`Go outside. Shut the door.`,
`Go slowly all the way round the outside`,
`Go to an extreme, come part way back`,
`Honour thy error as a hidden intention`,
`How would someone else do it?`,
`How would you have done it?`,
`Humanize something free of error`,
`Imagine the piece as a set of disconnected events`,
`In total darkness, or in a very large room, very quietly`,
`Infinitesimal gradations`,
`Intentions: nobility of, humility of, credibility of`,
`Into the impossible`,
`Is it finished?`,
`Is something missing?`,
`Is the information correct?`,
`Is the style right?`,
`It is quite possible (after all)`,
`It is simply a matter or work`,
`Just carry on`,
`Left channel, right channel, center channel`,
`Listen to the quiet voice`,
`Look at the order in which you do things`,
`Look closely at the most embarrassing details & amplify them`,
`Lost in useless territory`,
`Lowest common denominator`,
`Magnify the most difficult details`,
`Make a blank valuable by putting it in an exquisite frame`,
`Make an exhaustive list of everything you might do & do the last thing on the list`,
`Make it more sensual`,
`Make what's perfect more human`,
`Mechanicalize something idiosyncratic`,
`Move towards the unimportant`,
`Mute and continue`,
`Not building a wall but making a brick`,
`Once the search has begun, something will be found`,
`Only a part, not the whole`,
`Only one element of each kind`,
`Openly resist change`,
`[blank]`,
`Put in earplugs`,
`Question the heroic`,
`Reevaluation (a warm feeling)`,
`Remember quiet evenings`,
`Remove a restriction`,
`Remove ambiguities and convert to specifics`,
`Remove specifics and convert to ambiguities`,
`Repetition is a form of change`,
`Retrace your steps`,
`Reverse`,
`Simple subtraction`,
`Simply a matter of work`,
`Slow preparation, fast execution`,
`Spectrum analysis`,
`State the problem as clearly as possible`,
`Take a break`,
`Take away the elements in order of apparent non-importance`,
`Take away the important parts`,
`The inconsistency principle`,
`The most easily forgotten thing is the most important`,
`The most important thing is the thing most easily forgotten`,
`The tape is now the music`,
`Think: inside the work, outside the work`,
`Think of the radio`,
`Tidy up`,
`Towards the insignificant`,
`Trust in the you of now`,
`Try faking it`,
`Turn it upside down`,
`Twist the spine`,
`Use an old idea`,
`Use an unacceptable colour`,
`Use clichés`,
`Use fewer notes`,
`Use filters`,
`Use something nearby as a model`,
`Use your own ideas`,
`Voice your suspicions`,
`~water~`,
`What are the sections sections of? ...imagine a caterpillar moving`,
`What context would look right?`,
`What is the reality of the situation?`,
`What is the simplest solution?`,
`What mistakes did you make last time?`,
`What to increase? What to reduce? What to maintain?`,
`What were you really thinking about just now?`,
`What would your closest friend do?`,
`What wouldn't you do?`,
`When is it for?`,
`Where is the edge?`,
`Which parts can be grouped?`,
`Work at a different speed`,
`Would anyone want it?`,
`You are an engineer`,
`You can only make one dot at a time`,
`You don't have to be ashamed of using your own ideas`,
`Bridges: build, burn`,
`Faced with a choice, do both`,
`Think—inside the work—outside the work`,
`Try faking it`,
`Your mistake was a hidden intention`,
`Bridges\n-build\n-burn`,
`Always give yourself credit for having more than personality`,
`Tape your mouth`,
`Consult other sources\n-promising\n-unpromising`,
`Short circuit`,
];
module.exports = strategies;

BIN
src/touch_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -1,179 +0,0 @@
const strategies = [
"(Organic) machinery",
"A line has two sides",
"A very small object... its center",
"Abandon desire",
"Abandon normal instructions",
"Accept advice",
"Accretion",
"Adding on",
"Allow an easement (an easement is the abandonment of a stricture)",
"Always first steps",
"Always give yourself credit for having more than personality",
"Always the first steps",
"Are there sections? Consider transitions",
"Ask people to work against their better judgement",
"Ask your body",
"Assemble some of the elements in a group and treat the group",
"Balance the consistency principle with the inconsistency principle",
"Be dirty",
"Be extravagant",
"Be less critical",
"Breathe more deeply",
"Bridges: build, burn",
"Cascades",
"Change ambiguities to specifics",
"Change instrument roles",
"Change nothing and continue with immaculate consistency",
"Change specifics to ambiguities",
"Children: speaking, singing",
"Cluster analysis",
"Consider different fading systems",
"Consider transitions",
"Consult other sources: promising, unpromising",
"Convert a melodic element into a rhythmic element",
"Courage!",
"Cut a vital connection",
"Decorate, decorate",
"Define an area as 'safe' and use it as an anchor",
"Destroy nothing; Destroy the most important thing",
"Discard an axiom",
"Disciplined self-indulgence",
"Disconnect from desire",
"Discover the recipes you are using and abandon them",
"Distort time",
"Do nothing for as long as possible",
"Do something boring",
"Do something sudden, destructive, and unpredictable",
"Do the last thing first",
"Do the washing up",
"Do the words need changing?",
"Do we need holes?",
"Don't avoid what is easy",
"Don't be frightened of cliches",
"Don't break the silence",
"Don't stress one thing more than another",
"Dont be afraid of things because they're easy to do",
"Dont be frightened to display your talents",
"Emphasize differences",
"Emphasize repetitions",
"Emphasize the flaws",
"Faced with a choice, do both",
"Feed the recording back out of the medium",
"Fill every beat with something",
"Find a safe part and use it as an anchor",
"Get your neck massaged",
"Ghost echoes",
"Give the game away",
"Give the name away",
"Give way to your worst impulse",
"Go outside. Shut the door.",
"Go slowly all the way round the outside",
"Go to an extreme, come part way back",
"Honour thy error as a hidden intention",
"How would someone else do it?",
"How would you have done it?",
"Humanize something free of error",
"Imagine the piece as a set of disconnected events",
"In total darkness, or in a very large room, very quietly",
"Infinitesimal gradations",
"Intentions: nobility of, humility of, credibility of",
"Into the impossible",
"Is it finished?",
"Is something missing?",
"Is the information correct?",
"Is the style right?",
"It is quite possible (after all)",
"It is simply a matter or work",
"Just carry on",
"Left channel, right channel, center channel",
"Listen to the quiet voice",
"Look at the order in which you do things",
"Look closely at the most embarrassing details & amplify them",
"Lost in useless territory",
"Lowest common denominator",
"Magnify the most difficult details",
"Make a blank valuable by putting it in an exquisite frame",
"Make an exhaustive list of everything you might do & do the last thing on the list",
"Make it more sensual",
"Make what's perfect more human",
"Mechanicalize something idiosyncratic",
"Move towards the unimportant",
"Mute and continue",
"Not building a wall but making a brick",
"Once the search has begun, something will be found",
"Only a part, not the whole",
"Only one element of each kind",
"Openly resist change",
"[blank]",
"Put in earplugs",
"Question the heroic",
"Reevaluation (a warm feeling)",
"Remember quiet evenings",
"Remove a restriction",
"Remove ambiguities and convert to specifics",
"Remove specifics and convert to ambiguities",
"Repetition is a form of change",
"Retrace your steps",
"Reverse",
"Simple subtraction",
"Simply a matter of work",
"Slow preparation, fast execution",
"Spectrum analysis",
"State the problem as clearly as possible",
"Take a break",
"Take away the elements in order of apparent non-importance",
"Take away the important parts",
"The inconsistency principle",
"The most easily forgotten thing is the most important",
"The most important thing is the thing most easily forgotten",
"The tape is now the music",
"Think: inside the work, outside the work",
"Think of the radio",
"Tidy up",
"Towards the insignificant",
"Trust in the you of now",
"Try faking it",
"Turn it upside down",
"Twist the spine",
"Use an old idea",
"Use an unacceptable colour",
"Use clichés",
"Use fewer notes",
"Use filters",
"Use something nearby as a model",
"Use your own ideas",
"Voice your suspicions",
"~water~",
"What are the sections sections of? ...imagine a caterpillar moving",
"What context would look right?",
"What is the reality of the situation?",
"What is the simplest solution?",
"What mistakes did you make last time?",
"What to increase? What to reduce? What to maintain?",
"What were you really thinking about just now?",
"What would your closest friend do?",
"What wouldn't you do?",
"When is it for?",
"Where is the edge?",
"Which parts can be grouped?",
"Work at a different speed",
"Would anyone want it?",
"You are an engineer",
"You can only make one dot at a time",
"You don't have to be ashamed of using your own ideas",
"Bridges: build, burn",
"Faced with a choice, do both",
"Think—inside the work—outside the work",
"Try faking it",
"Your mistake was a hidden intention",
"Bridges\n-build\n-burn",
"Always give yourself credit for having more than personality",
"Tape your mouth",
"Consult other sources\n-promising\n-unpromising",
"Short circuit",
];
module.exports = strategies;