fix of intervals, change how memory.ts gets info
parent
24715e77d6
commit
8df5589242
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
/* eslint-disable no-await-in-loop */
|
||||
import { Client } from '..';
|
||||
import { RichEmbed } from '../class';
|
||||
import { TierInterface } from '../models';
|
||||
|
||||
const channelID = '691824484230889546';
|
||||
|
||||
|
@ -25,22 +26,9 @@ export default function memory(client: Client) {
|
|||
// memory in megabytes
|
||||
const memoryConversion = mem / 1024 / 1024;
|
||||
const userLimits: { soft?: number, hard?: number } = {};
|
||||
switch (acc.tier) {
|
||||
case 1:
|
||||
userLimits.soft = memoryLimits.TIER_1_SOFT;
|
||||
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;
|
||||
}
|
||||
const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec();
|
||||
userLimits.soft = tier.resourceLimits.ram;
|
||||
userLimits.hard = tier.resourceLimits.ram + 50;
|
||||
|
||||
/* if the user has exceeded their soft memory limit, which is the one described in the
|
||||
resource limit guidelines, we'll inform staff.
|
||||
|
|
Loading…
Reference in New Issue