More efficient

This commit is contained in:
Neko Life 2021-05-11 14:17:20 +00:00
parent 547784d853
commit 87a7259ed1

View file

@ -26,7 +26,7 @@ module.exports = class avatar extends commando.Command {
const footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote; const footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote;
const args = arg.trim().split(/(?<!\\),+/); const args = arg.trim().split(/(?<!\\),+/);
const option = arg.trim().split(/(?<!\\)(\-\-)+/); const option = arg.trim().split(/(?<!\\)(\-\-)+/);
let user, avatar, member, show; let user, avatar, member, show, notFound = "";
let [allEmb, multipleMemMes, dupliCheck] = [[], [], []]; let [allEmb, multipleMemMes, dupliCheck] = [[], [], []];
if (!arg) { if (!arg) {
user = msg.guild ? msg.guild.member(msg.author) : msg.author; user = msg.guild ? msg.guild.member(msg.author) : msg.author;
@ -54,36 +54,33 @@ module.exports = class avatar extends commando.Command {
let uID = cleanMentionID(avThis.trim()); let uID = cleanMentionID(avThis.trim());
if (uID.length > 0) { if (uID.length > 0) {
let ree = []; let ree = [];
async function nonDigit(client) { if (/^\d{17,19}$/.test(uID)) {
const theree = findMemberRegEx(msg, uID); const findmem = msg.guild.member(uID);
if (theree?.length > 0) { if (findmem) {
for (const reeRes of theree) { ree.push(findmem.user);
ree.push(reeRes); } else {
await this.client.users.fetch(uID).then(fetchUser => ree.push(fetchUser)).catch(() => {});
} }
} else {
user = undefined;
trySend(client, msg, `Can't find user: **${avThis.trim()}**`);
}
}
if (/\D/.test(uID)) {
await nonDigit(this.client);
} else { } else {
if (msg.guild?.member(uID)) { ree = findMemberRegEx(msg, uID).map(r => r.user);
ree.push(msg.guild.member(uID));
} else {
await this.client.users.fetch(uID).then(r => ree.push(r)).catch(async e => await nonDigit(this.client));
}
} }
if (ree.length > 0) { if (ree.length > 0) {
const duplicateRes = dupliCheck.findIndex(yes => yes === ree[0].id); const duplicateRes = dupliCheck.findIndex(yes => yes === ree[0].id);
if (duplicateRes !== -1) { if (duplicateRes !== -1) {
allEmb[duplicateRes].setDescription(`Duplicate result for: **${avThis.trim()}**`); if (allEmb[duplicateRes].description !== null) {
allEmb[duplicateRes].setDescription(allEmb[duplicateRes].description.slice(0, -2) + ", " + avThis.trim() + "**");
} else {
allEmb[duplicateRes].setDescription(`Duplicate result for: **${avThis.trim()}**`);
}
user = undefined; user = undefined;
} else { } else {
dupliCheck.push(ree[0].id); dupliCheck.push(ree[0].id);
user = ree[0].user ?? ree[0]; user = ree[0];
multipleMemMes.push(multipleMembersFound(this.client, msg, ree, uID, show)); multipleMemMes.push(multipleMembersFound(this.client, msg, ree, uID, show));
} }
} else {
user = undefined;
notFound += `Can't find user: **${avThis.trim()}**\n`;
} }
if (user) { if (user) {
avatar = user.displayAvatarURL({size:4096,dynamic:true}); avatar = user.displayAvatarURL({size:4096,dynamic:true});
@ -128,6 +125,9 @@ module.exports = class avatar extends commando.Command {
} }
allEmb.push(emb); allEmb.push(emb);
} }
if (notFound.length > 0) {
trySend(this.client, msg, notFound);
}
for (let index = 0; index < allEmb.length; index++) { for (let index = 0; index < allEmb.length; index++) {
const embelement = allEmb[index]; const embelement = allEmb[index];
const contelement = multipleMemMes[index]; const contelement = multipleMemMes[index];