mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
remove asset
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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<Interaction>(client as unknown as Emitter, 'interactionCreate');
|
||||
const interactionStream$ = sharedEventStream<Interaction>(client, 'interactionCreate');
|
||||
const handle = createInteractionHandler(interactionStream$, deps, defaultPrefix);
|
||||
|
||||
const interactionHandler$ = merge(handle(isMessageComponent),
|
||||
|
||||
37
src/index.ts
37
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<AssetEncoding, 'attachment' | 'json' >
|
||||
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<string>;
|
||||
export async function Asset(p: string, opts?: { name?: never, encoding: 'json' }): Promise<any>;
|
||||
export async function Asset(p: string, opts?: { name?: string, encoding: 'attachment' }): Promise<AttachmentBuilder>;
|
||||
export async function Asset(p: string, opts?: { name?: string, encoding: AssetEncoding }): Promise<string|AttachmentBuilder> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user