light command

This commit is contained in:
jane 2020-11-07 22:29:13 -05:00
parent 9eda4abcf7
commit 6c7bbc2304
7 changed files with 378 additions and 232 deletions

View file

@ -1,24 +1,40 @@
import {CommandInitializer, Command} from "../parser.js";
import parse, {instructions} from "../lights/light_parser.js";
import { CommandInitializer, Command } from '../parser.js';
import parse, { initialize, instructions } from '../lights/light_parser.js';
import req from '../lights/request.js';
const initializer = new CommandInitializer();
class LightsParser extends Command {
init(ctx, log) {
this.log = log;
}
name = "lights";
func(msg, args, ctx) {
let instructions = parse(args[0]);
init(ctx, log) {
this.log = log;
initialize(ctx);
}
name = 'lights';
whitelist = true;
func(msg, args, ctx) {
if (!args.length) {
msg.channel.createMessage('no args found.');
return;
}
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),
(response) => {
msg.channel.createMessage(`${response.statusCode}`);
},
(error) => {
msg.channel.createMessage(`error.`);
}
);
}
}
initializer.addCommand(new LightsParser());

View file

@ -1,14 +1,18 @@
import {CommandInitializer, Command} from "../parser.js";
import { CommandInitializer, Command } from '../parser.js';
const initializer = new CommandInitializer();
class PingCommand extends Command {
name = "ping";
func(msg, args, ctx) {
msg.channel.createMessage("p").then(m => {
m.edit(`rtt: ${Math.floor(m.timestamp - msg.timestamp)}, gateway: ${ctx.bot.shards.get(ctx.bot.guildShardMap[ctx.bot.channelGuildMap[msg.channel.id]] || 0).latency}`);
});
}
name = 'ping';
func(msg, args, ctx) {
msg.channel.createMessage('p').then((m) => {
m.edit(
`rtt: ${Math.floor(m.timestamp - msg.timestamp)}, gateway: ${
ctx.bot.shards.get(ctx.bot.guildShardMap[ctx.bot.channelGuildMap[msg.channel.id]] || 0).latency
}`
);
});
}
}
initializer.addCommand(new PingCommand());