44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
import { Message } from 'eris';
|
|
import { Command, RichEmbed } from '../class';
|
|
import { dataConversion } from '../functions';
|
|
import setRamNotification from './limits_setramnotification';
|
|
import { Client } from '..';
|
|
|
|
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 = [setRamNotification];
|
|
this.enabled = true;
|
|
}
|
|
|
|
public async run(message: Message) {
|
|
try {
|
|
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)) {
|
|
embed.addField(`Tier ${tier.id}`, `**RAM:** ${dataConversion(tier.resourceLimits?.ram * 1024 * 1024) ?? '0 B'}\n**Storage:** ${dataConversion(tier.resourceLimits?.storage * 1024 * 1024) ?? '0 B'}`);
|
|
}
|
|
return message.channel.createMessage({ embed });
|
|
} catch (error) {
|
|
return this.client.util.handleError(error, message, this);
|
|
}
|
|
}
|
|
}
|