fix(src/class/Util.ts): Fix resolver
parent
cecd616a88
commit
ba328b6c7d
|
@ -49,13 +49,26 @@ export default class Util {
|
|||
|
||||
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));
|
||||
let member = guild.members.find((mem) => `${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 (!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;
|
||||
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);
|
||||
member = guild.members.find((mem) => `${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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue