multiple changes to memory notification handling

merge-requests/4/head
Matthew 2020-05-03 17:49:50 -04:00
parent 7897ff2165
commit 3985b0c3aa
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 23 additions and 18 deletions

View File

@ -33,7 +33,9 @@ export default function memory(client: Client) {
const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec(); const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec();
userLimits.soft = tier.resourceLimits.ram - 50; userLimits.soft = tier.resourceLimits.ram - 50;
userLimits.hard = tier.resourceLimits.ram + 10; userLimits.hard = tier.resourceLimits.ram + 10;
if (memoryConversion <= userLimits.soft) {
set.delete(acc.username);
}
/* 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.
*/ */
@ -77,17 +79,18 @@ export default function memory(client: Client) {
embed.setFooter(client.user.username, client.user.avatarURL); embed.setFooter(client.user.username, client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
await client.createMessage(channelID, { embed }); await client.createMessage(channelID, { embed });
if (memoryConversion >= acc.ramLimitNotification) {
if (acc.ramLimitNotification === -1) return;
const notifyEmbed = new RichEmbed() const notifyEmbed = new RichEmbed()
.setTitle('Cloud Account | Notification') .setTitle('Cloud Account | Notification')
.setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard)} MB'. Please correct your usage to avoid further action.`) .setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard)} MB'. Please correct your usage to avoid further action.\nYou can set your notification preferences by running \`=limits set-ram-notification <preferred ram threshold in MB>\`, you can disable these notifications by running \`=limits set-ram-notification -1\`.`)
.addField('User', `${acc.username} | <@${acc.userID}>`, true)
.addField('Technician', 'SYSTEM', true) .addField('Technician', 'SYSTEM', true)
.setFooter(client.user.username, client.user.avatarURL) .setFooter(client.user.username, client.user.avatarURL)
.setTimestamp(); .setTimestamp();
client.getDMChannel(acc.userID).then((channel) => { client.getDMChannel(acc.userID).then((channel) => {
channel.createMessage({ embed: notifyEmbed }); channel.createMessage({ embed: notifyEmbed });
}); });
notifyEmbed.addField('User', `${acc.username} | <@${acc.userID}>`, true);
client.createMessage('580950455581147146', { embed });
client.util.transport.sendMail({ client.util.transport.sendMail({
to: acc.emailAddress, to: acc.emailAddress,
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>', from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
@ -100,6 +103,8 @@ export default function memory(client: Client) {
<b><i>Library of Code sp-us | Support Team</i></b> <b><i>Library of Code sp-us | Support Team</i></b>
`, `,
}); });
}
client.createMessage('580950455581147146', { embed });
set.add(acc.username); set.add(acc.username);
} }
} }