Fix thread header ping not working, utilize allowed_mentions
parent
c467c7d0f6
commit
581b09a8ae
|
@ -20,6 +20,11 @@ const intents = [
|
||||||
const bot = new Eris.Client(config.token, {
|
const bot = new Eris.Client(config.token, {
|
||||||
restMode: true,
|
restMode: true,
|
||||||
intents: Array.from(new Set(intents)),
|
intents: Array.from(new Set(intents)),
|
||||||
|
allowedMentions: {
|
||||||
|
everyone: false,
|
||||||
|
roles: false,
|
||||||
|
users: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -331,19 +331,25 @@ class Thread {
|
||||||
// Interrupt scheduled closing, if in progress
|
// Interrupt scheduled closing, if in progress
|
||||||
if (this.scheduled_close_at) {
|
if (this.scheduled_close_at) {
|
||||||
await this.cancelScheduledClose();
|
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) {
|
if (this.alert_ids) {
|
||||||
const ids = this.alert_ids.split(",");
|
const ids = this.alert_ids.split(",");
|
||||||
let mentions = "";
|
const mentionsStr = ids.map(id => `<@!${id}> `).join("");
|
||||||
|
|
||||||
ids.forEach(id => {
|
|
||||||
mentions += `<@!${id}> `;
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.deleteAlerts();
|
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,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,7 @@ async function createNewThreadForUser(user, opts = {}) {
|
||||||
if (config.mentionRole) {
|
if (config.mentionRole) {
|
||||||
await newThread.postNonLogMessage({
|
await newThread.postNonLogMessage({
|
||||||
content: `${utils.getInboxMention()}New modmail thread (${newThread.user_name})`,
|
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────────────────";
|
infoHeader += "\n────────────────";
|
||||||
|
|
||||||
await newThread.postSystemMessage(infoHeader);
|
await newThread.postSystemMessage({
|
||||||
|
content: infoHeader,
|
||||||
|
allowedMentions: config.mentionUserInThreadHeader ? { users: [user.id] } : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
if (config.updateNotifications) {
|
if (config.updateNotifications) {
|
||||||
const availableUpdate = await updates.getAvailableUpdate();
|
const availableUpdate = await updates.getAvailableUpdate();
|
||||||
|
|
|
@ -243,6 +243,7 @@ function initBaseMessageHandlers() {
|
||||||
let content;
|
let content;
|
||||||
const mainGuilds = utils.getMainGuilds();
|
const mainGuilds = utils.getMainGuilds();
|
||||||
const staffMention = (config.pingOnBotMention ? utils.getInboxMention() : "");
|
const staffMention = (config.pingOnBotMention ? utils.getInboxMention() : "");
|
||||||
|
const allowedMentions = (config.pingOnBotMention ? utils.getInboxMentionAllowedMentions() : undefined);
|
||||||
|
|
||||||
if (mainGuilds.length === 1) {
|
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}>`;
|
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, {
|
bot.createMessage(utils.getLogChannel().id, {
|
||||||
content,
|
content,
|
||||||
disableEveryone: false,
|
allowedMentions,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send an auto-response to the mention, if enabled
|
// Send an auto-response to the mention, if enabled
|
||||||
|
|
|
@ -9,7 +9,12 @@ module.exports = ({ bot, knex, config, commands }) => {
|
||||||
const logChannel = utils.getLogChannel();
|
const logChannel = utils.getLogChannel();
|
||||||
for (const userId of expiredBlocks) {
|
for (const userId of expiredBlocks) {
|
||||||
await blocked.unblock(userId);
|
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);
|
const blockStatus = await blocked.getBlockStatus(userIdToCheck);
|
||||||
if (blockStatus.isBlocked) {
|
if (blockStatus.isBlocked) {
|
||||||
if (blockStatus.expiresAt) {
|
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 {
|
} else {
|
||||||
msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked indefinitely`);
|
msg.channel.createMessage({
|
||||||
|
content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked indefinitely`,
|
||||||
|
allowedMentions: { users: [userIdToCheck] },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is NOT blocked`);
|
msg.channel.createMessage({
|
||||||
|
content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is NOT blocked`,
|
||||||
|
allowedMentions: { users: [userIdToCheck] },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
29
src/utils.js
29
src/utils.js
|
@ -46,18 +46,18 @@ function getMainGuilds() {
|
||||||
* @returns {Eris~TextChannel}
|
* @returns {Eris~TextChannel}
|
||||||
*/
|
*/
|
||||||
function getLogChannel() {
|
function getLogChannel() {
|
||||||
const inboxGuild = getInboxGuild();
|
const _inboxGuild = getInboxGuild();
|
||||||
const logChannel = inboxGuild.channels.get(config.logChannelId);
|
const _logChannel = _inboxGuild.channels.get(config.logChannelId);
|
||||||
|
|
||||||
if (! logChannel) {
|
if (! _logChannel) {
|
||||||
throw new BotError("Log channel (logChannelId) not found!");
|
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!");
|
throw new BotError("Make sure the logChannelId option is set to a text channel!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return logChannel;
|
return _logChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function postLog(...args) {
|
function postLog(...args) {
|
||||||
|
@ -217,7 +217,7 @@ function chunk(items, chunkSize) {
|
||||||
function trimAll(str) {
|
function trimAll(str) {
|
||||||
return str
|
return str
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map(str => str.trim())
|
.map(_str => _str.trim())
|
||||||
.join("\n");
|
.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +263,22 @@ function getInboxMention() {
|
||||||
return mentions.join(" ") + " ";
|
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) {
|
function postSystemMessageWithFallback(channel, thread, text) {
|
||||||
if (thread) {
|
if (thread) {
|
||||||
thread.postSystemMessage(text);
|
thread.postSystemMessage(text);
|
||||||
|
@ -343,6 +359,7 @@ module.exports = {
|
||||||
delayStringRegex,
|
delayStringRegex,
|
||||||
convertDelayStringToMS,
|
convertDelayStringToMS,
|
||||||
getInboxMention,
|
getInboxMention,
|
||||||
|
getInboxMentionAllowedMentions,
|
||||||
postSystemMessageWithFallback,
|
postSystemMessageWithFallback,
|
||||||
|
|
||||||
chunk,
|
chunk,
|
||||||
|
|
Loading…
Reference in New Issue