2020-11-08 03:29:13 +00:00
|
|
|
import { CommandInitializer, Command } from '../parser.js';
|
2021-06-04 20:14:40 +00:00
|
|
|
//import parse, { discover, initialize, instructions } from '../lights/light_parser.js';
|
2020-11-08 03:29:13 +00:00
|
|
|
import req from '../lights/request.js';
|
2020-11-07 23:12:27 +00:00
|
|
|
|
|
|
|
const initializer = new CommandInitializer();
|
|
|
|
|
|
|
|
class LightsParser extends Command {
|
2021-05-27 18:56:26 +00:00
|
|
|
init(ctx, log) {
|
|
|
|
this.log = log;
|
2021-06-04 20:14:40 +00:00
|
|
|
//initialize(ctx);
|
2021-05-27 18:56:26 +00:00
|
|
|
}
|
|
|
|
name = 'lights';
|
|
|
|
whitelist = true;
|
|
|
|
func(msg, args, ctx) {
|
|
|
|
if (ctx.sleep) {
|
|
|
|
msg.channel.createMessage('i have sleep mode enabled. the lights are probably off.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!args.length) {
|
|
|
|
msg.channel.createMessage('no args found.');
|
|
|
|
return;
|
|
|
|
}
|
2021-06-04 20:14:40 +00:00
|
|
|
// let instructions = parse(args[0]);
|
2020-11-07 23:12:27 +00:00
|
|
|
|
2021-06-04 20:14:40 +00:00
|
|
|
// this.log.debug(instructions);
|
|
|
|
// let res = '```\n';
|
|
|
|
// instructions.forEach((instruction) => {
|
|
|
|
// res += JSON.stringify(instruction) + '\n';
|
|
|
|
// });
|
|
|
|
// res += '```';
|
|
|
|
// msg.channel.createMessage(`parsed instructions:\n${res}`);
|
2021-05-27 18:56:26 +00:00
|
|
|
req(
|
2021-06-04 20:14:40 +00:00
|
|
|
args.join(' '),
|
2021-05-27 18:56:26 +00:00
|
|
|
(response) => {
|
2021-06-04 20:14:40 +00:00
|
|
|
msg.channel.createMessage(`\`\`\`\n${response}\`\`\``);
|
2021-05-27 18:56:26 +00:00
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
msg.channel.createMessage(`error: ${error.message}`);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-11-07 23:12:27 +00:00
|
|
|
}
|
|
|
|
initializer.addCommand(new LightsParser());
|
|
|
|
|
2020-11-12 09:48:33 +00:00
|
|
|
class Sleep extends Command {
|
2021-05-27 18:56:26 +00:00
|
|
|
name = 'sleep';
|
|
|
|
whitelist = true;
|
|
|
|
func(msg, args, ctx) {
|
|
|
|
let sleep = ctx.sleep;
|
|
|
|
sleep = !sleep;
|
|
|
|
msg.channel.createMessage(`sleep mode is now ${sleep ? 'on' : 'off'}`);
|
|
|
|
ctx.set_ctx('sleep', sleep);
|
|
|
|
}
|
2020-11-12 09:48:33 +00:00
|
|
|
}
|
|
|
|
initializer.addCommand(new Sleep());
|
|
|
|
|
2020-11-07 23:12:27 +00:00
|
|
|
export default initializer;
|