-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
65 lines (58 loc) · 1.97 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { Plugin } = require('powercord/entities');
const DISCORD_EPOCH = Number(1420070400000);
module.exports = class SnowflakeInfo extends Plugin {
startPlugin () {
const idToBinary = async(num) => {
let bin = '';
let high = parseInt(num.slice(0, -10)) || 0;
let low = parseInt(num.slice(-10));
while (low > 0 || high > 0) {
bin = String(low & 1) + bin;
low = Math.floor(low / 2);
if (high > 0) {
low += 5000000000 * (high % 2);
high = Math.floor(high / 2);
}
}
return bin;
}
powercord.api.commands.registerCommand({
command: 'snowflake',
aliases: [],
description: 'Lets you see the creation date of a snowflake.',
usage: '{c} <snowflake>',
executor: async (args) => {
if(args.length < 1) {
return {
send: false,
result: 'Please provide a snowflake to check'
};
}
if(!/\d{1,20}/.test(args[0])) return {
send: false,
result: 'The provided argument is not a snowflake'
};
const BINARY = (await idToBinary(args[0])).toString(2).padStart(64, '0');
const res = {
timestamp: parseInt(BINARY.substring(0, 42), 2) + DISCORD_EPOCH,
workerID: parseInt(BINARY.substring(42, 47), 2),
processID: parseInt(BINARY.substring(47, 52), 2),
increment: parseInt(BINARY.substring(52, 64), 2),
binary: BINARY,
};
return {
send: false,
result: `Snowflake info for \`${args[0]}\`\n\n`
+ `**Timestamp**: ${new Date(res.timestamp).toUTCString()} (${res.timestamp})\n`
+ `**Worker ID**: ${res.workerID}\n`
+ `**Process ID**: ${res.processID}\n`
+ `**Increment**: ${res.increment}\n`
+ `**Binary**: ${res.binary}\n`
};
}
})
}
pluginWillUnload () {
powercord.api.commands.unregisterCommand('snowflake')
}
}