Add ability to resolve roles

merge-requests/4/head
Null 2020-04-15 10:57:37 -05:00
parent f26bee8c7a
commit 35ab708dfc
No known key found for this signature in database
GPG Key ID: CFD79C1EC586E7BD
1 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,5 @@
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 { 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 {
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