Merge branch 'master' into 'master'
Revert to stricter resolver See merge request engineering/communityrelations!5merge-requests/3/merge
commit
95d4c34add
|
@ -51,49 +51,18 @@ export default class Util {
|
|||
}
|
||||
|
||||
public resolveGuildChannel(query: string, { channels }: Guild): AnyGuildChannel | undefined {
|
||||
let queries = query.split(' ').slice(0, 10).join(' ');
|
||||
const nchannels = channels.map((c) => c).sort((a: AnyGuildChannel, b: AnyGuildChannel) => a.type - b.type);
|
||||
let channel = nchannels.find((c) => (c.id === queries || c.name === queries || c.name.toLowerCase() === queries.toLowerCase() || c.name.toLowerCase().startsWith(queries.toLowerCase())));
|
||||
if (!channel && queries.split(' ').length > 0) {
|
||||
while (!channel && queries.split(' ').length > 1) {
|
||||
queries = queries.split(' ').slice(0, queries.split(' ').length - 1).join(' ');
|
||||
// eslint-disable-next-line no-loop-func
|
||||
channel = nchannels.find((c) => c.id === queries || c.name === queries || c.name.toLowerCase() === queries.toLowerCase() || c.name.toLowerCase().startsWith(queries.toLowerCase()));
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
const nchannels = channels.map(c => c).sort((a: AnyGuildChannel, b: AnyGuildChannel) => a.type - b.type);
|
||||
return nchannels.find((c) => (c.id === query || c.name === query || c.name.toLowerCase() === query.toLowerCase() || c.name.toLowerCase().startsWith(query.toLowerCase())));
|
||||
}
|
||||
|
||||
public resolveRole(query: string, { roles }: Guild): Role | undefined {
|
||||
let queries = query.split(' ').slice(0, 10).join(' ');
|
||||
let role = roles.find((r) => r.id === queries || r.name === queries || r.name.toLowerCase() === queries.toLowerCase() || r.name.toLowerCase().startsWith(queries.toLowerCase()));
|
||||
if (!role && queries.split(' ').length > 0) {
|
||||
while (!role && queries.split(' ').length > 1) {
|
||||
queries = queries.split(' ').slice(0, queries.split(' ').length - 1).join(' ');
|
||||
// eslint-disable-next-line no-loop-func
|
||||
role = roles.find((r) => r.id === queries || r.name === queries || r.name.toLowerCase() === queries.toLowerCase() || r.name.toLowerCase().startsWith(queries.toLowerCase()));
|
||||
}
|
||||
}
|
||||
return role;
|
||||
return roles.find((r) => r.id === query || r.name === query || r.name.toLowerCase() === query.toLowerCase() || r.name.toLowerCase().startsWith(query.toLowerCase()));
|
||||
}
|
||||
|
||||
public resolveMember(query: string, { members }: Guild): Member | undefined {
|
||||
let queries = query.split(' ').slice(0, 10).join(' ');
|
||||
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()}#${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.split(' ').length > 1 && !member) {
|
||||
while (!member && queries.split(' ').length > 0) {
|
||||
queries = queries.split(' ').slice(0, queries.length - 1).join(' ');
|
||||
// eslint-disable-next-line no-loop-func
|
||||
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
|
||||
// eslint-disable-next-line no-loop-func
|
||||
|| 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
|
||||
// eslint-disable-next-line no-loop-func
|
||||
|| members.find((m) => m.username.toLowerCase().startsWith(queries.toLowerCase()) || (m.nick && m.nick.toLowerCase().startsWith(queries.toLowerCase())));
|
||||
}
|
||||
}
|
||||
return member;
|
||||
return members.find((m) => m.mention.replace('!', '') === query.replace('!', '') || `${m.username}#${m.discriminator}` === query || m.username === queries || m.id === query || m.nick === query) // Exact match for mention, username+discrim, username and user 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
|
||||
|| members.find((m) => m.username.toLowerCase().startsWith(query.toLowerCase()) || (m.nick && m.nick.toLowerCase().startsWith(query.toLowerCase())));
|
||||
}
|
||||
|
||||
public async handleError(error: Error, message?: Message, command?: Command, disable?: boolean): Promise<void> {
|
||||
|
|
Loading…
Reference in New Issue