Skip to content

Commit

Permalink
Allow keyword selection of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Jun 13, 2018
1 parent d120d5b commit 95532de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/BotProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class BotProcess
constructor(bot: DaVinciBot, rootIdea: Idea) {
this.bot = bot;
this.rootIdea = rootIdea;
this.commands.push(new BotCommand('[Quit] this process.', [], (process: BotProcess) => { process.status = BotStatus.Idle; process.finish(); } ));
this.commands.push(new BotCommand('[Quit] this process.', [ 'q' ], (process: BotProcess) => { process.status = BotStatus.Idle; process.finish(); } ));
}

start(): void { }
Expand All @@ -36,13 +36,28 @@ export class BotProcess
let numInput = parseInt(input);
if (isNaN(numInput)) {
// TODO handle Q
// TODO loop through checking against keywords to call it
// loop through checking against keywords to call it

input = input.toLowerCase();
for (let i = 0; i < this.commands.length; ++i) {
let command = this.commands[i];
for (let j = 0; j < command.keywords.length; ++j) {
let keyword = command.keywords[j].toLowerCase();
if (keyword === input) {
command.event(this);
}
}
}

}
else {
// TODO 0 will call Quit, but it isn't indicated that this is the
// case. So maybe that's a bug
// TODO call the command corresponding with numInput
this.commands[numInput].event(this);
}
// TODO error checking
// TODO error checking -- what if the user inputs a typo, negative
// number, etc?
}

finish(): void { }
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ while (bot.status !== BotStatus.Idle) {
break;
}

console.log(bot.currentProcess);
console.log(bot.status);
// TODO make these easily enabled/disabled with a verbose arg
/*console.log(bot.currentProcess);*/
/*console.log(bot.status);*/
}

bot.startProcess(new SaveFileProcess(bot, rootIdea));
Expand Down

0 comments on commit 95532de

Please sign in to comment.