-
Notifications
You must be signed in to change notification settings - Fork 73
/
pool.js
39 lines (31 loc) · 1.11 KB
/
pool.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
// —— Requiring the packages that we need for this file.
const { Signale } = require('signale');
const createCode = require('./public/util.js').createCode;
const logger = new Signale({ scope: 'Pool' });
// —— Making the functions!!
let linkPool = [];
function createLink(discordID) {
const linkID = createCode(8);
linkPool.push({
discordID: discordID,
linkID: linkID
});
setTimeout(function() {
if (isValidLink(linkID)) removeLink(linkID);
}, 900000);
logger.info('Created new link ID:', linkID);
return linkID;
}
function isValidLink(linkID) {
for (let i = 0; i < linkPool.length; i++) if (linkPool[i].linkID == linkID) return true;
return false;
}
function removeLink(linkID) {
for (let i = 0; i < linkPool.length; i++) if (linkPool[i].linkID == linkID) delete linkPool[i];
linkPool = linkPool.filter(n => n);
}
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 };