Complete refractor

This commit is contained in:
Wessel Damian Tip
2019-01-15 19:49:56 +01:00
parent c7c64b69fb
commit a7b6e89b0a
22 changed files with 201 additions and 874 deletions

2
.gitattributes vendored
View File

@@ -1,2 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto

6
.gitignore vendored
View File

@@ -1,6 +0,0 @@
node_modules/
.vscode/
.eslintignore
.eslintrc
yarn.lock

View File

@@ -1,7 +1,7 @@
The MIT License (MIT)
Copyright (c) 2018 Wessel Tip
Copyright (c) 2019-present Wessel "wesselgame" T
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,33 +1,45 @@
# Snowflakey - Discord snowflake lookup
This is just some simple code to look up any snowflake on discord.
## What is a snowflake?
Snowflakes are strings from 14 to 16 characters long that determine
Which user/message/guild is which. You can't get much data with
just a snowflake, but you can get the creation date of the snowflake.
## Getting a snowflake
To get a user/message/guild's snowflake, go to the following path:
Settings > Apperance > Developer Mode > Slider should be blurple.
After you've enabled developer mode, go to a user/message/guild
and right-click on it. You'll see an option called "Copy ID"
## Using snowflakey
It's very simple to use snowflakey, all you gotta do is run
"yarn start" or "npm start" to start the script.
#### Requirements
* A device
* NodeJS v8.0+
* Yarn (NPM alternative, works faster)
* Git (Not required, makes things easier)
#### Installation
Installing:
```bash
git clone https://www.github.com/PassTheWessel/snowflakey.git # Or clone from the site
yarn # or npm i
node index.js # Run snowflakey
# snowflakey
> A lightweight Node.js snowflake generator/lookup tool
> [GitHub](https://www.github.com/PassTheWessel/Snowflakey) **|** [NPM](https://www.npmjs.com/package/snowflakey)
## Installing
```sh
$ yarn add snowflakey # Install w/ Yarn (the superior package manager)
$ npm i snowflakey # Install w/ NPM
```
Example:
```bash
? Snowflake >> 107130754189766660
>> Creation date of snowflake "107130754189766660": 2015-10-23 16:59:22
## Usage
##### Code
```js
// require & generate the instance
const Snowflake = require( './generator' );
const snowflake = new Snowflake.generator({
processBits: 0,
workerBits: 8,
incrementBits: 14,
workerId: process.env.CLUSTER_ID || 31
});
// exports for global use
exports.makeSnowflake = ( date ) => { return snowflake._generate( date ); };
exports.unmakeSnowflake = ( flake ) => { let decon = snowflake.deconstruct( flake ); return decon.timestamp.valueOf(); };
// example
const flake = this.makeSnowflake( Date.now() );
console.log( flake );
console.log( `Creation date: ${Snowflake.lookup( flake, 1420070400000 )}` );
console.log( this.unmakeSnowflake( flake ) );
```
## Credits
N/A
##### Result
```sh
$ node test.js
534760094454759424
Creation date: 2019-1-15 16:45:41
1547567141880
```
### What is a snowflake?
Snowflakes are strings that range from 14 to 19 characters long that can give every user it's unique idea. You can't get much data with just a snowflake, but you can get the creation date of the snowflake and identify every unique user with it.
##### Refrence
<img src="https://github.com/PassTheWessel/Snowflakey/tree/master/media/refrence.png">

View File

@@ -1,4 +0,0 @@
var colors = require('./lib/colors');
module['exports'] = colors;
require('./lib/extendStringPrototype')();

View File

