From e411f81ab9136988c4845b39b78839e1ba75db20 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 7 May 2023 00:46:22 -0500 Subject: [PATCH] chore: move and clean --- src/core/create-plugins.ts | 62 ++++++++++++++++++++++++++++++++++++++ src/core/index.ts | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/core/create-plugins.ts diff --git a/src/core/create-plugins.ts b/src/core/create-plugins.ts new file mode 100644 index 0000000..fa1bda9 --- /dev/null +++ b/src/core/create-plugins.ts @@ -0,0 +1,62 @@ +import { CommandType, EventType, PluginType } from '../structures'; +import type { Plugin, PluginResult, EventArgs, CommandArgs } from '../../types/plugin'; +import type { ClientEvents } from 'discord.js'; + +export function makePlugin( + type: PluginType, + execute: (...args: any[]) => any, +): Plugin { + return { + type, + execute, + } as Plugin; +} +/** + * @since 2.5.0 + * @__PURE__ + */ +export function EventInitPlugin( + execute: (...args: EventArgs) => PluginResult, +) { + return makePlugin(PluginType.Init, execute); +} +/** + * @since 2.5.0 + * @__PURE__ + */ +export function CommandInitPlugin( + execute: (...args: CommandArgs) => PluginResult, +) { + return makePlugin(PluginType.Init, execute); +} +/** + * @since 2.5.0 + * @__PURE__ + */ +export function CommandControlPlugin( + execute: (...args: CommandArgs) => PluginResult, +) { + return makePlugin(PluginType.Control, execute); +} +/** + * @since 2.5.0 + * @__PURE__ + */ +export function EventControlPlugin( + execute: (...args: EventArgs) => PluginResult, +) { + return makePlugin(PluginType.Control, execute); +} + +/** + * @since 2.5.0 + * @Experimental + * A specialized function for creating control plugins with discord.js ClientEvents. + * Will probably be moved one day! + */ +export function DiscordEventControlPlugin( + name: T, + execute: (...args: ClientEvents[T]) => PluginResult, +) { + return makePlugin(PluginType.Control, execute); +} diff --git a/src/core/index.ts b/src/core/index.ts index 5498a26..9494c0f 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,4 +1,4 @@ export * from './contracts'; -export * from './plugins'; +export * from './create-plugins'; export * from './structures'; export { single, transient, useContainerRaw, makeDependencies } from './dependencies';