3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

automod: ensure actions only apply once per user/member

This commit is contained in:
Dragory 2020-07-29 22:58:14 +03:00
parent e55a1e3bd6
commit c39d69dd5d
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
9 changed files with 27 additions and 22 deletions

View file

@ -423,9 +423,11 @@ interface MatchedURL extends url.URL {
input: string;
}
export function getUrlsInString(str: string, unique = false): MatchedURL[] {
export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
let matches = str.match(urlRegex) || [];
if (unique) matches = Array.from(new Set(matches));
if (onlyUnique) {
matches = unique(matches);
}
return matches.reduce((urls, match) => {
const withProtocol = protocolRegex.test(match) ? match : `https://${match}`;
@ -1230,3 +1232,7 @@ export function isGuildInvite(invite: AnyInvite): invite is GuildInvite {
export function asyncMap<T, R>(arr: T[], fn: (item: T) => Promise<R>): Promise<R[]> {
return Promise.all(arr.map((item, index) => fn(item)));
}
export function unique<T>(arr: T[]): T[] {
return Array.from(new Set(arr));
}