led-bot/cmd/lights.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

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 {
init(ctx, log) {
this.log = log;
2021-06-04 20:14:40 +00:00
//initialize(ctx);
}
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}`);
req(
2021-06-04 20:14:40 +00:00
args.join(' '),
(response) => {
2021-06-04 20:14:40 +00:00
msg.channel.createMessage(`\`\`\`\n${response}\`\`\``);
},
(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 {
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;