commands to set resource limits

merge-requests/4/head
Matthew 2020-05-02 02:34:52 -04:00
parent 637c01ae49
commit 84cf60069f
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
2 changed files with 50 additions and 0 deletions

23
src/commands/setlimit.ts Normal file
View File

@ -0,0 +1,23 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
export default class SetLimit extends Command {
constructor(client: Client) {
super(client);
this.name = 'setlimit';
this.description = 'Sets resource limits for the various tiers';
this.usage = `Run ${this.client.config.prefix}${this.name} [subcommand] for usage information`;
this.permissions = { roles: ['662163685439045632'] };
this.subcmds = [];
this.enabled = true;
}
public async run(message: Message) {
try {
return this.client.commands.get('help').run(message, [this.name]);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

@ -0,0 +1,27 @@
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
export default class SetLimit_RAM extends Command {
constructor(client: Client) {
super(client);
this.name = 'ram';
this.description = 'Sets tier limits for RAM.';
this.usage = `${this.client.config.prefix}setlimit ram <tier> <limit in MB>`;
this.permissions = { roles: ['662163685439045632'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, ['setlimit', this.name]);
const tier = await this.client.db.Tier.findOne({ id: Number(args[0]) });
if (!tier) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate that tier.***`);
if (Number.isNaN(Number(args[1]))) return message.channel.createMessage(`***${this.client.stores.emojis.error} This is not a valid number.***`);
await tier.updateOne({ 'resourceLimits.ram': Number(args[1]) });
return message.channel.createMessage(`***${this.client.stores.emojis.success} Tier ${tier.id} RAM resource limit set to ${args[1]} MB.***`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}