diff --git a/src/commands/securesign_account.ts b/src/commands/securesign_account.ts index 26ea3f5..0ec1efc 100644 --- a/src/commands/securesign_account.ts +++ b/src/commands/securesign_account.ts @@ -16,10 +16,10 @@ export default class SecureSign_Account extends Command { public async run(message: Message, args: string[]) { try { const user = await this.client.db.Account.findOne({ userID: message.author.id }); - if (!user || (!user.permissions.associate && !(message.channel instanceof PrivateChannel))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Run this command in your DMs!***`); + if (!user || (!user.permissions.staff && !(message.channel instanceof PrivateChannel))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Run this command in your DMs!***`); let account: AccountInterface; - if (!args[0] || !user.permissions.associate) account = user; + if (!args[0] || !user.permissions.staff) account = user; else account = await this.client.db.Account.findOne({ $or: [{ userID: args[0] }, { username: args[0] }, { emailAddress: args[0] }] }); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 1f96d20..87c5d60 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -13,61 +13,63 @@ export const memoryLimits = { TIER_3_HARD: 550, }; -export default async function memory(client: Client) { - const accounts = await client.db.Account.find(); - for (const acc of accounts) { - if (acc.root) return; - // memory in bytes - const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; - // memory in megabytes - const memoryConversion = mem / 1024 / 1024; - let userLimits: { soft: number, hard: number }; - if (acc.tier === 1) { - userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; - } else if (acc.tier === 2) { - userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD }; - } else if (acc.tier === 3) { - userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD }; - } - - /* if the user has exceeded their soft memory limit, which is the one described in the - resource limit guidelines, we'll inform staff. - */ - if (acc.tier === 1 && memoryConversion >= userLimits.soft) { - const embed = new RichEmbed(); - if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL); - embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true); - embed.addField('Tier', String(acc.tier), true); - embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true); - embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true); - embed.setFooter(client.user.username, client.user.avatarURL); - embed.setTimestamp(); - - // if they exceed the hard limit, we'll kill all of their processes. - if (memoryConversion >= userLimits.hard) { - client.util.exec(`killall -9 -u ${acc.username}`); - embed.setTitle('Resource Enforcement Notification'); - embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.'); - client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.'); - client.util.transport.sendMail({ - to: acc.emailAddress, - from: 'Library of Code sp-us | Cloud Services ', - subject: 'Your account has been warned', - html: ` -

Library of Code sp-us | Cloud Services

-

Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid possible moderative action.

-

Reason: [AUTO] Exceeded resource limit for RAM.

-

Moderator: ${client.user.username}

- - Library of Code sp-us | Support Team - `, - }); - } else { - embed.setTitle('Resource Limit Notification'); - embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.'); +export default function memory(client: Client) { + setInterval(async () => { + const accounts = await client.db.Account.find(); + for (const acc of accounts) { + if (acc.root) return; + // memory in bytes + const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; + // memory in megabytes + const memoryConversion = mem / 1024 / 1024; + let userLimits: { soft: number, hard: number }; + if (acc.tier === 1) { + userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; + } else if (acc.tier === 2) { + userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD }; + } else if (acc.tier === 3) { + userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD }; + } + + /* if the user has exceeded their soft memory limit, which is the one described in the + resource limit guidelines, we'll inform staff. + */ + if (acc.tier === 1 && memoryConversion >= userLimits.soft) { + const embed = new RichEmbed(); + if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL); + embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true); + embed.addField('Tier', String(acc.tier), true); + embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true); + embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true); + embed.setFooter(client.user.username, client.user.avatarURL); + embed.setTimestamp(); + + // if they exceed the hard limit, we'll kill all of their processes. + if (memoryConversion >= userLimits.hard) { + client.util.exec(`killall -9 -u ${acc.username}`); + embed.setTitle('Resource Enforcement Notification'); + embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.'); + client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.'); + client.util.transport.sendMail({ + to: acc.emailAddress, + from: 'Library of Code sp-us | Cloud Services ', + subject: 'Your account has been warned', + html: ` +

Library of Code sp-us | Cloud Services

+

Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid possible moderative action.

+

Reason: [AUTO] Exceeded resource limit for RAM.

+

Moderator: ${client.user.username}

+ + Library of Code sp-us | Support Team + `, + }); + } else { + embed.setTitle('Resource Limit Notification'); + embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.'); + } + // @ts-ignore + client.createMessage(channelID, { embed }); } - // @ts-ignore - client.createMessage(channelID, { embed }); } - } + }, 300000); } diff --git a/src/models/Account.ts b/src/models/Account.ts index ab38d31..3f10dc2 100644 --- a/src/models/Account.ts +++ b/src/models/Account.ts @@ -10,7 +10,7 @@ export interface AccountInterface extends Document { locked: boolean, tier: number; permissions: { - associate: boolean, + staff: boolean, sheriff: boolean, facultyMarshal: boolean, }, @@ -30,7 +30,7 @@ const Account: Schema = new Schema({ locked: Boolean, tier: Number, permissions: { - associate: Boolean, + staff: Boolean, sheriff: Boolean, facultyMarshal: Boolean, },