Add channel resolver
parent
2206a11050
commit
3c6ecb8e76
|
@ -1,5 +1,5 @@
|
||||||
import signale from 'signale';
|
import signale from 'signale';
|
||||||
import {Member, Message, Guild, PrivateChannel, GroupChannel, Role} from 'eris';
|
import { Member, Message, Guild, PrivateChannel, GroupChannel, Role, AnyGuildChannel } 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,20 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
public resolveRole(query: string, { roles }: Guild): Role | undefined {
|
public resolveRole(query: string, { roles }: Guild): Role | undefined {
|
||||||
let queries = query.split(' ').slice(0, 10).join(' ');
|
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()));
|
let role = roles.find((r) => r.id === queries || r.name === queries || r.name.toLowerCase() === queries.toLowerCase() || r.name.toLowerCase().startsWith(queries.toLowerCase()));
|
||||||
|
|
Loading…
Reference in New Issue