Improve resolver further
Use startsWith over includes for better accuracy, allow iterations on the query to avoid accidental user input screwing up resolvermerge-requests/4/head
parent
4a94e56842
commit
f26bee8c7a
|
@ -48,9 +48,19 @@ export default class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveMember(query: string, { members }: Guild): Member | undefined {
|
public resolveMember(query: string, { members }: Guild): Member | undefined {
|
||||||
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
|
let queries = query.split(' ').slice(0, 10).join(' ');
|
||||||
|| 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 = members.find((m) => m.mention.replace('!', '') === queries.replace('!', '') || `${m.username}#${m.discriminator}` === query || m.username === queries || m.id === queries || m.nick === queries) // Exact match for mention, username+discrim, username and user ID
|
||||||
|| members.find((m) => m.username.toLowerCase().includes(query.toLowerCase()) || (m.nick && m.nick.toLowerCase().includes(query.toLowerCase())));
|
|| members.find((m) => `${m.username.toLowerCase()}#${m.discriminator}` === queries.toLowerCase() || m.username.toLowerCase() === queries.toLowerCase() || (m.nick && m.nick.toLowerCase() === queries.toLowerCase())) // Case insensitive match for username+discrim, username
|
||||||
|
|| members.find((m) => m.username.toLowerCase().startsWith(queries.toLowerCase()) || (m.nick && m.nick.toLowerCase().startsWith(queries.toLowerCase())));
|
||||||
|
if (queries.length > 1 && !member) {
|
||||||
|
while (!member && queries.length > 0) {
|
||||||
|
queries = queries.split(' ').slice(0, queries.length - 1).join(' ');
|
||||||
|
member = members.find((m) => m.mention.replace('!', '') === queries.replace('!', '') || `${m.username}#${m.discriminator}` === query || m.username === queries || m.id === queries || m.nick === queries) // Exact match for mention, username+discrim, username and user ID
|
||||||
|
|| members.find((m) => `${m.username.toLowerCase()}#${m.discriminator}` === queries.toLowerCase() || m.username.toLowerCase() === queries.toLowerCase() || (m.nick && m.nick.toLowerCase() === queries.toLowerCase())) // Case insensitive match for username+discrim, username
|
||||||
|
|| members.find((m) => m.username.toLowerCase().startsWith(queries.toLowerCase()) || (m.nick && m.nick.toLowerCase().startsWith(queries.toLowerCase())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return member;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async handleError(error: Error, message?: Message, command?: Command): Promise<void> {
|
public async handleError(error: Error, message?: Message, command?: Command): Promise<void> {
|
||||||
|
|
Loading…
Reference in New Issue