forked from nates/ward
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpool.js
More file actions
47 lines (41 loc) · 1.17 KB
/
pool.js
File metadata and controls
47 lines (41 loc) · 1.17 KB
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
// Packages
const crypto = require('crypto');
const { Signale } = require('signale');
// Variables
const logger = new Signale({ scope: 'Pool' });
let linkPool = [];
// Functions
// Create a link ID for a user
function createLink(discordID) {
const linkID = crypto.randomBytes(4).toString('hex');
linkPool.push({
discordID: discordID,
linkID: linkID
});
setTimeout(function() {
if (isValidLink(linkID)) removeLink(linkID);
}, 900000);
logger.info('Created new link ID:', linkID);
return linkID;
}
// Checks if link ID exists
function isValidLink(linkID) {
for (let i = 0; i < linkPool.length; i++) if (linkPool[i].linkID == linkID) return true;
return false;
}
// Remove link
function removeLink(linkID) {
for (let i = 0; i < linkPool.length; i++) if (linkPool[i].linkID == linkID) delete linkPool[i];
linkPool = linkPool.filter(n => n);
}
// Get Discord ID from link ID
function getDiscordId(linkID) {
for (let i = 0; i < linkPool.length; i++) if (linkPool[i].linkID == linkID) return linkPool[i].discordID;
return false;
}
module.exports = {
isValidLink,
removeLink,
createLink,
getDiscordId
};