diff --git a/src/class/CmdContext.ts b/src/class/CmdContext.ts new file mode 100644 index 0000000..a4efb76 --- /dev/null +++ b/src/class/CmdContext.ts @@ -0,0 +1,24 @@ +import { Message, MessageContent, FileContent } from 'eris'; +import { Client } from '.'; + +export default class CmdContext { + public client: Client; + + public message: Message; + + public args?: string[]; + + constructor(message: Message, args?: string[]) { + this.message = message; + this.args = args; + } + + public async uniCreateMessage(content: MessageContent, file?: FileContent | FileContent[]) { + if ([2, 3].includes(this.message.channel.type)) { + const channel = await this.client.getDMChannel(this.message.author.id); + if (!channel) throw new Error(`Unable to fetch DM channel for '${this.message.author.id}'.`); + return channel.createMessage(content, file); + } + return this.message.channel.createMessage(content, file); + } +} diff --git a/src/class/Command.ts b/src/class/Command.ts index ba68fbe..a917b81 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -1,5 +1,5 @@ import { Member, Message, TextableChannel } from 'eris'; -import { Client, Collection } from '.'; +import { Client, CmdContext, Collection } from '.'; export default class Command { public client: Client; @@ -52,7 +52,7 @@ export default class Command { public enabled: boolean; - public run(message: Message, args: string[]): Promise { return Promise.resolve(); } + public run(ctx: CmdContext): Promise { return Promise.resolve(); } constructor(client: Client) { this.client = client; diff --git a/src/class/index.ts b/src/class/index.ts index 80a3830..2eb9c23 100644 --- a/src/class/index.ts +++ b/src/class/index.ts @@ -1,4 +1,5 @@ export { default as Client } from './Client'; +export { default as CmdContext } from './CmdContext'; export { default as Collection } from './Collection'; export { default as Command } from './Command'; export { default as Event } from './Event';