fix(spam): count duplicate mentions; only clean offending messages

This commit is contained in:
Dragory 2018-08-01 19:13:32 +03:00
parent e8c021eea6
commit 847ee11195
2 changed files with 64 additions and 16 deletions

View file

@ -238,3 +238,33 @@ export function trimLines(str: string) {
export const emptyEmbedValue = "\u200b";
export const embedPadding = "\n" + emptyEmbedValue;
export const userMentionRegex = /<@!?([0-9]+)>/g;
export const roleMentionRegex = /<&([0-9]+)>/g;
export function getUserMentions(str: string) {
const regex = new RegExp(userMentionRegex.source, "g");
const userIds = [];
let match;
// tslint:disable-next-line
while ((match = regex.exec(str)) !== null) {
console.log("m", match);
userIds.push(match[1]);
}
return userIds;
}
export function getRoleMentions(str: string) {
const regex = new RegExp(roleMentionRegex.source, "g");
const roleIds = [];
let match;
// tslint:disable-next-line
while ((match = regex.exec(str)) !== null) {
roleIds.push(match[1]);
}
return roleIds;
}