Added lookup member command

This commit is contained in:
Neko Life 2021-05-08 23:46:13 +00:00
parent 56211ad566
commit d88bb5c75c
3 changed files with 87 additions and 27 deletions

View file

@ -2,7 +2,7 @@
const commando = require("@iceprod/discord.js-commando");
const { MessageEmbed } = require("discord.js");
const { ranLog, errLog, trySend, findMemberRegEx, multipleMembersFound } = require("../../resources/functions");
const { ranLog, errLog, trySend, findMemberRegEx, multipleMembersFound, cleanMentionID } = require("../../resources/functions");
const { database } = require("../../database/mongo");
const { randomColors } = require("../../config.json");
@ -16,11 +16,6 @@ module.exports = class avatar extends commando.Command {
description: "Avatar showcase."
});
}
/**
*
* @param {commando.CommandoMessage} msg
* @param {*} arg
*/
async run(msg, arg) {
const doc = msg.guild?.id ?? msg.author.id;
const config = database.collection(msg.guild ? "Guild" : "User");
@ -29,7 +24,8 @@ module.exports = class avatar extends commando.Command {
errLog(docErr, msg, this.client);
}
const footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote;
const withPerm = arg.trim().split(/,/);
const withPerm = arg.trim().split(/,+/);
console.log(withPerm);
const option = arg.trim().split(/(\-\-)+/);
let user, avatar, member, show;
let [allEmb, multipleMemMes, dupliCheck] = [[], [], []];
@ -55,22 +51,11 @@ module.exports = class avatar extends commando.Command {
}
}
}
if (arg) {
if (args.length !== 0) {
for(const theAvThis of args) {
const avThis = theAvThis.replace(/\-\-show *\d*/i, "");
let uID = avThis.trim();
if (uID.startsWith('<@')) {
uID = uID.slice(2);
}
if (uID.startsWith('!')) {
uID = uID.slice(1);
}
if (uID.endsWith('>')) {
uID = uID.slice(0,-1)
}
if (uID.startsWith("@")) {
uID = uID.slice(1);
}
uID = cleanMentionID(uID);
if (uID.length === 1) {
return trySend(this.client, msg, "One character for searching member isn't allowed <:catstareLife:794930503076675584>");
} else {
@ -103,7 +88,7 @@ module.exports = class avatar extends commando.Command {
} else {
dupliCheck.push(ree[0].id);
user = ree[0].user ?? ree[0];
multipleMemMes.push(await multipleMembersFound(this.client, msg, ree, uID, show));
multipleMemMes.push(multipleMembersFound(this.client, msg, ree, uID, show));
}
}
if (user) {

53
cmds/utility/lookup.js Normal file
View file

@ -0,0 +1,53 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const { cleanMentionID, findMemberRegEx, multipleMembersFound, trySend } = require("../../resources/functions");
module.exports = class lookup extends commando.Command {
constructor(client) {
super(client, {
name: "lookup",
memberName: "lookup",
group: "utility",
description: "Lookup something in the server using mention, ID, or RegExp."
});
}
async run(msg, arg) {
let show;
const showArg = arg.match(/\-\-show *\d*/i);
if (showArg?.[0]) {
const digit = showArg[0].match(/\d*/g);
for (const val of digit) {
if (val.length > 0) {
const res = parseInt(val, 10);
show = res;
}
}
}
arg = arg.replace(/\-\-show *\d*/i, "");
const args = arg.split(/ +/);
let [fetchedMember, memMes] = [[], ""];
if (args[0].toLowerCase() === "member") {
if (args[1]) {
const memberID = cleanMentionID(arg.slice("member".length).trim());
if (!/\D/.test(memberID)) {
fetchedMember.push(msg.guild.member(memberID));
}
if (/\D/.test(memberID) || fetchedMember[0] === undefined) {
fetchedMember = await findMemberRegEx(msg, this.client, memberID);
}
if (fetchedMember.length > 1) {
memMes = multipleMembersFound(this.client, msg, fetchedMember, memberID, show, true);
} else {
if (fetchedMember.length === 0) {
return trySend(this.client, msg, `No member found for: **${memberID}**`);
}
memMes = `Member found for: **${memberID}**\`\`\`md\n# ${fetchedMember[0].user.tag} (${fetchedMember[0].user.id})\`\`\``;
}
}
}
if (memMes.length > 0) {
return trySend(this.client, msg, memMes);
}
}
};

View file

@ -171,17 +171,19 @@ async function ranLog(msg, cmd, addition) {
* @param {GuildMember[]} arr - Test array
* @param {String} key - Keyword
* @param {Number} max - Max length
* @returns {Promise<String>}
* @param {Boolean} withID - Include user_ID
* @returns {String}
*/
async function multipleMembersFound(client, msg, arr, key, max) {
if (!max) {
max = 5;
}
function multipleMembersFound(client, msg, arr, key, max = 5, withID) {
if (arr.length > 1) {
try {
let multipleFound = [];
for(const one of arr) {
multipleFound.push((await (client.users.fetch(one.id))).tag);
let mes = one.user.tag;
if (withID) {
mes = mes + ` (${one.user.id})`;
}
multipleFound.push(mes);
}
let multi = [];
for(const mu of multipleFound) {
@ -323,7 +325,27 @@ async function defaultImageEmbed(client, msg, image, author, title, footerText)
return emb;
}
/**
* Return clean ID of provided key
* @param {String} key - Mention | Channel Name | Username | Rolename
* @returns {String} Clean ID
*/
function cleanMentionID(key) {
let uID = key.trim();
if (uID.startsWith('<@') || uID.startsWith('<#')) {
uID = uID.slice(2);
}
if (uID.endsWith('>')) {
uID = uID.slice(0,-1)
}
if (uID.startsWith('!') || uID.startsWith("@") || uID.startsWith("#") || uID.startsWith('&')) {
uID = uID.slice(1);
}
return uID;
}
module.exports = {
cleanMentionID,
multipleMembersFound,
findMemberRegEx, getUser,
getChannelMessage, errLog,