UNPKG

889 BPlain TextView Raw
1import { Guild, User } from 'discord.js'
2
3export function checkMKeep (m: string) { return m.toLowerCase().startsWith('m!keep') }
4export function checkIgnoredSequences (m: string) {
5 return Array.isArray(config.ignoredSequences) &&
6 config.ignoredSequences.map(r => new RegExp(r)).some(r => r.test(m))
7}
8export function truncatePeople (people: string[]) {
9 return people.length > 10
10 ? people.slice(0, 10).join(', ') + ` and ${people.length - 10} more...`
11 : people.join(', ')
12}
13export function splitString (str: string, fragmentLength: number): string[] {
14 return str.length > fragmentLength
15 ? str.match(new RegExp(`[\\s\\S]{1,${fragmentLength}}`, 'g'))!!
16 : [ str ]
17}
18export function hasAdmin (user: User, guild: Guild) {
19 const member = guild.members.find(member => user.id === member.id)
20 return member.hasPermission('ADMINISTRATOR') || guild.ownerID === user.id
21}