Command Context class declaration and index restructure

ctx
Matthew 2022-09-19 18:48:47 -04:00
parent ca6e20fa0b
commit af72a4d6d2
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 27 additions and 2 deletions

24
src/class/CmdContext.ts Normal file
View File

@ -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);
}
}

View File

@ -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<any> { return Promise.resolve(); }
public run(ctx: CmdContext): Promise<any> { return Promise.resolve(); }
constructor(client: Client) {
this.client = client;

View File

@ -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';