@@ -1,201 +0,0 @@
/*
The MIT License (MIT)
Original Library
- Copyright (c) Marak Squires
Additional functionality
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var colors = {};
module['exports'] = colors;
colors.themes = {};
var util = require('util');
var ansiStyles = colors.styles = require('./styles');
var defineProps = Object.defineProperties;
var newLineRegex = new RegExp(/[\r\n]+/g);
colors.supportsColor = require('./system/supports-colors').supportsColor;
if (typeof colors.enabled === 'undefined') {
colors.enabled = colors.supportsColor() !== false;
}
colors.enable = function() {
colors.enabled = true;
};
colors.disable = function() {
colors.enabled = false;
};
colors.stripColors = colors.strip = function(str) {
return ('' + str).replace(/\x1B\[\d+m/g, '');
};
// eslint-disable-next-line no-unused-vars
var stylize = colors.stylize = function stylize(str, style) {
if (!colors.enabled) {
return str+'';
}
return ansiStyles[style].open + str + ansiStyles[style].close;
};
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
var escapeStringRegexp = function(str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return str.replace(matchOperatorsRe, '\\$&');
};
function build(_styles) {
var builder = function builder() {
return applyStyle.apply(builder, arguments);
};
builder._styles = _styles;
// __proto__ is used because we must return a function, but there is
// no way to create a function with a different prototype.
builder.__proto__ = proto;
return builder;
}
var styles = (function() {
var ret = {};
ansiStyles.grey = ansiStyles.gray;
Object.keys(ansiStyles).forEach(function(key) {
ansiStyles[key].closeRe =
new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
ret[key] = {
get: function() {
return build(this._styles.concat(key));
}
};
});
return ret;
})();
var proto = defineProps(function colors() {}, styles);
function applyStyle() {
var args = Array.prototype.slice.call(arguments);
var str = args.map(function(arg) {
if (arg !== undefined && arg.constructor === String) {
return arg;
} else {
return util.inspect(arg);
}
}).join(' ');
if (!colors.enabled || !str) {
return str;
}
var newLinesPresent = str.indexOf('\n') != -1;
var nestedStyles = this._styles;
var i = nestedStyles.length;
while (i--) {
var code = ansiStyles[nestedStyles[i]];
str = code.open + str.replace(code.closeRe, code.open) + code.close;
if (newLinesPresent) {
str = str.replace(newLineRegex, function(match) {
return code.close + match + code.open;
});
}
}
return str;
}
colors.setTheme = function(theme) {
if (typeof theme === 'string') {
console.log('colors.setTheme now only accepts an object, not a string. ' +
'If you are trying to set a theme from a file, it is now your (the ' +
'caller\'s) responsibility to require the file. The old syntax ' +
'looked like colors.setTheme(__dirname + ' +
'\'/../themes/generic-logging.js\'); The new syntax looks like '+
'colors.setTheme(require(__dirname + ' +
'\'/../themes/generic-logging.js\'));');
return;
}
for (var style in theme) {
(function(style) {
colors[style] = function(str) {
if (typeof theme[style] === 'object') {
var out = str;
for (var i in theme[style]) {
out = colors[theme[style][i]](out);
}
return out;
}
return colors[theme[style]](str);
};
})(style);
}
};
function init() {
var ret = {};
Object.keys(styles).forEach(function(name) {
ret[name] = {
get: function() {
return build([name]);
}
};
});
return ret;
}
var sequencer = function sequencer(map, str) {
var exploded = str.split('');
exploded = exploded.map(map);
return exploded.join('');
};
// custom formatter methods
colors.trap = require('./custom/trap');
colors.zalgo = require('./custom/zalgo');
// maps
colors.maps = {};
colors.maps.america = require('./maps/america')(colors);
colors.maps.zebra = require('./maps/zebra')(colors);
colors.maps.rainbow = require('./maps/rainbow')(colors);
colors.maps.random = require('./maps/random')(colors);
for (var map in colors.maps) {
(function(map) {
colors[map] = function(str) {
return sequencer(colors.maps[map], str);
};
})(map);
}
defineProps(colors, init());

View File

@@ -1,46 +0,0 @@
module['exports'] = function runTheTrap(text, options) {
var result = '';
text = text || 'Run the trap, drop the bass';
text = text.split('');
var trap = {
a: ['\u0040', '\u0104', '\u023a', '\u0245', '\u0394', '\u039b', '\u0414'],
b: ['\u00df', '\u0181', '\u0243', '\u026e', '\u03b2', '\u0e3f'],
c: ['\u00a9', '\u023b', '\u03fe'],
d: ['\u00d0', '\u018a', '\u0500', '\u0501', '\u0502', '\u0503'],
e: ['\u00cb', '\u0115', '\u018e', '\u0258', '\u03a3', '\u03be', '\u04bc',
'\u0a6c'],
f: ['\u04fa'],
g: ['\u0262'],
h: ['\u0126', '\u0195', '\u04a2', '\u04ba', '\u04c7', '\u050a'],
i: ['\u0f0f'],
j: ['\u0134'],
k: ['\u0138', '\u04a0', '\u04c3', '\u051e'],
l: ['\u0139'],
m: ['\u028d', '\u04cd', '\u04ce', '\u0520', '\u0521', '\u0d69'],
n: ['\u00d1', '\u014b', '\u019d', '\u0376', '\u03a0', '\u048a'],
o: ['\u00d8', '\u00f5', '\u00f8', '\u01fe', '\u0298', '\u047a', '\u05dd',
'\u06dd', '\u0e4f'],
p: ['\u01f7', '\u048e'],
q: ['\u09cd'],
r: ['\u00ae', '\u01a6', '\u0210', '\u024c', '\u0280', '\u042f'],
s: ['\u00a7', '\u03de', '\u03df', '\u03e8'],
t: ['\u0141', '\u0166', '\u0373'],
u: ['\u01b1', '\u054d'],
v: ['\u05d8'],
w: ['\u0428', '\u0460', '\u047c', '\u0d70'],
x: ['\u04b2', '\u04fe', '\u04fc', '\u04fd'],
y: ['\u00a5', '\u04b0', '\u04cb'],
z: ['\u01b5', '\u0240'],
};
text.forEach(function(c) {
c = c.toLowerCase();
var chars = trap[c] || [' '];
var rand = Math.floor(Math.random() * chars.length);
if (typeof trap[c] !== 'undefined') {
result += trap[c][rand];
} else {
result += c;
}
});
return result;
};

View File

@@ -1,110 +0,0 @@
// please no
module['exports'] = function zalgo(text, options) {
text = text || ' he is here ';
var soul = {
'up': [
'̍', '̎', '̄', '̅',
'̿', '̑', '̆', '̐',
'͒', '͗', '͑', '̇',
'̈', '̊', '͂', '̓',
'̈', '͊', '͋', '͌',
'̃', '̂', '̌', '͐',
'̀', '́', '̋', '̏',
'̒', '̓', '̔', '̽',
'̉', 'ͣ', 'ͤ', 'ͥ',
'ͦ', 'ͧ', 'ͨ', 'ͩ',
'ͪ', 'ͫ', 'ͬ', 'ͭ',
'ͮ', 'ͯ', '̾', '͛',
'͆', '̚',
],
'down': [
'̖', '̗', '̘', '̙',
'̜', '̝', '̞', '̟',
'̠', '̤', '̥', '̦',
'̩', '̪', '̫', '̬',
'̭', '̮', '̯', '̰',
'̱', '̲', '̳', '̹',
'̺', '̻', '̼', 'ͅ',
'͇', '͈', '͉', '͍',
'͎', '͓', '͔', '͕',
'͖', '͙', '͚', '̣',
],
'mid': [
'̕', '̛', '̀', '́',
'͘', '̡', '̢', '̧',
'̨', '̴', '̵', '̶',
'͜', '͝', '͞',
'͟', '͠', '͢', '̸',
'̷', '͡', ' ҉',
],
};
var all = [].concat(soul.up, soul.down, soul.mid);
function randomNumber(range) {
var r = Math.floor(Math.random() * range);
return r;
}
function isChar(character) {
var bool = false;
all.filter(function(i) {
bool = (i === character);
});
return bool;
}
function heComes(text, options) {
var result = '';
var counts;
var l;
options = options || {};
options['up'] =
typeof options['up'] !== 'undefined' ? options['up'] : true;
options['mid'] =
typeof options['mid'] !== 'undefined' ? options['mid'] : true;
options['down'] =
typeof options['down'] !== 'undefined' ? options['down'] : true;
options['size'] =
typeof options['size'] !== 'undefined' ? options['size'] : 'maxi';
text = text.split('');
for (l in text) {
if (isChar(l)) {
continue;
}
result = result + text[l];
counts = {'up': 0, 'down': 0, 'mid': 0};
switch (options.size) {
case 'mini':
counts.up = randomNumber(8);
counts.mid = randomNumber(2);
counts.down = randomNumber(8);
break;
case 'maxi':
counts.up = randomNumber(16) + 3;
counts.mid = randomNumber(4) + 1;
counts.down = randomNumber(64) + 3;
break;
default:
counts.up = randomNumber(8) + 1;
counts.mid = randomNumber(6) / 2;
counts.down = randomNumber(8) + 1;
break;
}
var arr = ['up', 'mid', 'down'];
for (var d in arr) {
var index = arr[d];
for (var i = 0; i <= counts[index]; i++) {
if (options[index]) {
result = result + soul[index][randomNumber(soul[index].length)];
}
}
}
}
return result;
}
// don't summon him
return heComes(text, options);
};

View File

@@ -1,104 +0,0 @@
var colors = require('./colors');
module['exports'] = function() {
//
// Extends prototype of native string object to allow for "foo".red syntax
//
var addProperty = function(color, func) {
String.prototype.__defineGetter__(color, func);
};
addProperty('strip', function() {
return colors.strip(this);
});
addProperty('stripColors', function() {
return colors.strip(this);
});
addProperty('trap', function() {
return colors.trap(this);
});
addProperty('zalgo', function() {
return colors.zalgo(this);
});
addProperty('zebra', function() {
return colors.zebra(this);
});
addProperty('rainbow', function() {
return colors.rainbow(this);
});
addProperty('random', function() {
return colors.random(this);
});
addProperty('america', function() {
return colors.america(this);
});
//
// Iterate through all default styles and colors
//
var x = Object.keys(colors.styles);
x.forEach(function(style) {
addProperty(style, function() {
return colors.stylize(this, style);
});
});
function applyTheme(theme) {
//
// Remark: This is a list of methods that exist
// on String that you should not overwrite.
//
var stringPrototypeBlacklist = [
'__defineGetter__', '__defineSetter__', '__lookupGetter__',
'__lookupSetter__', 'charAt', 'constructor', 'hasOwnProperty',
'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString',
'valueOf', 'charCodeAt', 'indexOf', 'lastIndexOf', 'length',
'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice',
'split', 'substring', 'toLocaleLowerCase', 'toLocaleUpperCase',
'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight',
];
Object.keys(theme).forEach(function(prop) {
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
console.log('warn: '.red + ('String.prototype' + prop).magenta +
' is probably something you don\'t want to override. ' +
'Ignoring style name');
} else {
if (typeof(theme[prop]) === 'string') {
colors[prop] = colors[theme[prop]];
} else {
var tmp = colors[theme[prop][0]];
for (var t = 1; t < theme[prop].length; t++) {
tmp = tmp[theme[prop][t]];
}
colors[prop] = tmp;
}
addProperty(prop, function() {
return colors[prop](this);
});
}
});
}
colors.setTheme = function(theme) {
if (typeof theme === 'string') {
console.log('colors.setTheme now only accepts an object, not a string. ' +
'If you are trying to set a theme from a file, it is now your (the ' +
'caller\'s) responsibility to require the file. The old syntax ' +
'looked like colors.setTheme(__dirname + ' +
'\'/../themes/generic-logging.js\'); The new syntax looks like '+
'colors.setTheme(require(__dirname + ' +
'\'/../themes/generic-logging.js\'));');
return;
} else {
applyTheme(theme);
}
};
};

View File

@@ -1,10 +0,0 @@
module['exports'] = function(colors) {
return function(letter, i, exploded) {
if (letter === ' ') return letter;
switch (i%3) {
case 0: return colors.red(letter);
case 1: return colors.white(letter);
case 2: return colors.blue(letter);
}
};
};

View File

@@ -1,12 +0,0 @@
module['exports'] = function(colors) {
// RoY G BiV
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta'];
return function(letter, i, exploded) {
if (letter === ' ') {
return letter;
} else {
return colors[rainbowColors[i++ % rainbowColors.length]](letter);
}
};
};

View File

@@ -1,10 +0,0 @@
module['exports'] = function(colors) {
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
'blue', 'white', 'cyan', 'magenta'];
return function(letter, i, exploded) {
return letter === ' ' ? letter :
colors[
available[Math.round(Math.random() * (available.length - 2))]
](letter);
};
};

View File

@@ -1,5 +0,0 @@
module['exports'] = function(colors) {
return function(letter, i, exploded) {
return i % 2 === 0 ? letter : colors.inverse(letter);
};
};

View File

@@ -1,77 +0,0 @@
/*
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var styles = {};
module['exports'] = styles;
var codes = {
reset: [0, 0],
bold: [1, 22],
dim: [2, 22],
italic: [3, 23],
underline: [4, 24],
inverse: [7, 27],
hidden: [8, 28],
strikethrough: [9, 29],
black: [30, 39],
red: [31, 39],
green: [32, 39],
yellow: [33, 39],
blue: [34, 39],
magenta: [35, 39],
cyan: [36, 39],
white: [37, 39],
gray: [90, 39],
grey: [90, 39],
bgBlack: [40, 49],
bgRed: [41, 49],
bgGreen: [42, 49],
bgYellow: [43, 49],
bgBlue: [44, 49],
bgMagenta: [45, 49],
bgCyan: [46, 49],
bgWhite: [47, 49],
// legacy styles for colors pre v1.0.0
blackBG: [40, 49],
redBG: [41, 49],
greenBG: [42, 49],
yellowBG: [43, 49],
blueBG: [44, 49],
magentaBG: [45, 49],
cyanBG: [46, 49],
whiteBG: [47, 49],
};
Object.keys(codes).forEach(function(key) {
var val = codes[key];
var style = styles[key] = [];
style.open = '\u001b[' + val[0] + 'm';
style.close = '\u001b[' + val[1] + 'm';
});

View File

@@ -1,35 +0,0 @@
/*
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use strict';
module.exports = function(flag, argv) {
argv = argv || process.argv;
var terminatorPos = argv.indexOf('--');
var prefix = /^-{1,2}/.test(flag) ? '' : '--';
var pos = argv.indexOf(prefix + flag);
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
};

View File

@@ -1,151 +0,0 @@
/*
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
'use strict';
var os = require('os');
var hasFlag = require('./has-flag.js');
var env = process.env;
var forceColor = void 0;
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
forceColor = false;
} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true')
|| hasFlag('color=always')) {
forceColor = true;
}
if ('FORCE_COLOR' in env) {
forceColor = env.FORCE_COLOR.length === 0
|| parseInt(env.FORCE_COLOR, 10) !== 0;
}
function translateLevel(level) {
if (level === 0) {
return false;
}
return {
level: level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3,
};
}
function supportsColor(stream) {
if (forceColor === false) {
return 0;
}
if (hasFlag('color=16m') || hasFlag('color=full')
|| hasFlag('color=truecolor')) {
return 3;
}
if (hasFlag('color=256')) {
return 2;
}
if (stream && !stream.isTTY && forceColor !== true) {
return 0;
}
var min = forceColor ? 1 : 0;
if (process.platform === 'win32') {
// Node.js 7.5.0 is the first version of Node.js to include a patch to
// libuv that enables 256 color output on Windows. Anything earlier and it
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
// release, and Node.js 7 is not. Windows 10 build 10586 is the first
// Windows release that supports 256 colors. Windows 10 build 14931 is the
// first release that supports 16m/TrueColor.
var osRelease = os.release().split('.');
if (Number(process.versions.node.split('.')[0]) >= 8
&& Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
return Number(osRelease[2]) >= 14931 ? 3 : 2;
}
return 1;
}
if ('CI' in env) {
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function(sign) {
return sign in env;
}) || env.CI_NAME === 'codeship') {
return 1;
}
return min;
}
if ('TEAMCITY_VERSION' in env) {
return (/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0
);
}
if ('TERM_PROGRAM' in env) {
var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
switch (env.TERM_PROGRAM) {
case 'iTerm.app':
return version >= 3 ? 3 : 2;
case 'Hyper':
return 3;
case 'Apple_Terminal':
return 2;
// No default
}
}
if (/-256(color)?$/i.test(env.TERM)) {
return 2;
}
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
return 1;
}
if ('COLORTERM' in env) {
return 1;
}
if (env.TERM === 'dumb') {
return min;
}
return min;
}
function getSupportLevel(stream) {
var level = supportsColor(stream);
return translateLevel(level);
}
module.exports = {
supportsColor: getSupportLevel,
stdout: getSupportLevel(process.stdout),
stderr: getSupportLevel(process.stderr),
};

1
fake_node_modules/bigInt.js generated Normal file

File diff suppressed because one or more lines are too long

129
generator.js Normal file
View File

@@ -0,0 +1,129 @@
const big = require( './fake_node_modules/bigInt' );
const sleep = ( time = 1 ) => { return new Promise( res => { setTimeout( res, time ); } ); };
const getBits = ( bits ) => { return ( 2 ** bits ) - 1; };
exports.lookup = ( flake = 0, epoch = 1420070400000 ) => { return new Date( ( flake / 4194304 ) + epoch ).toLocaleString(); };
exports.generator = class Snowflake {
constructor( options = {} ) {
this.options = Object.assign({
async : false,
epoch : 1420070400000,
workerId : 0,
processId : 0,
stringify : true,
workerBits : 5,
processBits : 5,
incrementBits: 12
}, options);
// an object containing mutable (unfrozen) properties
this.mutable = {
locks : [],
locked : false,
increment : big.zero.subtract( 1 ),
lastTimestamp: Date.now()
};
if ( this.options.incrementBits + this.options.processBits + this.options.workerBits !== 22) throw new Error( 'incrementBits, processBits, and workerBits must add up to 22.' );
// ensure that ids conform to the number of bits
this.options.workerId = this.options.workerId % ( 2 ** this.options.workerBits );
this.options.processId = this.options.processId % ( 2 ** this.options.processBits );
// check if NaN
if ( isNaN( this.options.workerId ) ) this.options.workerId = 0;
if ( isNaN( this.options.processId ) ) this.options.processId = 0;
// store the maximum increment bound
this.maxIncrement = 2 ** this.options.incrementBits;
// calculate the shifted worker/process ids for later reference
this.workerId = big( this.options.workerId ).shiftLeft( this.options.incrementBits + this.options.processBits );
this.processId = big( this.options.processId ).shiftLeft( this.options.incrementBits );
// freeze options and this object, to prevent tampering
Object.freeze( this.options );
Object.freeze( this );
}
get increment() { return this.mutable.increment = this.mutable.increment.next().mod( this.maxIncrement ); }
generate() {
if ( this.options.async ) return this._generateAsync();
else return this._generate();
}
_generate( date, increment = null ) {
// 0000000000000000000000000000000000000000000000000000000000000000
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000
let flake = big( date || Date.now() ).minus( this.options.epoch ).shiftLeft( 22 )
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb00000000000000000
.add( this.workerId )
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbccccc000000000000
.add( this.processId )
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbcccccdddddddddddd
.add( increment || this.increment );
if ( this.options.stringify ) flake = flake.toString();
return flake;
}
_lock() {
if ( this.mutable.locked ) return new Promise( res => this.mutable.locks.push( res ) );
else this.mutable.locked = true;
}
_unlock() {
if ( this.mutable.locks.length > 0 ) this.mutable.locks.shift()();
else this.mutable.locked = false;
}
async _generateAsync() {
let lock = this._lock();
if( lock ) await lock;
let now = Date.now();
// check if increment should be reset
if ( this.mutable.lastTimestamp !== now ) {
// last timestamp didnt match, reset increment
this.mutable.increment = big.zero;
this.mutable.lastTimestamp = now;
} else {
// last timestamp matched, increase increment
this.mutable.increment = this.mutable.increment.next();
// check if increment exceeds max bounds
if ( this.mutable.increment.greaterOrEquals( this.maxIncrement ) ) {
// sleep for 2ms - 1ms has a risk of timestamp not incrementing for some reason?
await sleep( 2 );
// reset increment
this.mutable.increment = big.zero;
now = this.mutable.lastTimestamp = Date.now();
}
}
// generate a snowflake with the new increment
let flake = this._generate( now, this.mutable.increment );
this._unlock();
return flake;
}
deconstruct( snowflake ) {
// turn snowflake into a bigint
let flake = big( snowflake );
// shift right, and add epoch to obtain timestamp
let timestamp = flake.shiftRight( 22 ).add( this.options.epoch );
//obtain workerId
let wBitShift = this.options.incrementBits + this.options.processBits;
let workerId = flake.and( big( getBits( this.options.workerBits ) ).shiftLeft( wBitShift ) ).shiftRight( wBitShift );
// obtain processId
let processId = flake.and( big( getBits( this.options.processBits ) ).shiftLeft( this.options.incrementBits ) ).shiftRight( this.options.incrementBits );
// obtain increment
let increment = flake.and(getBits(this.options.incrementBits));
return { timestamp, workerId, processId, increment };
}
};

View File

@@ -1,53 +0,0 @@
const inquirer = require('inquirer');
const {
red: red, gray: gray,
cyan: cyan, green: green,
yellow: yellow, magenta: magenta,
rainbow: rainbow
} = require('./deps/colors');
const questions = [
{
name: 'snowflake',
message: `Snowflake (${gray('type "exit" to exit')}) ${magenta('>>')}`,
validate: input => !isNaN(input) || typeof input === 'string' && input.toLowerCase() === 'exit',
default: 107130754189766656
}
];
console.log([
`[#]--------[ ${rainbow('Discord snowflake lookup')} ]--------[#]`,
`[# Input a snowflake (userID) below to check #]`,
`[# the creation date of an account. To get a #]`,
`[# userID, go to Settings > Apperance > #]`,
`[# Developer mode; After that, right-click a #]`,
`[# user/message/server and press "Copy ID" #]`,
`[# ${red('! This tool only includes creation date !')} #]`,
`[# ${red('Because that\'s the only thing you can get')} #]`,
`[# ${gray('Created by Wessel Tip <discord@go2it.eu>')} #]`,
`[################################################]`
].join('\n'));
prompt(questions);
process.on('exit', (code) => {
console.log([
`${green('Thank you for using snowflakey!')}`,
`If you have any feedback, feel free to`,
`post it in ${cyan('https://discord.gg/SV7DAE9')}`
].join('\n'));
if (code !== 0) {
console.log([
`${red('!!')} An error occured while exiting ${red('!!')}`,
`Error code: ${red(code)}`
].join('\n'));
}
});
function prompt(question) {
inquirer.prompt(question).then((res) => {
if (typeof res.snowflake === 'string' && res.snowflake.toLowerCase() === 'exit') process.exit(0);
res.snowflake = new String(res.snowflake).trim();
console.log(`${cyan('>>')} Creation date of snowflake "${yellow(res.snowflake)}": ${green(new Date((res.snowflake / 4194304) + 1420070400000).toLocaleString())}`);
prompt(question);
});
};

BIN
media/refrence.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

@@ -1,23 +1,16 @@
{
"name": "snowflakey",
"displayName": "Snowflakey",
"main": "index.js",
"version": "0.0.1",
"description": "Discord snowflake lookup",
"engines": { "node": ">=8.0" },
"dependencies": { "inquirer": "^6.1.0" },
"devDependencies": { "eslint": "^5.3.0" },
"description": "❄️ Snowflake generation/lookup",
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
"main": "generator.js",
"license": "MIT",
"files": [ "generator.js", "LICENSE" ],
"bugs": { "url": "https://www.github.com/PassTheWessel/Snowflakey/issues" },
"homepage": "https://www.github.com/PassTheWessel/Snowflakey#readme",
"repository": {
"type": "git",
"url": "https://www.github.com/PassTheWessel/snowflakey.git"
"url": "https://www.github.com/PassTheWessel/Snowflakey"
},
"author": "Wessel Tip <discord@go2it.eu>",
"maintainers": [ "Wessel Tip <discord@go2it.eu>" ],
"publisher": "Wessel Tip <discord@go2it.eu>",
"license": "MIT",
"private": false,
"keywords": [ "snowflake", "discord" ],
"homepage": "https://passthewessel.github.io",
"scripts": { "start": "node index.js" },
"directories": { "deps": "deps/*" }
"keywords": [ "snowflake", "generator", "cli", "accounts", "lookup", "lightweight" ]
}

18
test.js Normal file
View File

@@ -0,0 +1,18 @@
// require & generate the instance
const Snowflake = require( './generator' );
const snowflake = new Snowflake.generator({
processBits: 0,
workerBits: 8,
incrementBits: 14,
workerId: process.env.CLUSTER_ID || 31
});
// exports for global use
exports.makeSnowflake = ( date ) => { return snowflake._generate( date ); };
exports.unmakeSnowflake = ( flake ) => { let decon = snowflake.deconstruct( flake ); return decon.timestamp.valueOf(); };
// example
const flake = this.makeSnowflake( Date.now() );
console.log( flake );
console.log( `Creation date: ${Snowflake.lookup( flake, 1420070400000 )}` );
console.log( this.unmakeSnowflake( flake ) );