feat: beginning of moderation
This commit is contained in:
parent
2e3e0bbe0a
commit
07029ffc52
8 changed files with 115 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { Command } from '../Command';
|
import { Command } from '../Command';
|
||||||
import { MessageEmbed } from 'discord.js';
|
import { defaultEmbed } from '../../util/DefaultEmbed';
|
||||||
|
|
||||||
export const command = new Command(
|
export const command = new Command(
|
||||||
'ping',
|
'ping',
|
||||||
|
@ -7,19 +7,17 @@ export const command = new Command(
|
||||||
const m = await msg.channel.send('Ping?');
|
const m = await msg.channel.send('Ping?');
|
||||||
m.delete({ timeout: 100 });
|
m.delete({ timeout: 100 });
|
||||||
|
|
||||||
const embed = new MessageEmbed()
|
const embed = defaultEmbed()
|
||||||
.setTitle('Pong! :ping_pong:')
|
.setTitle('Pong! :ping_pong:')
|
||||||
.addField('Bot Latency', `${Math.round(lifeguard.ws.ping)}ms`)
|
.addField('Bot Latency', `${Math.round(lifeguard.ws.ping)}ms`)
|
||||||
.addField(
|
.addField(
|
||||||
'Message Latency',
|
'Message Latency',
|
||||||
`${m.createdTimestamp - msg.createdTimestamp}ms`
|
`${m.createdTimestamp - msg.createdTimestamp}ms`
|
||||||
)
|
)
|
||||||
.setColor(0x7289da)
|
|
||||||
.setFooter(
|
.setFooter(
|
||||||
`Executed By ${msg.author.tag}`,
|
`Executed By ${msg.author.tag}`,
|
||||||
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
||||||
)
|
);
|
||||||
.setTimestamp();
|
|
||||||
|
|
||||||
msg.channel.send(embed);
|
msg.channel.send(embed);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Command } from '../Command';
|
import { Command } from '../Command';
|
||||||
import { MessageEmbed } from 'discord.js';
|
|
||||||
import { inspect } from 'util';
|
import { inspect } from 'util';
|
||||||
import { runInNewContext } from 'vm';
|
import { runInNewContext } from 'vm';
|
||||||
|
import { defaultEmbed } from '../../util/DefaultEmbed';
|
||||||
|
|
||||||
function parseBlock(script: string) {
|
function parseBlock(script: string) {
|
||||||
const cbr = /^(([ \t]*`{3,4})([^\n]*)([\s\S]+?)(^[ \t]*\2))/gm;
|
const cbr = /^(([ \t]*`{3,4})([^\n]*)([\s\S]+?)(^[ \t]*\2))/gm;
|
||||||
|
@ -47,7 +47,7 @@ export const command = new Command(
|
||||||
{
|
{
|
||||||
lifeguard,
|
lifeguard,
|
||||||
msg,
|
msg,
|
||||||
MessageEmbed,
|
defaultEmbed,
|
||||||
dbUser,
|
dbUser,
|
||||||
},
|
},
|
||||||
{ filename: msg.guild?.id.toString() }
|
{ filename: msg.guild?.id.toString() }
|
||||||
|
@ -56,20 +56,16 @@ export const command = new Command(
|
||||||
const end = Date.now();
|
const end = Date.now();
|
||||||
|
|
||||||
if (typeof exec === 'string') {
|
if (typeof exec === 'string') {
|
||||||
const embed = new MessageEmbed()
|
const embed = defaultEmbed()
|
||||||
.addField('Input', makeCodeBlock(script, 'js'))
|
.addField('Input', makeCodeBlock(script, 'js'))
|
||||||
.addField('Output', makeCodeBlock(exec, 'js'))
|
.addField('Output', makeCodeBlock(exec, 'js'))
|
||||||
.setFooter(`Script Executed in ${end - start}ms`)
|
.setFooter(`Script Executed in ${end - start}ms`);
|
||||||
.setTimestamp()
|
|
||||||
.setColor(0x7289da);
|
|
||||||
msg.channel.send(embed);
|
msg.channel.send(embed);
|
||||||
} else {
|
} else {
|
||||||
const embed = new MessageEmbed()
|
const embed = defaultEmbed()
|
||||||
.addField('Input', makeCodeBlock(script, 'js'))
|
.addField('Input', makeCodeBlock(script, 'js'))
|
||||||
.addField('Output', makeCodeBlock(`${exec.name}: ${exec.message}`))
|
.addField('Output', makeCodeBlock(`${exec.name}: ${exec.message}`))
|
||||||
.setFooter(`Script Executed in ${end - start}ms`)
|
.setFooter(`Script Executed in ${end - start}ms`);
|
||||||
.setTimestamp()
|
|
||||||
.setColor(0x7289da);
|
|
||||||
msg.channel.send(embed);
|
msg.channel.send(embed);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
23
src/plugins/global/blacklist.ts
Normal file
23
src/plugins/global/blacklist.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { Command } from '../Command';
|
||||||
|
import { parseUser } from '../../util/parseUser';
|
||||||
|
|
||||||
|
export const command = new Command(
|
||||||
|
'blacklist',
|
||||||
|
async (lifeguard, msg, args) => {
|
||||||
|
const u = parseUser(args[0]);
|
||||||
|
try {
|
||||||
|
await lifeguard.db.users.findOneAndUpdate(
|
||||||
|
{ id: u },
|
||||||
|
{ $set: { blacklisted: true } },
|
||||||
|
{ returnOriginal: false }
|
||||||
|
);
|
||||||
|
msg.channel.send(`<@${u}> was sucessfully blacklisted`);
|
||||||
|
} catch (err) {
|
||||||
|
msg.channel.send(err.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 4,
|
||||||
|
usage: ['blacklist {user}'],
|
||||||
|
}
|
||||||
|
);
|
|
@ -1,13 +1,20 @@
|
||||||
import { Command } from '../Command';
|
import { Command } from '../Command';
|
||||||
import { MessageEmbed, Collection } from 'discord.js';
|
import { MessageEmbed, Collection, GuildMember, Guild } from 'discord.js';
|
||||||
import { Plugin } from '../Plugin';
|
import { Plugin } from '../Plugin';
|
||||||
|
import { calcUserLevel } from '../../assertions/userLevel';
|
||||||
|
import { defaultEmbed } from '../../util/DefaultEmbed';
|
||||||
|
|
||||||
function convertPlugins(plugins: Collection<string, Plugin>) {
|
function convertPlugins(
|
||||||
|
plugins: Collection<string, Plugin>,
|
||||||
|
member: GuildMember,
|
||||||
|
guild: Guild
|
||||||
|
) {
|
||||||
return plugins
|
return plugins
|
||||||
.map((plugin, key) => ({
|
.map((plugin, key) => ({
|
||||||
name: key,
|
name: key,
|
||||||
cmds: [...plugin.values()]
|
cmds: [...plugin.values()]
|
||||||
.filter(cmd => !cmd.options.hidden)
|
.filter(cmd => !cmd.options.hidden)
|
||||||
|
.filter(cmd => calcUserLevel(member, guild) >= cmd.options.level)
|
||||||
.map(cmd => cmd.name)
|
.map(cmd => cmd.name)
|
||||||
.sort((a, b) => a.localeCompare(b)),
|
.sort((a, b) => a.localeCompare(b)),
|
||||||
}))
|
}))
|
||||||
|
@ -18,19 +25,25 @@ export const command = new Command(
|
||||||
'help',
|
'help',
|
||||||
(lifeguard, msg, args) => {
|
(lifeguard, msg, args) => {
|
||||||
if (!args.length) {
|
if (!args.length) {
|
||||||
const plugins = convertPlugins(lifeguard.plugins);
|
const plugins = convertPlugins(
|
||||||
|
lifeguard.plugins,
|
||||||
|
msg.member as GuildMember,
|
||||||
|
msg.guild as Guild
|
||||||
|
);
|
||||||
|
|
||||||
const embed = new MessageEmbed()
|
const embed = defaultEmbed()
|
||||||
.setTitle('Lifeguard Help')
|
.setTitle('Lifeguard Help')
|
||||||
.setColor(0x7289da)
|
|
||||||
.setFooter(
|
.setFooter(
|
||||||
`Executed By ${msg.author.tag}`,
|
`Executed By ${msg.author.tag}`,
|
||||||
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
||||||
)
|
);
|
||||||
.setTimestamp();
|
|
||||||
|
|
||||||
for (const plugin of plugins) {
|
for (const plugin of plugins) {
|
||||||
embed.addField(plugin.name, plugin.cmds.join('\n'));
|
// console.log(plugin)
|
||||||
|
// embed.addField(plugin.name, plugin.cmds.join('\n'));
|
||||||
|
if (plugin.cmds.length > 0) {
|
||||||
|
embed.addField(plugin.name, plugin.cmds.join('\n'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.channel.send(embed);
|
msg.channel.send(embed);
|
||||||
|
@ -39,14 +52,12 @@ export const command = new Command(
|
||||||
const cmd = plugin?.get(args[0]);
|
const cmd = plugin?.get(args[0]);
|
||||||
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
const embed = new MessageEmbed()
|
const embed = defaultEmbed()
|
||||||
.setTitle(cmd.name)
|
.setTitle(cmd.name)
|
||||||
.setColor(0x7289da)
|
|
||||||
.setFooter(
|
.setFooter(
|
||||||
`Executed By ${msg.author.tag}`,
|
`Executed By ${msg.author.tag}`,
|
||||||
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
||||||
)
|
);
|
||||||
.setTimestamp();
|
|
||||||
|
|
||||||
const options = Object.entries(cmd.options);
|
const options = Object.entries(cmd.options);
|
||||||
options.map(([key, val]) => {
|
options.map(([key, val]) => {
|
||||||
|
|
38
src/plugins/moderation/role.ts
Normal file
38
src/plugins/moderation/role.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { Command } from '../Command';
|
||||||
|
import { parseUser } from '../../util/parseUser';
|
||||||
|
|
||||||
|
export const command = new Command(
|
||||||
|
'role',
|
||||||
|
async (lifeguard, msg, args) => {
|
||||||
|
const [cmd, uid, rid, ...r] = args;
|
||||||
|
const u = parseUser(uid);
|
||||||
|
const role = msg.guild?.roles.get(rid);
|
||||||
|
switch (cmd) {
|
||||||
|
case 'add':
|
||||||
|
if (role) {
|
||||||
|
const member = msg.guild?.members.get(u);
|
||||||
|
member?.roles.add(role, r.join(' '));
|
||||||
|
msg.channel.send(`Added ${role.name} to ${member}`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'rmv':
|
||||||
|
if (role) {
|
||||||
|
const member = msg.guild?.members.get(u);
|
||||||
|
member?.roles.remove(role, r.join(' '));
|
||||||
|
msg.channel.send(`Removed ${role.name} from ${member}`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
usage: [
|
||||||
|
'role add {user} {role id} [reason]',
|
||||||
|
'role rmv {user} {role id} [reason]',
|
||||||
|
],
|
||||||
|
}
|
||||||
|
);
|
|
@ -21,8 +21,10 @@ export async function PluginLoader() {
|
||||||
const files = await readDir(`${folderDir}`);
|
const files = await readDir(`${folderDir}`);
|
||||||
for await (const file of files) {
|
for await (const file of files) {
|
||||||
if (file.endsWith('.js')) {
|
if (file.endsWith('.js')) {
|
||||||
const command: Command = require(`./${folder}/${file}`).command;
|
const command = require(`./${folder}/${file}`).command;
|
||||||
plugin.set(command.name, command);
|
if (command instanceof Command) {
|
||||||
|
plugin.set(command.name, command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
src/util/DefaultEmbed.ts
Normal file
5
src/util/DefaultEmbed.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { MessageEmbed } from 'discord.js';
|
||||||
|
|
||||||
|
export function defaultEmbed() {
|
||||||
|
return new MessageEmbed().setColor(0x7289da).setTimestamp();
|
||||||
|
}
|
13
src/util/parseUser.ts
Normal file
13
src/util/parseUser.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
export function parseUser(user: string) {
|
||||||
|
if (user.startsWith("<@") && user.endsWith(">")) {
|
||||||
|
user = user.slice(2, -1);
|
||||||
|
|
||||||
|
if (user.startsWith("!")) {
|
||||||
|
user = user.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
} else {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue