From 30feb790b1d6e2c43c2e4581659511d69fc1ca07 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:09:13 -0500 Subject: [PATCH] remove asset --- src/handlers/event-utils.ts | 2 +- src/handlers/interaction.ts | 3 +-- src/index.ts | 37 +------------------------------------ 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index 129d456..813f6ed 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -222,7 +222,7 @@ export async function callInitPlugins(module: Module, deps: Dependencies, emit?: absPath: _module.meta.absPath, deps }); - if (!res) throw Error("Plugin did not return anything."); + if (!res) throw Error("Plugin did not return anything. " + inspect(plugin, false, Infinity, true)); if(res.isErr()) { if(emit) { emitter?.emit('module.register', diff --git a/src/handlers/interaction.ts b/src/handlers/interaction.ts index 0c95e1d..e09eeef 100644 --- a/src/handlers/interaction.ts +++ b/src/handlers/interaction.ts @@ -4,13 +4,12 @@ import { createInteractionHandler, executeModule, intoTask, sharedEventStream, f import { SernError } from '../core/structures/enums' import { isAutocomplete, isCommand, isMessageComponent, isModal, resultPayload } from '../core/functions' import { UnpackedDependencies } from '../types/utility'; -import { Emitter } from '../core/interfaces'; export default function interactionHandler(deps: UnpackedDependencies, defaultPrefix?: string) { //i wish javascript had clojure destructuring const { '@sern/client': client, '@sern/emitter': emitter } = deps - const interactionStream$ = sharedEventStream(client as unknown as Emitter, 'interactionCreate'); + const interactionStream$ = sharedEventStream(client, 'interactionCreate'); const handle = createInteractionHandler(interactionStream$, deps, defaultPrefix); const interactionHandler$ = merge(handle(isMessageComponent), diff --git a/src/index.ts b/src/index.ts index 54c042e..81af075 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,3 @@ -import fs from 'node:fs/promises' -import path from 'node:path' export * as Sern from './sern'; export type { @@ -51,45 +49,12 @@ export { export * from './core/presences' export * from './core/interfaces' import type { controller } from './core/create-plugins'; -import { AttachmentBuilder } from 'discord.js'; export type Controller = typeof controller export * from './core/create-plugins'; export { CommandType, PluginType, PayloadType, EventType } from './core/structures/enums'; export { Context } from './core/structures/context'; +export { Asset } from './core/structures/asset'; export * from './core/ioc'; -export type AssetEncoding = "attachment"|"base64"|"binary"|"utf8"|"json" -type PartialAssetEncoding = Exclude -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 encoding is utf8. - */ -export async function Asset(p: string, opts?: { name?: never, encoding: PartialAssetEncoding }): Promise; -export async function Asset(p: string, opts?: { name?: never, encoding: 'json' }): 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)) { - relativePath = path.relative(ASSETS_DIR, "assets" + p); - } else { - relativePath = p; - } - - const filePath = path.join(ASSETS_DIR, relativePath); - - if (encoding === 'attachment') { - const attachmentName = opts?.name || path.basename(filePath); - return new AttachmentBuilder(filePath, { name: attachmentName }); - } else if(encoding === 'json') { - return fs.readFile(filePath, 'utf8') - .then(JSON.parse) - } else { - return fs.readFile(filePath, encoding); - } -}