diff --git a/bot.js b/bot.js index 07177cf..53b46d3 100644 --- a/bot.js +++ b/bot.js @@ -12,13 +12,17 @@ const cfg = require('./config.json'); const dir = dirname(import.meta.url); const bot = new Eris(cfg.token); -const ctx = { + +global.ctx = { bot: bot, log_level: levels.DEBUG, - whitelist: cfg.user_whitelist || [] + whitelist: cfg.user_whitelist || [], + set_ctx: (key, value) => { + global.ctx[key] = value; + }, }; -const log = new Logger(filename(import.meta.url), ctx.log_level); -const parse = new CommandParser(ctx); +const log = new Logger(filename(import.meta.url), global.ctx.log_level); +const parse = new CommandParser(global.ctx); const checkGuild = (guild) => { if (!cfg.whitelist.includes(guild.id)) { @@ -34,7 +38,9 @@ bot.on('ready', () => { bot.on('guildAvaliable', (guild) => checkGuild(guild)); -bot.on('messageCreate', (msg) => parse.parseMsg(msg, ctx)); +bot.on('messageCreate', (msg) => parse.parseMsg(msg, global.ctx)); + +bot.on('error', (err) => log.error(err.toString())); bot.connect(); @@ -51,7 +57,7 @@ async function load_commands() { } if (obj.default != undefined) { if (obj.default.constructor.name == 'CommandInitializer') { - obj.default.initialize(ctx); + obj.default.initialize(global.ctx); let cmds = obj.default.getCommands(); if (parse.isCmd(cmds)) { parse.addCommand(cmds); diff --git a/cmd/lights.js b/cmd/lights.js index 7cf5bea..db088dd 100644 --- a/cmd/lights.js +++ b/cmd/lights.js @@ -12,6 +12,10 @@ class LightsParser extends Command { 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; @@ -31,11 +35,23 @@ class LightsParser extends Command { msg.channel.createMessage(`${response}`); }, (error) => { - msg.channel.createMessage(`error.`); + msg.channel.createMessage(`error: ${error.message}`); } ); } } initializer.addCommand(new LightsParser()); +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); + } +} +initializer.addCommand(new Sleep()); + export default initializer; diff --git a/lights/light_parser.js b/lights/light_parser.js index 2ef8e6d..2d8df25 100644 --- a/lights/light_parser.js +++ b/lights/light_parser.js @@ -16,6 +16,14 @@ const available_targets = { g: new Target('g'), b: new Target('b'), stack: new Target('stack'), + stack2: new Target('stack2'), + stack3: new Target('stack3'), + stack4: new Target('stack4'), + stack5: new Target('stack5'), + stack6: new Target('stack6'), + stack6: new Target('stackr'), + stack6: new Target('stackg'), + stack6: new Target('stackb'), tick: new Target('tick'), index: new Target('index'), }; @@ -47,7 +55,11 @@ export const instructions = [ { n: 'MULTIPLY', a: true }, { n: 'DIVIDE', a: true }, { n: 'MODULO', a: true }, + { n: 'FADE', a: true }, { n: 'RANDOM', a: false }, + { n: 'JMP', a: false }, + { n: 'JNZ', a: true }, + { n: 'JEZ', a: true }, ]; export function initialize(ctx) { diff --git a/lights/request.js b/lights/request.js index ac05297..ca412c9 100644 --- a/lights/request.js +++ b/lights/request.js @@ -15,6 +15,10 @@ function padLeft(size = 4, str = '') { export default function req(data, callback, errorCallback) { let string_data = JSON.stringify(data); let size = getBinarySize(string_data); + if (size > 9999) { + errorCallback("too long"); + return; + } let client = new net.Socket(); client.connect(port, hostname, () => {