finish migration of lights script to backend

This commit is contained in:
jane 2021-06-04 23:51:59 -04:00
parent be73eaa4cd
commit 8b6116e0cc
2 changed files with 38 additions and 17 deletions

View file

@ -3,29 +3,50 @@ import { CommandInitializer, Command } from '../parser.js';
const initializer = new CommandInitializer(); const initializer = new CommandInitializer();
class PingCommand extends Command { class PingCommand extends Command {
name = 'ping'; name = 'ping';
func(msg, args, ctx) { func(msg, args, ctx) {
msg.channel.createMessage('p').then((m) => { msg.channel.createMessage('p').then((m) => {
m.edit( m.edit(
`rtt: ${Math.floor(m.timestamp - msg.timestamp)}, gateway: ${ `rtt: ${Math.floor(m.timestamp - msg.timestamp)}, gateway: ${ctx.bot.shards.get(ctx.bot.guildShardMap[ctx.bot.channelGuildMap[msg.channel.id]] || 0).latency
ctx.bot.shards.get(ctx.bot.guildShardMap[ctx.bot.channelGuildMap[msg.channel.id]] || 0).latency }`
}` );
); });
}); }
}
} }
initializer.addCommand(new PingCommand()); initializer.addCommand(new PingCommand());
class RestartCommand extends Command { class RestartCommand extends Command {
name = 'restart'; name = 'restart';
func(msg, args, ctx) { func(msg, args, ctx) {
msg.channel.createMessage('restarting.').then(() => { msg.channel.createMessage('restarting.').then(() => {
process.exit(); process.exit();
}); });
} }
} }
initializer.addCommand(new RestartCommand()); 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; export default initializer;

View file

@ -39,7 +39,7 @@ export default function req(data, callback, errorCallback) {
client.write(string_data); client.write(string_data);
}) })
client.on('data', (dat) => { client.on('data', (dat) => {
callback(dat); callback(String(dat));
client.destroy(); client.destroy();
}) })