merge-requests/4/merge
Bsian 2020-04-15 11:12:36 -04:00
parent 6a95ad10e5
commit b4ff1ce805
1 changed files with 2 additions and 26 deletions

View File

@ -48,32 +48,8 @@ export default class Util {
} }
public resolveMember(message: Message, search: string, guild: Guild): Member | undefined { public resolveMember(message: Message, search: string, guild: Guild): Member | undefined {
try { return members.find((m) => m.mention.replace('!', '') === query.replace('!', '') || `${m.username}#${m.discriminator}` === query || m.username === query || m.id === query || m.nick === query) // Exact match for mention, username+discrim, username and user ID
// Name, Mention, or ID || members.find((m) => `${m.username.toLowerCase()}#${m.discriminator}` === query.toLowerCase() || m.username.toLowerCase() === query.toLowerCase() || (m.nick && m.nick.toLowerCase() === query.toLowerCase())) // Case insensitive match for username+discrim, username
let member = guild.members.find((mem) => mem.user.id === message.mentions[0].id || `${mem.user.username}#${mem.user.discriminator}` === search || mem.user.id === search || mem.user.username === search || mem.user.username.startsWith(search) || mem.user.username.toLowerCase() === search.toLowerCase() || mem.user.username.toLowerCase().startsWith(search.toLowerCase()));
// Nickname
// eslint-disable-next-line no-mixed-operators
if (!member) {
member = guild.members.find((mem) => mem.nick && (mem.nick === search || mem.nick.startsWith(search) || mem.nick.toLowerCase() === search.toLowerCase() || mem.nick.toLowerCase().startsWith(search.toLowerCase())));
}
if (search.split(' ').length > 1 && !member) {
let nSearch = search.split(' ');
while (!member && nSearch.length > 0) {
nSearch = nSearch.slice(0, nSearch.length - 1);
// Name, Mention, or ID
member = guild.members.find((mem) => mem.user.id === message.mentions[0].id || `${mem.user.username}#${mem.user.discriminator}` === search || mem.user.id === search || mem.user.username === search || mem.user.username.startsWith(search) || mem.user.username.toLowerCase() === search.toLowerCase() || mem.user.username.toLowerCase().startsWith(search.toLowerCase()));
// Nickname
// eslint-disable-next-line no-mixed-operators
if (!member) {
member = guild.members.find((mem) => mem.nick && (mem.nick === search || mem.nick.startsWith(search) || mem.nick.toLowerCase() === search.toLowerCase() || mem.nick.toLowerCase().startsWith(search.toLowerCase())));
}
}
}
if (!member) return undefined;
return member;
} catch {
return undefined;
}
} }
public async handleError(error: Error, message?: Message, command?: Command): Promise<void> { public async handleError(error: Error, message?: Message, command?: Command): Promise<void> {