add Util class

merge-requests/1/merge
Matthew 2020-04-14 19:03:10 -04:00
parent 54151f911c
commit f121a9bd37
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 15 additions and 1 deletions

View File

@ -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;
}
}
}