This commit is contained in:
Dragon Fire
2021-06-05 12:31:10 -04:00
parent 7917766ce3
commit 8809dee34c
19 changed files with 82 additions and 83 deletions
+33 -33
View File
@@ -1,35 +1,35 @@
{
"ADMINISTRATOR": "",
"CREATE_INSTANT_INVITE": "",
"KICK_MEMBERS": "",
"BAN_MEMBERS": "",
"MANAGE_CHANNELS": "",
"MANAGE_GUILD": "",
"ADD_REACTIONS": "",
"VIEW_AUDIT_LOG": "",
"PRIORITY_SPEAKER": "",
"STREAM": "",
"VIEW_CHANNEL": "",
"SEND_MESSAGES": "",
"SEND_TTS_MESSAGES": "",
"MANAGE_MESSAGES": "",
"EMBED_LINKS": "",
"ATTACH_FILES": "",
"READ_MESSAGE_HISTORY": "",
"MENTION_EVERYONE": "",
"USE_EXTERNAL_EMOJIS": "",
"VIEW_GUILD_INSIGHTS": "",
"CONNECT": "",
"SPEAK": "",
"MUTE_MEMBERS": "",
"DEAFEN_MEMBERS": "",
"MOVE_MEMBERS": "",
"USE_VAD": "",
"CHANGE_NICKNAME": "",
"MANAGE_NICKNAMES": "",
"MANAGE_ROLES": "",
"MANAGE_WEBHOOKS": "",
"MANAGE_EMOJIS": "",
"USE_APPLICATION_COMMANDS": "",
"REQUEST_TO_SPEAK": ""
"ADMINISTRATOR": "Administrator",
"CREATE_INSTANT_INVITE": "Create Invite",
"KICK_MEMBERS": "Kick Members",
"BAN_MEMBERS": "Ban Members",
"MANAGE_CHANNELS": "Manage Channels",
"MANAGE_GUILD": "Manage Server",
"ADD_REACTIONS": "Add Reactions",
"VIEW_AUDIT_LOG": "View Audit Log",
"PRIORITY_SPEAKER": "Priority Speaker",
"STREAM": "Video",
"VIEW_CHANNEL": "View Channels",
"SEND_MESSAGES": "Send Messages",
"SEND_TTS_MESSAGES": "Send Text-to-Speech Messages",
"MANAGE_MESSAGES": "Manage Messages",
"EMBED_LINKS": "Embed Links",
"ATTACH_FILES": "Attach Files",
"READ_MESSAGE_HISTORY": "Read Message History",
"MENTION_EVERYONE": "Mention everyone, here, and All Roles",
"USE_EXTERNAL_EMOJIS": "Use External Emoji",
"VIEW_GUILD_INSIGHTS": "View Server Insights",
"CONNECT": "Connect",
"SPEAK": "Speak",
"MUTE_MEMBERS": "Mute Members",
"DEAFEN_MEMBERS": "Deafen Members",
"MOVE_MEMBERS": "Move Members",
"USE_VAD": "Use Voice Activity",
"CHANGE_NICKNAME": "Change Nickname",
"MANAGE_NICKNAMES": "Manage Nicknames",
"MANAGE_ROLES": "Manage Roles",
"MANAGE_WEBHOOKS": "Manage Webhooks",
"MANAGE_EMOJIS": "Manage Emojis",
"USE_APPLICATION_COMMANDS": "Use Slash Commands",
"REQUEST_TO_SPEAK": "Request to Speak"
}
+8 -9
View File
@@ -32,7 +32,7 @@ module.exports = class EvalCommand extends Command {
run(msg, args) {
// Make a bunch of helpers
/* eslint-disable no-unused-vars */
/* eslint-disable no-unused-vars destructuring */
const message = msg;
const client = msg.client;
const lastResult = this.lastResult;
@@ -42,13 +42,13 @@ module.exports = class EvalCommand extends Command {
} else {
const result = this.makeResultMessages(val, process.hrtime(this.hrStart));
if (Array.isArray(result)) {
for(const item of result) msg.reply(item);
for (const item of result) msg.reply(item);
} else {
msg.reply(result);
}
}
};
/* eslint-enable no-unused-vars */
/* eslint-enable no-unused-vars destructuring */
// Remove any surrounding code blocks before evaluation
if (args.script.startsWith('```') && args.script.endsWith('```')) {
@@ -81,10 +81,10 @@ module.exports = class EvalCommand extends Command {
.replace(this.sensitivePattern, '--snip--');
const split = inspected.split('\n');
const last = inspected.length - 1;
const prependPart = inspected[0] !== '{' && inspected[0] !== '[' && inspected[0] !== "'" ? split[0] : inspected[0];
const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== "'" ?
split[split.length - 1] :
inspected[last];
const prependPart = inspected[0] !== '{' && inspected[0] !== '[' && inspected[0] !== '\'' ? split[0] : inspected[0];
const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== '\''
? split[split.length - 1]
: inspected[last];
const prepend = `\`\`\`javascript\n${prependPart}\n`;
const append = `\n${appendPart}\n\`\`\``;
if (input) {
@@ -106,9 +106,8 @@ module.exports = class EvalCommand extends Command {
get sensitivePattern() {
if (!this._sensitivePattern) {
const client = this.client;
let pattern = '';
if (client.token) pattern += escapeRegex(client.token);
if (this.client.token) pattern += escapeRegex(this.client.token);
Object.defineProperty(this, '_sensitivePattern', { value: new RegExp(pattern, 'gi'), configurable: false });
}
return this._sensitivePattern;
+5 -2
View File
@@ -1,5 +1,6 @@
const { Client } = require('discord.js');
const fs = require('fs');
const path = require('path');
const { stripIndents } = require('common-tags');
const Registry = require('./Registry');
const Dispatcher = require('./Dispatcher');
@@ -95,7 +96,9 @@ module.exports = class CommandClient extends Client {
const throttleAmount = command.throttles.get(msg.author.id) || 0;
if (throttleAmount >= command.throttling.uses) {
const timeout = command._timeouts.get(msg.author.id);
await msg.reply(`Please wait ${getTimeLeft(timeout)} seconds before using the \`${command.name}\` command again.`);
await msg.reply(
`Please wait ${getTimeLeft(timeout)} seconds before using the \`${command.name}\` command again.`
);
return;
}
command.throttles.set(msg.author.id, throttleAmount + 1);
@@ -224,5 +227,5 @@ module.exports = class CommandClient extends Client {
};
function getTimeLeft(timeout) {
return Math.ceil((timeout._idleStart + timeout._idleTimeout - Date.now()) / 1000);
return Math.ceil((timeout._idleStart + timeout._idleTimeout - Date.now()) / 1000);
}
+2 -2
View File
@@ -31,8 +31,8 @@ module.exports = class CommandDispatcher {
};
}
const content = msg.content.replace(this.commandPattern, '').trim();
const result = (content.match(argRegex) || []).map(m => m.replace(argRegex, '$1$2'));
const parsed = minimist(result);
const firstResult = (content.match(argRegex) || []).map(m => m.replace(argRegex, '$1$2'));
const parsed = minimist(firstResult);
const result = { flags: [...parsed] };
for (let i = 0; i > command.args.length; i++) {
const arg = command.args[i];
+2 -5
View File
@@ -1,11 +1,7 @@
const { Structures } = require('discord.js');
module.exports = Structures.extend('Message', Message => {
return class CommandMessage extends Message {
constructor(...args) {
super(...args);
}
class CommandMessage extends Message {
say(content, options) {
return this.channel.send(content, options);
}
@@ -18,4 +14,5 @@ module.exports = Structures.extend('Message', Message => {
return this.channel.send(content, { code: lang, ...options });
}
}
return CommandMessage;
});
+4 -4
View File
@@ -28,8 +28,8 @@ module.exports = class Registry {
const commands = fs.readdirSync(path.join(dir, group));
for (const command of commands) {
if (!command.endsWith('.js')) continue;
const required = require(path.join(dir, group, command));
this.registerCommand(new required(this.client));
const Required = require(path.join(dir, group, command));
this.registerCommand(new Required(this.client));
}
}
return this;
@@ -62,8 +62,8 @@ module.exports = class Registry {
const types = fs.readdirSync(dir);
for (const type of types) {
if (!type.endsWith('.js')) continue;
const required = require(path.join(dir, type));
this.registerType(new required(this.client));
const Required = require(path.join(dir, type));
this.registerType(new Required(this.client));
}
return this;
}
+1 -1
View File
@@ -18,4 +18,4 @@ module.exports = class BooleanArgumentType extends ArgumentType {
if (this.falsy.has(lc)) return false;
throw new RangeError('Unknown boolean value.');
}
}
};
+1 -1
View File
@@ -28,7 +28,7 @@ module.exports = class ChannelArgumentType extends ArgumentType {
if (exactChannels.size === 1) return exactChannels.first();
return null;
}
}
};
function nameFilterExact(search) {
return thing => thing.name.toLowerCase() === search;
+1 -1
View File
@@ -14,4 +14,4 @@ module.exports = class CommandArgumentType extends ArgumentType {
parse(val) {
return this.client.registry.findCommands(val).first();
}
}
};
+1 -1
View File
@@ -29,7 +29,7 @@ module.exports = class CustomEmojiArgumentType extends ArgumentType {
if (exactEmojis.size === 1) return exactEmojis.first();
return null;
}
}
};
function nameFilterExact(search) {
return emoji => emoji.name.toLowerCase() === search;
+1 -1
View File
@@ -15,4 +15,4 @@ module.exports = class DefaultEmojiArgumentType extends ArgumentType {
parse(value) {
return value;
}
}
};
+1 -1
View File
@@ -17,4 +17,4 @@ module.exports = class FloatArgumentType extends ArgumentType {
parse(val) {
return Number.parseFloat(val);
}
}
};
+1 -1
View File
@@ -14,4 +14,4 @@ module.exports = class GroupArgumentType extends ArgumentType {
parse(val) {
return this.client.registry.findGroups(val).first();
}
}
};
+3 -3
View File
@@ -6,7 +6,7 @@ module.exports = class IntegerArgumentType extends ArgumentType {
}
validate(val, msg, arg) {
const int = Number.parseInt(val);
const int = Number.parseInt(val, 10);
if (Number.isNaN(int)) return false;
if (arg.oneOf && !arg.oneOf.includes(int)) return false;
if (arg.min !== null && typeof arg.min !== 'undefined' && int < arg.min) return false;
@@ -15,6 +15,6 @@ module.exports = class IntegerArgumentType extends ArgumentType {
}
parse(val) {
return Number.parseInt(val);
return Number.parseInt(val, 10);
}
}
};
+7 -7
View File
@@ -36,16 +36,16 @@ module.exports = class MemberArgumentType extends ArgumentType {
if (exactMembers.size === 1) return exactMembers.first();
return null;
}
}
};
function memberFilterExact(search) {
return mem => mem.user.username.toLowerCase() === search ||
(mem.nickname && mem.nickname.toLowerCase() === search) ||
mem.tag.toLowerCase() === search;
return mem => mem.user.username.toLowerCase() === search
|| (mem.nickname && mem.nickname.toLowerCase() === search)
|| mem.tag.toLowerCase() === search;
}
function memberFilterInexact(search) {
return mem => mem.user.username.toLowerCase().includes(search) ||
(mem.nickname && mem.nickname.toLowerCase().includes(search)) ||
mem.tag.toLowerCase().includes(search);
return mem => mem.user.username.toLowerCase().includes(search)
|| (mem.nickname && mem.nickname.toLowerCase().includes(search))
|| mem.tag.toLowerCase().includes(search);
}
+1 -1
View File
@@ -13,4 +13,4 @@ module.exports = class MessageArgumentType extends ArgumentType {
parse(val, msg) {
return msg.channel.messages.cache.get(val);
}
}
};
+1 -1
View File
@@ -28,7 +28,7 @@ module.exports = class RoleArgumentType extends ArgumentType {
if (exactRoles.size === 1) return exactRoles.first();
return null;
}
}
};
function nameFilterExact(search) {
return thing => thing.name.toLowerCase() === search;
+1 -1
View File
@@ -15,4 +15,4 @@ module.exports = class StringArgumentType extends ArgumentType {
parse(val) {
return val;
}
}
};
+8 -8
View File
@@ -5,7 +5,7 @@ module.exports = class UserArgumentType extends ArgumentType {
super(client, 'user');
}
async validate(val, msg, arg) {
async validate(val, msg) {
const matches = val.match(/^(?:<@!?)?([0-9]+)>?$/);
if (matches) {
try {
@@ -38,16 +38,16 @@ module.exports = class UserArgumentType extends ArgumentType {
if (exactMembers.size === 1) return exactMembers.first().user;
return null;
}
}
};
function memberFilterExact(search) {
return mem => mem.user.username.toLowerCase() === search ||
(mem.nickname && mem.nickname.toLowerCase() === search) ||
mem.tag.toLowerCase() === search;
return mem => mem.user.username.toLowerCase() === search
|| (mem.nickname && mem.nickname.toLowerCase() === search)
|| mem.tag.toLowerCase() === search;
}
function memberFilterInexact(search) {
return mem => mem.user.username.toLowerCase().includes(search) ||
(mem.nickname && mem.nickname.toLowerCase().includes(search)) ||
mem.tag.toLowerCase().includes(search);
return mem => mem.user.username.toLowerCase().includes(search)
|| (mem.nickname && mem.nickname.toLowerCase().includes(search))
|| mem.tag.toLowerCase().includes(search);
}