Skip to content

Commit

Permalink
feat(bot): dispatch commands to multiple controllers
Browse files Browse the repository at this point in the history
BREAKING CHANGE: bot will attempt to execute commands with each
controller in turn, rather than stopping after the first passing
check. This allows workflows to branch off and coexist with chat.
  • Loading branch information
ssube committed Oct 27, 2019
1 parent 00eac2b commit 848c547
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,22 @@ export class Bot extends BaseService<BotData> implements Service {
commandVerb: cmd.verb,
});

let handled = false;

for (const h of this.controllers) {
if (await h.check(cmd)) {
await h.handle(cmd);
return;
try {
if (await h.check(cmd)) {
await h.handle(cmd);
handled = true;
}
} catch (err) {
this.logger.error(err, 'controller leaked error checking or handling message');
}
}

this.logger.warn({ cmd }, 'unhandled command');
if (!handled) {
this.logger.warn({ cmd }, 'command was rejected by every controller (unhandled command)');
}
}

/**
Expand Down

0 comments on commit 848c547

Please sign in to comment.