commands for viewing limit and changing limit threshold
parent
c3f6867f4b
commit
0182b0af14
|
@ -1,15 +1,16 @@
|
||||||
import { Message } from 'eris';
|
import { Message } from 'eris';
|
||||||
import { Command, RichEmbed } from '../class';
|
import { Command, RichEmbed } from '../class';
|
||||||
import { dataConversion } from '../functions';
|
import { dataConversion } from '../functions';
|
||||||
|
import setRamNotification from './limits_setramnotification';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
|
|
||||||
export default class SetLimit extends Command {
|
export default class Limits extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'limits';
|
this.name = 'limits';
|
||||||
this.description = 'Views resource limits for each tier.';
|
this.description = 'Views resource limits for each tier.';
|
||||||
this.usage = `${this.client.config.prefix}limits`;
|
this.usage = `${this.client.config.prefix}limits`;
|
||||||
this.subcmds = [];
|
this.subcmds = [setRamNotification];
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +19,17 @@ export default class SetLimit extends Command {
|
||||||
const tiers = await this.client.db.Tier.find();
|
const tiers = await this.client.db.Tier.find();
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Resource Limit Information');
|
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.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
for (const tier of tiers.sort((a, b) => a.id - b.id)) {
|
for (const tier of tiers.sort((a, b) => a.id - b.id)) {
|
||||||
|
|
|
@ -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 <limit in mb>`;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue