From 3985b0c3aaa221bf2dca8e7fe70e6999a2641ef5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 3 May 2020 17:49:50 -0400 Subject: [PATCH] multiple changes to memory notification handling --- src/intervals/memory.ts | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index a7fa307..d80685a 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -33,7 +33,9 @@ export default function memory(client: Client) { const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec(); userLimits.soft = tier.resourceLimits.ram - 50; 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 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.setTimestamp(); await client.createMessage(channelID, { embed }); - const notifyEmbed = new RichEmbed() - .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.`) - .addField('Technician', 'SYSTEM', true) - .setFooter(client.user.username, client.user.avatarURL) - .setTimestamp(); - client.getDMChannel(acc.userID).then((channel) => { - channel.createMessage({ embed: notifyEmbed }); - }); - notifyEmbed.addField('User', `${acc.username} | <@${acc.userID}>`, true); - client.createMessage('580950455581147146', { embed }); - client.util.transport.sendMail({ - to: acc.emailAddress, - from: 'Library of Code sp-us | Cloud Services ', - subject: 'Notification', - html: ` + if (memoryConversion >= acc.ramLimitNotification) { + if (acc.ramLimitNotification === -1) return; + const notifyEmbed = new RichEmbed() + .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.\nYou can set your notification preferences by running \`=limits set-ram-notification \`, you can disable these notifications by running \`=limits set-ram-notification -1\`.`) + .addField('User', `${acc.username} | <@${acc.userID}>`, true) + .addField('Technician', 'SYSTEM', true) + .setFooter(client.user.username, client.user.avatarURL) + .setTimestamp(); + client.getDMChannel(acc.userID).then((channel) => { + channel.createMessage({ embed: notifyEmbed }); + }); + client.util.transport.sendMail({ + to: acc.emailAddress, + from: 'Library of Code sp-us | Cloud Services ', + subject: 'Notification', + html: `

Library of Code sp-us | Cloud Services

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.

Technician: SYSTEM

Library of Code sp-us | Support Team `, - }); + }); + } + client.createMessage('580950455581147146', { embed }); set.add(acc.username); } }