Fix thread header ping not working, utilize allowed_mentions

cshd
Dragory 2020-08-21 05:13:24 +03:00
parent c467c7d0f6
commit 581b09a8ae
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
6 changed files with 66 additions and 20 deletions

View File

@ -20,6 +20,11 @@ const intents = [
const bot = new Eris.Client(config.token, {
restMode: true,
intents: Array.from(new Set(intents)),
allowedMentions: {
everyone: false,
roles: false,
users: false,
},
});
/**

View File

@ -331,19 +331,25 @@ class Thread {
// Interrupt scheduled closing, if in progress
if (this.scheduled_close_at) {
await this.cancelScheduledClose();
await this.postSystemMessage(`<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`);
await this.postSystemMessage({
content: `<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`,
allowedMentions: {
users: [this.scheduled_close_id],
},
});
}
if (this.alert_ids) {
const ids = this.alert_ids.split(",");
let mentions = "";
ids.forEach(id => {
mentions += `<@!${id}> `;
});
const mentionsStr = ids.map(id => `<@!${id}> `).join("");
await this.deleteAlerts();
await this.postSystemMessage(`${mentions}New message from ${this.user_name}`);
await this.postSystemMessage({
content: `${mentionsStr}New message from ${this.user_name}`,
allowedMentions: {
users: ids,
},
});
}
}

View File

@ -186,7 +186,7 @@ async function createNewThreadForUser(user, opts = {}) {
if (config.mentionRole) {
await newThread.postNonLogMessage({
content: `${utils.getInboxMention()}New modmail thread (${newThread.user_name})`,
disableEveryone: false
allowedMentions: utils.getInboxMentionAllowedMentions(),
});
}
@ -255,7 +255,10 @@ async function createNewThreadForUser(user, opts = {}) {
infoHeader += "\n────────────────";
await newThread.postSystemMessage(infoHeader);
await newThread.postSystemMessage({
content: infoHeader,
allowedMentions: config.mentionUserInThreadHeader ? { users: [user.id] } : undefined,
});
if (config.updateNotifications) {
const availableUpdate = await updates.getAvailableUpdate();

View File

@ -243,6 +243,7 @@ function initBaseMessageHandlers() {
let content;
const mainGuilds = utils.getMainGuilds();
const staffMention = (config.pingOnBotMention ? utils.getInboxMention() : "");
const allowedMentions = (config.pingOnBotMention ? utils.getInboxMentionAllowedMentions() : undefined);
if (mainGuilds.length === 1) {
content = `${staffMention}Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}(${msg.author.id})**: "${msg.cleanContent}"\n\n<https:\/\/discordapp.com\/channels\/${msg.channel.guild.id}\/${msg.channel.id}\/${msg.id}>`;
@ -252,7 +253,7 @@ function initBaseMessageHandlers() {
bot.createMessage(utils.getLogChannel().id, {
content,
disableEveryone: false,
allowedMentions,
});
// Send an auto-response to the mention, if enabled

View File

@ -9,7 +9,12 @@ module.exports = ({ bot, knex, config, commands }) => {
const logChannel = utils.getLogChannel();
for (const userId of expiredBlocks) {
await blocked.unblock(userId);
logChannel.createMessage(`Block of <@!${userId}> (id \`${userId}\`) expired`);
logChannel.createMessage({
content: `Block of <@!${userId}> (id \`${userId}\`) expired`,
allowedMentions: {
users: [userId],
},
});
}
}
@ -88,12 +93,21 @@ module.exports = ({ bot, knex, config, commands }) => {
const blockStatus = await blocked.getBlockStatus(userIdToCheck);
if (blockStatus.isBlocked) {
if (blockStatus.expiresAt) {
msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked until ${blockStatus.expiresAt} (UTC)`);
msg.channel.createMessage({
content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked until ${blockStatus.expiresAt} (UTC)`,
allowedMentions: { users: [userIdToCheck] },
});
} else {
msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked indefinitely`);
msg.channel.createMessage({
content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked indefinitely`,
allowedMentions: { users: [userIdToCheck] },
});
}
} else {
msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is NOT blocked`);
msg.channel.createMessage({
content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is NOT blocked`,
allowedMentions: { users: [userIdToCheck] },
});
}
});
};

View File

@ -46,18 +46,18 @@ function getMainGuilds() {
* @returns {Eris~TextChannel}
*/
function getLogChannel() {
const inboxGuild = getInboxGuild();
const logChannel = inboxGuild.channels.get(config.logChannelId);
const _inboxGuild = getInboxGuild();
const _logChannel = _inboxGuild.channels.get(config.logChannelId);
if (! logChannel) {
if (! _logChannel) {
throw new BotError("Log channel (logChannelId) not found!");
}
if (! (logChannel instanceof Eris.TextChannel)) {
if (! (_logChannel instanceof Eris.TextChannel)) {
throw new BotError("Make sure the logChannelId option is set to a text channel!");
}
return logChannel;
return _logChannel;
}
function postLog(...args) {
@ -217,7 +217,7 @@ function chunk(items, chunkSize) {
function trimAll(str) {
return str
.split("\n")
.map(str => str.trim())
.map(_str => _str.trim())
.join("\n");
}
@ -263,6 +263,22 @@ function getInboxMention() {
return mentions.join(" ") + " ";
}
function getInboxMentionAllowedMentions() {
const mentionRoles = Array.isArray(config.mentionRole) ? config.mentionRole : [config.mentionRole];
const allowedMentions = {
everyone: false,
roles: [],
};
for (const role of mentionRoles) {
if (role == null) continue;
else if (role === "here" || role === "everyone") allowedMentions.everyone = true;
else allowedMentions.roles.push(role);
}
return allowedMentions;
}
function postSystemMessageWithFallback(channel, thread, text) {
if (thread) {
thread.postSystemMessage(text);
@ -343,6 +359,7 @@ module.exports = {
delayStringRegex,
convertDelayStringToMS,
getInboxMention,
getInboxMentionAllowedMentions,
postSystemMessageWithFallback,
chunk,