migrate parsing to backend

This commit is contained in:
jane 2021-06-04 16:14:40 -04:00
parent 03bbf03279
commit be73eaa4cd
4 changed files with 192 additions and 194 deletions

View file

@ -1,5 +1,5 @@
import { CommandInitializer, Command } from '../parser.js';
import parse, { discover, initialize, instructions } from '../lights/light_parser.js';
//import parse, { discover, initialize, instructions } from '../lights/light_parser.js';
import req from '../lights/request.js';
const initializer = new CommandInitializer();
@ -7,7 +7,7 @@ const initializer = new CommandInitializer();
class LightsParser extends Command {
init(ctx, log) {
this.log = log;
initialize(ctx);
//initialize(ctx);
}
name = 'lights';
whitelist = true;
@ -20,21 +20,20 @@ class LightsParser extends Command {
msg.channel.createMessage('no args found.');
return;
}
let instructions = parse(args[0]);
// let instructions = parse(args[0]);
this.log.debug(instructions);
let res = '```\n';
instructions.forEach((instruction) => {
res += JSON.stringify(instruction) + '\n';
});
res += '```';
msg.channel.createMessage(`parsed instructions:\n${res}`);
// this.log.debug(instructions);
// let res = '```\n';
// instructions.forEach((instruction) => {
// res += JSON.stringify(instruction) + '\n';
// });
// res += '```';
// msg.channel.createMessage(`parsed instructions:\n${res}`);
req(
instructions.filter((i) => i.valid),
args.join(' '),
(response) => {
msg.channel.createMessage(`${response}`);
msg.channel.createMessage(`\`\`\`\n${response}\`\`\``);
},
discover,
(error) => {
msg.channel.createMessage(`error: ${error.message}`);
}