fix of intervals, change how memory.ts gets info

merge-requests/4/head
Matthew 2020-05-02 02:35:17 -04:00
parent 24715e77d6
commit 8df5589242
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
3 changed files with 84 additions and 16 deletions

View File

@ -0,0 +1,31 @@
import { Client } from '..';
let interval: NodeJS.Timeout;
export default function checkLock(client: Client) {
interval = setInterval(async () => {
try {
const moderations = await client.db.Moderation.find();
moderations.forEach(async (moderation) => {
if (!moderation.expiration) return;
if (moderation.expiration.processed) return;
if (new Date() > moderation.expiration.date) {
const account = await client.db.Account.findOne({ username: moderation.username });
if (!account) return;
await client.util.exec(`unlock ${account.username}`);
await moderation.updateOne({ 'expiration.processed': true });
await account.updateOne({ locked: false });
await client.util.createModerationLog(account.userID, client.user, 3, 'Auto');
client.signale.complete(`Unlocked account ${account.username} | Queue date at ${moderation.expiration.date.toLocaleString('en-us')}`);
}
});
} catch (error) {
await client.util.handleError(error);
}
}, 10000);
return interval;
}
export function clear() {
clearInterval(interval);
}

49
src/intervals/checkSS.ts Normal file
View File

@ -0,0 +1,49 @@
/* eslint-disable consistent-return */
/* eslint-disable no-unreachable */
/* eslint-disable no-await-in-loop */
import axios from 'axios';
import { inspect } from 'util';
import { Client } from '..';
let interval: NodeJS.Timeout;
export default function checkSS(client: Client) {
return;
interval = setInterval(async () => {
try {
const accounts = await client.db.Account.find();
for (const { userID, homepath, hash } of accounts) {
try {
const Authorization = client.util.getAcctHash(homepath);
if (hash === null) throw new Error('Unable to locate auth file, homepath is probably incorrect');
await axios({
method: 'get',
url: 'https://api.securesign.org/account/details',
headers: { Authorization },
});
if (!hash) {
await client.db.Account.updateOne({ userID }, { $set: { hash: true } });
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign account has been automatically initialized via the SecureSign CLI.')).catch();
}
} catch (error) {
if (!hash) return;
try {
const { status } = error.response;
if (status === 400 || status === 401 || status === 403 || status === 404) {
await client.db.Account.updateOne({ userID }, { $set: { hash: false } });
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account. Run `=securesign init` for more information')).catch();
}
} catch (e) {
throw error;
}
}
}
} catch (error) {
client.util.handleError(error);
}
}, 60000);
return interval;
}
export function clear() {
clearTimeout(interval);
}

View File

@ -2,6 +2,7 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import { Client } from '..'; import { Client } from '..';
import { RichEmbed } from '../class'; import { RichEmbed } from '../class';
import { TierInterface } from '../models';
const channelID = '691824484230889546'; const channelID = '691824484230889546';
@ -25,22 +26,9 @@ export default function memory(client: Client) {
// memory in megabytes // memory in megabytes
const memoryConversion = mem / 1024 / 1024; const memoryConversion = mem / 1024 / 1024;
const userLimits: { soft?: number, hard?: number } = {}; const userLimits: { soft?: number, hard?: number } = {};
switch (acc.tier) { const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec();
case 1: userLimits.soft = tier.resourceLimits.ram;
userLimits.soft = memoryLimits.TIER_1_SOFT; userLimits.hard = tier.resourceLimits.ram + 50;
userLimits.hard = memoryLimits.TIER_1_HARD;
break;
case 2:
userLimits.soft = memoryLimits.TIER_2_SOFT;
userLimits.hard = memoryLimits.TIER_2_HARD;
break;
case 3:
userLimits.soft = memoryLimits.TIER_3_SOFT;
userLimits.hard = memoryLimits.TIER_3_HARD;
break;
default:
break;
}
/* if the user has exceeded their soft memory limit, which is the one described in the /* if the user has exceeded their soft memory limit, which is the one described in the
resource limit guidelines, we'll inform staff. resource limit guidelines, we'll inform staff.