diff --git a/src/commands/limits.ts b/src/commands/limits.ts index 78bd292..1db6bf4 100644 --- a/src/commands/limits.ts +++ b/src/commands/limits.ts @@ -1,15 +1,16 @@ import { Message } from 'eris'; import { Command, RichEmbed } from '../class'; import { dataConversion } from '../functions'; +import setRamNotification from './limits_setramnotification'; import { Client } from '..'; -export default class SetLimit extends Command { +export default class Limits extends Command { constructor(client: Client) { super(client); this.name = 'limits'; this.description = 'Views resource limits for each tier.'; this.usage = `${this.client.config.prefix}limits`; - this.subcmds = []; + this.subcmds = [setRamNotification]; this.enabled = true; } @@ -18,6 +19,17 @@ export default class SetLimit extends Command { const tiers = await this.client.db.Tier.find(); const embed = new RichEmbed(); embed.setTitle('Resource Limit Information'); + const account = await this.client.db.Account.findOne({ userID: message.author.id }); + if (account) { + const tier = await this.client.db.Tier.findOne({ id: account.tier }); + let msg: string; + if (account.ramLimitNotification !== -1) { + msg = `You will be notified when you are using ${account.ramLimitNotification} MB+.`; + } else { + msg = 'You will not be notified about impending resource limits for your account.'; + } + embed.setDescription(`Your resource limit is ${dataConversion(tier.resourceLimits?.ram * 1024 * 1024) ?? '0 B'}.\n${msg}`); + } embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setTimestamp(); for (const tier of tiers.sort((a, b) => a.id - b.id)) { diff --git a/src/commands/limits_setramnotification.ts b/src/commands/limits_setramnotification.ts new file mode 100644 index 0000000..11ecf9c --- /dev/null +++ b/src/commands/limits_setramnotification.ts @@ -0,0 +1,31 @@ +import { Message } from 'eris'; +import { Command, RichEmbed } from '../class'; +import { Client } from '..'; + +export default class Limits_SetRAMNotification extends Command { + constructor(client: Client) { + super(client); + this.name = 'set-ram-notification'; + this.description = 'Sets your personal perference for receiving RAM resource limit notifications. Set the limit to "-1" to disable notifications.'; + this.usage = `${this.client.config.prefix}limits set-ram-notification `; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + const account = await this.client.db.Account.findOne({ userID: message.author.id }); + if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You do not have a Cloud Account.***`); + const tier = await this.client.db.Tier.findOne({ id: account.tier }); + if (Number(args[0]) >= tier.resourceLimits.ram) return message.channel.createMessage(`***${this.client.stores.emojis.error} You cannot set your notification limit to be set to or above your hard limit.***`); + if ((Number(args[0]) < 1) && (Number(args[0]) !== -1)) return message.channel.createMessage(`***${this.client.stores.emojis.error} You cannot set your notification limit to a negative number.***`); + if (Number(args[0]) === -1) { + await account.updateOne({ $set: { ramLimitNotification: -1 } }); + return message.channel.createMessage(`***${this.client.stores.emojis.success} You have disabled notifications.***`); + } + await account.updateOne({ $set: { ramLimitNotification: Number(args[0]) } }); + return message.channel.createMessage(`***${this.client.stores.emojis.success} You will now receive notifications when you go above ${Number(args[0])} MB.***`); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +}