Add ability to resolve roles
parent
f26bee8c7a
commit
35ab708dfc
|
@ -1,5 +1,5 @@
|
||||||
import signale from 'signale';
|
import signale from 'signale';
|
||||||
import { Member, Message, Guild, PrivateChannel, GroupChannel } from 'eris';
|
import {Member, Message, Guild, PrivateChannel, GroupChannel, Role} from 'eris';
|
||||||
import { Client, Command, RichEmbed } from '.';
|
import { Client, Command, RichEmbed } from '.';
|
||||||
import { statusMessages as emotes } from '../configs/emotes.json';
|
import { statusMessages as emotes } from '../configs/emotes.json';
|
||||||
|
|
||||||
|
@ -47,6 +47,18 @@ export default class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(' ');
|
||||||
|
role = roles.find((r) => r.id === queries || r.name === queries || r.name.toLowerCase() === queries.toLowerCase() || r.name.toLowerCase().startsWith(queries.toLowerCase()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
public resolveMember(query: string, { members }: Guild): Member | undefined {
|
public resolveMember(query: string, { members }: Guild): Member | undefined {
|
||||||
let queries = query.split(' ').slice(0, 10).join(' ');
|
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
|
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
|
||||||
|
|
Loading…
Reference in New Issue