misc fixes

This commit is contained in:
Erik 2021-06-20 14:12:23 +03:00
parent 0d62a410ad
commit 346707d5da
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16
5 changed files with 69 additions and 4 deletions

View File

@ -14,7 +14,7 @@ class Registry {
find(name) {
return this.commands.find((c) => c.name === name || c.aliases?.includes(name));
return this.commands.find((c) => c.name === name.toLowerCase() || c.aliases?.includes(name.toLowerCase()));
}

View File

@ -72,6 +72,70 @@ class Resolver {
}
/**
* Resolve multiple channels
*
* @param {Array<String>} [resolveables=[]] an array of channel resolveables (name, id)
* @param {Guild} guild the guild in which to look for channels
* @param {Boolean} [strict=false] whether or not partial names are resolved
* @param {Function} [filter=()] filter the resolving channels
* @returns {Promise<Array<GuildChannel>> || Promise<Boolean>} an array of guild channels or false if none were resolved
* @memberof Resolver
*/
async resolveChannels(resolveables = [], strict = false, guild = null, filter = () => true) {
if (typeof resolveables === 'string') resolveables = [resolveables];
if (resolveables.length === 0) return false;
if (!guild) return false;
const CM = guild.channels;
const resolved = [];
for (const resolveable of resolveables) {
const channel = CM.resolve(resolveable);
if (channel && filter(channel)) {
resolved.push(channel);
continue;
}
const name = /^#?([a-z0-9\-_0]+)/iu;
const id = /^<?#?([0-9]{17,22})>?/iu;
if (id.test(resolveable)) {
const match = resolveable.match(id);
const [, ch] = match;
const channel = await this.client.channels.fetch(ch).catch((e) => { }); //eslint-disable-line no-empty, no-empty-function, no-unused-vars
if (channel && filter(channel)) resolved.push(channel);
} else if (name.test(resolveable)) {
const match = resolveable.match(name);
const ch = match[1].toLowerCase();
const channel = CM.cache.sort((a, b) => a.name.length - b.name.length).filter(filter).filter((c) => {
if (!strict) return c.name.toLowerCase().includes(ch);
return c.name.toLowerCase() === ch;
}).first();
if (channel) resolved.push(channel);
}
}
return resolved.length > 0 ? resolved : false;
}
async resolveChannel(resolveable, strict, guild, filter) {
if (!resolveable) return false;
if (resolveable instanceof Array) throw new Error('Resolveable cannot be of type Array, use resolveChannels for resolving arrays of channels');
const result = await this.resolveChannels([resolveable], strict, guild, filter);
return result ? result[0] : false;
}
}
module.exports = Resolver;

View File

@ -14,6 +14,7 @@ class Eval extends Command {
async execute(message, { clean }) {
if (!this.client._options.evalAccess.includes(message.author.id)) return;
const { guild, author, member, client, channel } = message; //eslint-disable-line no-unused-vars
try {

View File

@ -8,9 +8,9 @@ class Markread extends Command {
});
}
async execute(message) {
async execute(message, { args }) {
return this.client.modmail.markread(message);
return this.client.modmail.markread(message, args);
}

View File

@ -25,7 +25,7 @@ class Modmail extends Command {
first = second;
}
const user = await this.client.resolveUser(first);
const user = await this.client.resolveUser(first, true);
if (!user) return {
error: true,
msg: 'Failed to resolve user'