pinbot/cmd/reg.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-04-05 20:53:19 +00:00
import { CommandInitializer, Command } from '../parser.js';
import Logger, { levels } from '../logger.js';
import { filename } from '../utils.js';
const initializer = new CommandInitializer();
const log = new Logger(filename(import.meta.url), global.ctx.log_level);
class PingCommand extends Command {
name = 'ping';
2021-04-10 05:12:10 +00:00
aliases = ['p'];
2021-04-05 20:53:19 +00:00
func(msg, args, ctx) {
msg.channel.createMessage('p').then((m) => {
m.edit(
2021-04-10 05:12:10 +00:00
`rtt: ${Math.floor(m.timestamp - msg.timestamp)}ms, gateway: ${
2021-04-05 20:53:19 +00:00
ctx.bot.shards.get(ctx.bot.guildShardMap[ctx.bot.channelGuildMap[msg.channel.id]] || 0).latency
2021-04-10 05:12:10 +00:00
}ms`
2021-04-05 20:53:19 +00:00
);
});
}
}
initializer.addCommand(new PingCommand());
class RestartCommand extends Command {
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) {
2021-04-10 05:12:10 +00:00
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');
}
2021-04-05 20:53:19 +00:00
}
}
initializer.addCommand(new EvalCommand());
2021-04-10 05:12:10 +00:00
class HelpCommand extends Command {
name = 'help';
description = 'get help for commands';
helptext = '```md\nhelp\nshows this text\n\nhelp <command>\nshows the helptext for <command>';
func(msg, args, ctx) {}
}
initializer.addCommand(new HelpCommand());
2021-04-05 20:53:19 +00:00
export default initializer;