-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
36 lines (30 loc) · 803 Bytes
/
utils.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
const crypto = require("crypto");
const { green } = require("./words.json");
const generateSnowflake = function () {
return (
BigInt(Date.now()) * BigInt(Math.pow(2, 16)) +
BigInt(crypto.randomInt(Math.pow(2, 16)))
).toString();
};
const generateToken = function () {
return crypto.randomUUID();
};
const generateHandle = function () {
return green[crypto.randomInt(green.length)];
};
const generateDiscriminator = function () {
return crypto.randomInt(1, Math.pow(10, process.env.DISCRIMINATOR_LENGTH));
};
const formatName = function (arg1, arg2 = undefined) {
if (arg2) {
return `${arg1}#${arg2}`;
}
return `${arg1.handle}#${arg1.discriminator}`;
}
module.exports = {
generateSnowflake,
generateToken,
generateHandle,
generateDiscriminator,
formatName,
};