diff --git a/src/commands/addmerchant.ts b/src/commands/addmerchant.ts new file mode 100644 index 0000000..d41451f --- /dev/null +++ b/src/commands/addmerchant.ts @@ -0,0 +1,31 @@ +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.'; + this.usage = `${this.client.config.prefix}addmerchant `; + this.aliases = ['am']; + this.permissions = 6; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + const key = randomBytes(20).toString('hex'); + const merchant = await (new this.client.db.Merchant({ + name: args.join(' '), + key, + pulls: [], + })).save(); + return this.success(message.channel, `Created merchant (${merchant._id}). \`${args.join(' ')}\`\n\n\`${key}\``); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/delmerchant.ts b/src/commands/delmerchant.ts new file mode 100644 index 0000000..b3e4704 --- /dev/null +++ b/src/commands/delmerchant.ts @@ -0,0 +1,27 @@ +import { Message } from 'eris'; +import { randomBytes } from 'crypto'; +import { Client, Command } from '../class'; + +export default class DelMerchant extends Command { + constructor(client: Client) { + super(client); + this.name = 'delmerchant'; + this.description = 'Deletes a merchant.'; + this.usage = `${this.client.config.prefix}delmerchant `; + this.aliases = ['dm']; + this.permissions = 6; + this.guildOnly = true; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + const merchant = await this.client.db.Merchant.findOne({ _id: args[0] }); + if (!merchant) return this.error(message.channel, 'Merchant specified does not exist.'); + return this.success(message.channel, `Deleted merchant \`${merchant._id}\`.`); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index cc2ddba..21bf384 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,9 +1,11 @@ export { default as additem } from './additem'; +export { default as addmerchant } from './addmerchant'; export { default as addnote } from './addnote'; export { default as addrank } from './addrank'; export { default as addredirect } from './addredirect'; export { default as ban } from './ban'; export { default as delitem } from './delitem'; +export { default as delmerchant } from './delmerchant'; export { default as delnote } from './delnote'; export { default as delrank } from './delrank'; export { default as delredirect } from './delredirect';