mirror of
https://github.com/sern-handler/cli
synced 2026-06-06 01:16:53 +00:00
plugin calling
This commit is contained in:
@@ -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")}
|
||||
`);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user