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,29 +79,32 @@ 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 });
const notifyEmbed = new RichEmbed() if (memoryConversion >= acc.ramLimitNotification) {
.setTitle('Cloud Account | Notification') if (acc.ramLimitNotification === -1) return;
.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.`) const notifyEmbed = new RichEmbed()
.addField('Technician', 'SYSTEM', true) .setTitle('Cloud Account | Notification')
.setFooter(client.user.username, client.user.avatarURL) .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\`.`)
.setTimestamp(); .addField('User', `${acc.username} | <@${acc.userID}>`, true)
client.getDMChannel(acc.userID).then((channel) => { .addField('Technician', 'SYSTEM', true)
channel.createMessage({ embed: notifyEmbed }); .setFooter(client.user.username, client.user.avatarURL)
}); .setTimestamp();
notifyEmbed.addField('User', `${acc.username} | <@${acc.userID}>`, true); client.getDMChannel(acc.userID).then((channel) => {
client.createMessage('580950455581147146', { embed }); channel.createMessage({ embed: notifyEmbed });
client.util.transport.sendMail({ });
to: acc.emailAddress, client.util.transport.sendMail({
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>', to: acc.emailAddress,
subject: 'Notification', from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
html: ` subject: 'Notification',
html: `
<h1>Library of Code sp-us | Cloud Services</h1> <h1>Library of Code sp-us | Cloud Services</h1>
<p>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.</p> <p>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.</p>
<p><strong>Technician:</strong> SYSTEM</p> <p><strong>Technician:</strong> SYSTEM</p>
<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);
} }
} }