diff --git a/cmd/reg.js b/cmd/reg.js index fabb293..2acdd8a 100644 --- a/cmd/reg.js +++ b/cmd/reg.js @@ -3,29 +3,50 @@ 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()); class RestartCommand extends Command { - name = 'restart'; - func(msg, args, ctx) { - msg.channel.createMessage('restarting.').then(() => { - process.exit(); - }); - } + name = 'restart'; + func(msg, args, ctx) { + msg.channel.createMessage('restarting.').then(() => { + process.exit(); + }); + } } initializer.addCommand(new RestartCommand()); +class EvalCommand extends Command { + name = 'eval'; + whitelist = true; + func(msg, args, ctx) { + log.debug('evaluating ' + args[0]); + let result; + try { + result = eval(args[0]); + } catch (e) { + result = e.stack; + } + log.debug('result is: \n' + result); + if (String.valueOf(result).length <= 1999) { + msg.channel.createMessage('```\n' + result + '```\n'); + } else { + msg.channel.createMessage('result too long, see logs'); + } + } +} + +initializer.addCommand(new EvalCommand()); + export default initializer; diff --git a/lights/request.js b/lights/request.js index 840eeee..d32c3df 100644 --- a/lights/request.js +++ b/lights/request.js @@ -39,7 +39,7 @@ export default function req(data, callback, errorCallback) { client.write(string_data); }) client.on('data', (dat) => { - callback(dat); + callback(String(dat)); client.destroy(); })