From f121a9bd370b73a21bab0cf2d9f5b153e3bdaf24 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Tue, 14 Apr 2020 19:03:10 -0400 Subject: [PATCH] add Util class --- src/class/Util.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index e747c2f..d2d10f9 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -1,4 +1,4 @@ -// import { Message } from 'eris'; +import { Member, Message, Guild } from 'eris'; import { Client, Command } from '.'; export default class Util { @@ -36,4 +36,18 @@ export default class Util { return Promise.reject(error); } } + + public resolveMember(message: Message, search: string, guild: Guild): Member | undefined { + try { + let mem = guild.members.find((member) => `${member.user.username}#${member.user.discriminator}` === search || member.user.username === search || member.id === search || (message.mentions[0] && member.id === message.mentions[0].id) || (member.nick !== undefined && member.nick === search)); + // eslint-disable-next-line no-mixed-operators + if (!mem) mem = guild.members.find((member) => `${member.user.username.toLowerCase()}#${member.user.discriminator}` === search.toLowerCase() || member.user.username.toLowerCase() === search.toLowerCase() || member.nick !== undefined && member.nick.toLowerCase() === search.toLowerCase()); + // eslint-disable-next-line no-mixed-operators + if (!mem) mem = guild.members.find((member) => member.user.username.toLowerCase().includes(search.toLowerCase()) || member.nick !== undefined && member.nick.toLowerCase().includes(search.toLowerCase())); + if (mem) return mem; + return undefined; + } catch { + return undefined; + } + } }