initial commit; add events system
This commit is contained in:
parent
2e7834b17e
commit
fc1f05ae0c
11 changed files with 532 additions and 0 deletions
94
cmd/perm.js
Normal file
94
cmd/perm.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
import { CommandInitializer, Command } from '../parser.js';
|
||||
|
||||
const initializer = new CommandInitializer();
|
||||
|
||||
class WhitelistUser extends Command {
|
||||
name = 'wu';
|
||||
whitelist = true;
|
||||
func = async function (msg, args, ctx) {
|
||||
let user = await ctx.bot.users.get(args[0].trim());
|
||||
this.log.debug(msg.channel.guild.members);
|
||||
this.log.debug(user);
|
||||
if (!user) {
|
||||
user = msg.channel.guild.members.get(args[0].trim());
|
||||
this.log.debug(user);
|
||||
if (!user) {
|
||||
user = (await msg.channel.guild.fetchMembers({ userIDs: [args[0]] }))[0];
|
||||
this.log.debug(user);
|
||||
}
|
||||
}
|
||||
if (user.username) {
|
||||
if (!ctx.whitelist.wl) {
|
||||
ctx.whitelist.wl = {
|
||||
user: [],
|
||||
guild: [],
|
||||
};
|
||||
}
|
||||
let list = ctx.whitelist.wl.user || [];
|
||||
if (!list.includes(args[0])) {
|
||||
list.push(args[0]);
|
||||
ctx.whitelist.wl.user = list;
|
||||
ctx.whitelist.save();
|
||||
msg.channel.createMessage(`added user "${user.username}#${user.discriminator}" (${args[0]}) to whitelist`);
|
||||
} else {
|
||||
msg.channel.createMessage('user already whitelisted');
|
||||
}
|
||||
} else {
|
||||
msg.channel.createMessage(`user with id ${args[0]} could not be found`);
|
||||
}
|
||||
};
|
||||
}
|
||||
initializer.addCommand(new WhitelistUser());
|
||||
|
||||
class WhitelistGuild extends Command {
|
||||
name = 'wg';
|
||||
whitelist = true;
|
||||
func = async function (msg, args, ctx) {
|
||||
let guild = await ctx.bot.guilds.get(args[0]);
|
||||
if (guild && guild.name) {
|
||||
if (!ctx.whitelist.wl) {
|
||||
ctx.whitelist.wl = {
|
||||
user: [],
|
||||
guild: [],
|
||||
};
|
||||
}
|
||||
let list = ctx.whitelist.wl.guild || [];
|
||||
if (!list.includes(args[0])) {
|
||||
list.push(args[0]);
|
||||
ctx.whitelist.wl.guild = list;
|
||||
ctx.whitelist.save();
|
||||
msg.channel.createMessage(`added guild "${guild.name}" (${args[0]}) to whitelist`);
|
||||
} else {
|
||||
msg.channel.createMessage('guild already whitelisted');
|
||||
}
|
||||
} else {
|
||||
msg.channel.createMessage(`guild with id ${args[0]} could not be found`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initializer.addCommand(new WhitelistGuild());
|
||||
|
||||
class Purge extends Command {
|
||||
name = 'purge';
|
||||
whitelist = true;
|
||||
func = async function (msg, args, ctx) {
|
||||
let guilds = await ctx.bot.guilds;
|
||||
let whitelist = ctx.whitelist.guild;
|
||||
let purged = 0;
|
||||
guilds.forEach((guild) => {
|
||||
if (!whitelist(guild)) {
|
||||
this.log.info(`purging guild ${guild.name} (${guild.id})`);
|
||||
guild.leave();
|
||||
purged++;
|
||||
} else {
|
||||
this.log.debug(`keeping guild ${guild.name} (${guild.id})`);
|
||||
}
|
||||
});
|
||||
msg.channel.createMessage(`purged ${purged} guilds.`);
|
||||
};
|
||||
}
|
||||
|
||||
initializer.addCommand(new Purge());
|
||||
|
||||
export default initializer;
|
52
cmd/reg.js
Normal file
52
cmd/reg.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
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';
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initializer.addCommand(new RestartCommand());
|
||||
|
||||
class EvalCommand extends Command {
|
||||
name = 'eval';
|
||||
whitelist = true;
|
||||
func(msg, args, ctx) {
|
||||
log.debug('evaluating ' + args[0]);
|
||||
let result = eval(args[0]);
|
||||
log.debug('result is: \n' + result);
|
||||
if (result.length <= 1999) {
|
||||
msg.channel.createMessage(result);
|
||||
}
|
||||
else {
|
||||
msg.channel.createMessage("result too long, see logs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initializer.addCommand(new EvalCommand());
|
||||
|
||||
export default initializer;
|
Loading…
Add table
Add a link
Reference in a new issue