Skip to content

Commit

Permalink
Refactor usage on Node side
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert committed Dec 19, 2023
1 parent 517c0da commit d52b63d
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/server/managers/AppSlashCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AppMethod } from '../../definition/metadata';
import type { ISlashCommand, ISlashCommandPreview, ISlashCommandPreviewItem, SlashCommandContext } from '../../definition/slashcommands';
import type { ProxiedApp } from '../ProxiedApp';
import { AppConsole } from '../logging';
import type { AppLogStorage } from '../storage';
import type { AppAccessorManager } from './AppAccessorManager';

Expand Down Expand Up @@ -66,35 +65,16 @@ export class AppSlashCommand {
): Promise<void | ISlashCommandPreview> {
const { command } = this.slashCommand;

// Ensure the slash command has the property before going on
if (typeof this.slashCommand[method] !== 'function') {
return;
}

const logger = this.app.setupLogger(method);
logger.debug(`${command}'s ${method} is being executed...`, context);

try {
const runCode = `module.exports = slashCommand.${method}.apply(slashCommand, args)`;
const result = await this.app.getRuntime().runInSandbox(runCode, {
slashCommand: this.slashCommand,
args: [
...runContextArgs,
context,
accessors.getReader(this.app.getID()),
accessors.getModifier(this.app.getID()),
accessors.getHttp(this.app.getID()),
accessors.getPersistence(this.app.getID()),
],
const result = await this.app.getDenoRuntime().sendRequest({
method: `slashcommand:${command}:${method}`,
params: [...runContextArgs, context],
});

logger.debug(`${command}'s ${method} was successfully executed.`);
return result;
return result as void | ISlashCommandPreview;
} catch (e) {
logger.error(e);
logger.debug(`${command}'s ${method} was unsuccessful.`);
} finally {
await logStorage.storeEntries(AppConsole.toStorageEntry(this.app.getID(), logger));
// @TODO this needs to be revisited
console.error(e);
}
}
}

0 comments on commit d52b63d

Please sign in to comment.