From 2465e8da1d90fdb52f448f7b866cda2eb6782489 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:46:37 -0500 Subject: [PATCH] plugin calling --- src/commands/build.ts | 24 +++++++++++++++++++----- templates/cf.js | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/commands/build.ts b/src/commands/build.ts index d897559..6fc765b 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -165,14 +165,28 @@ export async function build(options: Record) { dropLabels: [buildConfig.mode === 'production' ? '__DEV__' : '__PROD__', ...buildConfig.dropLabels!], }); //may need to invest in magicast for this lol + if(commandsPaths.length === 0) { + throw Error("No modules found. Stopping building.") + } + const fst = commandsPaths.shift()! const importedModulesTemplate = template .replace("\"use modules\";", commandsImports.join("\n")) .replace("\"use handle\";", ` - if(interaction.data.name === "${p.parse(commandsPaths.shift()!).name}") { - return; - } - ${commandsPaths.map(imp => { - return `else if(interaction.data.name === "${p.parse(imp).name}" ) { }` + ${commandsPaths.map((imp, i) => { + if(i === 0) { + return `if(interaction.data.name === "${p.parse(fst).name}") { + const success = await applyPlugins(${p.parse(fst).name}); + if(success) { + await ${p.parse(fst).name}.execute(); + } + }` + } + return `else if(interaction.data.name === "${p.parse(imp).name}" ) { + const success = await applyPlugins(${p.parse(imp).name}); + if(success) { + await ${p.parse(imp).name}.execute(); + } + }` }).join("\n")} `); diff --git a/templates/cf.js b/templates/cf.js index 54afbed..f9283a8 100644 --- a/templates/cf.js +++ b/templates/cf.js @@ -29,13 +29,24 @@ async function executeModule( ) { try { await module.execute(args); - emitter.emit('module.activate', /*resultPayload(PayloadType.Success, module)*/); + //emitter.emit('module.activate', /*resultPayload(PayloadType.Success, module)*/); } catch(e) { - throw e /* { } */ + throw e } } +async function applyPlugins(module, payload) { + let success = true; + for (const plg of module.onEvent){ + const res = await plg.execute(payload); + if(!res.ok) { + success = false; + } + } + return success; +} + const router = Router(); /**