diff --git a/src/core/structures/context.ts b/src/core/structures/context.ts index 2313f6b1..59dcbb0c 100644 --- a/src/core/structures/context.ts +++ b/src/core/structures/context.ts @@ -14,7 +14,6 @@ import * as assert from 'assert'; import type { ReplyOptions } from '../../types/utility'; import { fmt } from '../functions' -type ShitType = ChatInputCommandInteraction['options'] /** * @since 1.0.0 @@ -22,21 +21,13 @@ type ShitType = ChatInputCommandInteraction['options'] * Message and ChatInputCommandInteraction */ export class Context extends CoreContext { + get options() { - return this.interaction.options; - } - args(type: 'message') : string[] - args(type: 'interaction') : ShitType - //TODO - args(type: 'message'|'interaction') { - switch(type) { - case 'message': { - const [, ...rest] = fmt(this.message.content, this.prefix); - return rest; - }; - case 'interaction': { - return this.interaction.options; - }; + if(this.isMessage()) { + const [, ...rest] = fmt(this.message.content, this.prefix); + return rest; + } else { + return this.interaction.options; } } diff --git a/src/index.ts b/src/index.ts index 9ee4c0b1..a9a9f1f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,11 +60,18 @@ export * from './core/ioc'; export type AssetEncoding = "attachment"|"base64"|"binary"|"utf8" const ASSETS_DIR = path.resolve('assets'); + + + /** * Reads an asset file from the 'assets' directory. + * If encoding is 'attachment', a discord.js AttachmentBuilder is provided, else + * fs.promises.readFile is called. The default is utf8. */ -export async function Asset(p: string, opts: { name?: string, encoding?: AssetEncoding }) { - const encoding = opts.encoding || 'utf8'; +export async function Asset(p: string, opts?: { name?: string, encoding: Exclude }): Promise; +export async function Asset(p: string, opts?: { name?: string, encoding: 'attachment' }): Promise; +export async function Asset(p: string, opts?: { name?: string, encoding: AssetEncoding }): Promise { + const encoding = opts?.encoding || 'utf8'; let relativePath: string; if (path.isAbsolute(p)) { @@ -76,11 +83,9 @@ export async function Asset(p: string, opts: { name?: string, encoding?: AssetEn const filePath = path.join(ASSETS_DIR, relativePath); if (encoding === 'attachment') { - const attachmentName = opts.name || path.basename(filePath); + const attachmentName = opts?.name || path.basename(filePath); return new AttachmentBuilder(filePath, { name: attachmentName }); } else { return fs.readFile(filePath, encoding); } } - -