Unify mentionRole parsing

cshd
Dragory 2020-11-01 21:01:42 +02:00
parent a8580e1ef8
commit f6825376c0
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 11 additions and 6 deletions

View File

@ -251,12 +251,18 @@ function convertDelayStringToMS(str) {
return ms; return ms;
} }
function getInboxMention() { function getValidMentionRoles() {
const mentionRoles = Array.isArray(config.mentionRole) ? config.mentionRole : [config.mentionRole]; const mentionRoles = Array.isArray(config.mentionRole) ? config.mentionRole : [config.mentionRole];
return mentionRoles.filter(roleStr => {
return (roleStr !== null && roleStr !== "none" && roleStr !== "off" && roleStr !== "");
});
}
function getInboxMention() {
const mentionRoles = getValidMentionRoles();
const mentions = []; const mentions = [];
for (const role of mentionRoles) { for (const role of mentionRoles) {
if (role == null || role === "none" || role === "off" || role === "") continue; if (role === "here") mentions.push("@here");
else if (role === "here") mentions.push("@here");
else if (role === "everyone") mentions.push("@everyone"); else if (role === "everyone") mentions.push("@everyone");
else mentions.push(`<@&${role}>`); else mentions.push(`<@&${role}>`);
} }
@ -264,15 +270,14 @@ function getInboxMention() {
} }
function getInboxMentionAllowedMentions() { function getInboxMentionAllowedMentions() {
const mentionRoles = Array.isArray(config.mentionRole) ? config.mentionRole : [config.mentionRole]; const mentionRoles = getValidMentionRoles();
const allowedMentions = { const allowedMentions = {
everyone: false, everyone: false,
roles: [], roles: [],
}; };
for (const role of mentionRoles) { for (const role of mentionRoles) {
if (role == null || role === "none" || role === "") continue; if (role === "here" || role === "everyone") allowedMentions.everyone = true;
else if (role === "here" || role === "everyone") allowedMentions.everyone = true;
else allowedMentions.roles.push(role); else allowedMentions.roles.push(role);
} }