Created
May 13, 2018 15:16
-
-
Save kjensenxz/8604fcc543e6d2d23ce9debdded61e57 to your computer and use it in GitHub Desktop.
CLI client for adedomin/neomoose
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 characters
#!/usr/bin/env node | |
const reladate = require('relative-date'), | |
https = require('https'); | |
const mooseShade = { | |
0: '\x1b[47mâ–‘', | |
1: '\x1b[47mâ–’', | |
2: '\x1b[47mâ–“', | |
3: 'â–ˆ', | |
4: '\x1b[40mâ–“', | |
5: '\x1b[40mâ–’', | |
6: '\x1b[40mâ–‘', | |
}; | |
const mooseColor = { | |
0: ['white', '37'], | |
1: ['black', '30'], | |
2: ['navy', '34'], | |
3: ['green', '32'], | |
4: ['red', '91'], | |
5: ['brown', '31'], | |
6: ['purple', '35'], | |
7: ['olive', '33'], | |
8: ['yellow', '93'], | |
9: ['lime', '92'], | |
a: ['teal', '36'], | |
b: ['cyan', '96'], | |
c: ['blue', '94'], | |
d: ['pink', '95'], | |
e: ['gray', '90'], | |
f: ['silver', '37'], | |
}; | |
var moose, | |
path = process.argv.slice(2).join(' ') || 'random'; | |
https.get(`https://moose.ghetty.space/moose/${path}`, (res) => { | |
let data = ''; | |
res.on('data', (chunk) => { | |
data += chunk; | |
}); | |
res.on('end', () => { | |
moose = JSON.parse(data); | |
if (moose.status) { | |
console.log(`${moose.status + ': ' + moose.msg}`) | |
process.exit(0); | |
} | |
parseMoose(moose); | |
console.log(moose.name); | |
console.log('Created ' + reladate(new Date(moose.created))); | |
}); | |
}).on('error', (err) => { | |
console.log(err.message); | |
}); | |
var parseMoose = (moose) => { | |
var shade = moose.shade.split('\n'), | |
image = moose.image.split('\n'), | |
date = moose.date, | |
name = moose.name; | |
image.map((e, i) => { | |
var lineShade = shade[i], | |
line = e, | |
thisLine = ''; | |
line.split('').map((charColor, ind) => { | |
var thisChar = '', | |
charShade = lineShade ? lineShade[ind] : 3; | |
if (charColor == 't') thisChar += ' '; | |
else thisChar += `\x1b[${mooseColor[charColor][1]}m` + mooseShade[charShade]; | |
thisLine += thisChar; | |
}); | |
if (thisLine != false) | |
console.log(thisLine + '\x1b[0m'); | |
}); | |
} |
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 characters
{ | |
"dependencies": { | |
"relative-date": "^1.1.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment