plugin calling

This commit is contained in:
Jacob Nguyen
2024-03-28 23:46:37 -05:00
parent fcca124c20
commit 2465e8da1d
2 changed files with 32 additions and 7 deletions

View File

@@ -165,14 +165,28 @@ export async function build(options: Record<string, any>) {
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")}
`);

View File

@@ -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();
/**