community-relations/src/commands/addmerchant.ts

34 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-09-29 02:43:59 -04:00
import { Message } from 'eris';
import { randomBytes } from 'crypto';
import { Client, Command } from '../class';
export default class AddMerchant extends Command {
constructor(client: Client) {
super(client);
this.name = 'addmerchant';
this.description = 'Creates a new merchant.';
2020-10-13 22:19:47 -04:00
this.usage = `${this.client.config.prefix}addmerchant <privileged: 1 for yes | 0 for no> <type: 0 for only soft | 1 for soft and hard> <merchant name>`;
2020-09-29 02:43:59 -04:00
this.aliases = ['am'];
this.permissions = 6;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
2020-10-13 22:19:47 -04:00
if (!args[1]) return this.client.commands.get('help').run(message, [this.name]);
if ((Number(args[0]) !== 0) && (Number(args[0]) !== 1)) return this.error(message.channel, 'Invalid permissions.');
2020-09-29 02:43:59 -04:00
const key = randomBytes(20).toString('hex');
const merchant = await (new this.client.db.Merchant({
2020-10-13 22:19:47 -04:00
name: args.slice(2).join(' '),
privileged: Number(args[0]),
2020-09-29 02:43:59 -04:00
key,
pulls: [],
})).save();
2020-10-13 22:19:47 -04:00
return this.success(message.channel, `Created merchant (${merchant._id}). \`${args.slice(2).join(' ')}\`\n\n\`${key}\``);
2020-09-29 02:43:59 -04:00
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}