Add 'logChannelId' config option
parent
748fd3c463
commit
ddff708ff5
|
@ -58,3 +58,4 @@ These go in `config.json`. See also `config.example.json`.
|
||||||
|url|None|URL to use for attachment and log links. Defaults to `IP:PORT`|
|
|url|None|URL to use for attachment and log links. Defaults to `IP:PORT`|
|
||||||
|snippetPrefix|"!!"|Prefix to use snippets. Defaults to `prefix` x2.|
|
|snippetPrefix|"!!"|Prefix to use snippets. Defaults to `prefix` x2.|
|
||||||
|inboxServerPermission|None|Permission required to use bot commands on the inbox server|
|
|inboxServerPermission|None|Permission required to use bot commands on the inbox server|
|
||||||
|
|logChannelId|Server's default channel|Channel where to post links to closed threads and other alerts|
|
||||||
|
|
34
src/index.js
34
src/index.js
|
@ -52,7 +52,7 @@ function formatAttachment(attachment) {
|
||||||
if (config.alwaysReply) {
|
if (config.alwaysReply) {
|
||||||
bot.on('messageCreate', msg => {
|
bot.on('messageCreate', msg => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
if (msg.author.bot) return;
|
if (msg.author.bot) return;
|
||||||
if (msg.content[0] == bot.commandOptions.prefix) return;
|
if (msg.content[0] == bot.commandOptions.prefix) return;
|
||||||
|
@ -67,12 +67,12 @@ bot.on('messageCreate', msg => {
|
||||||
|
|
||||||
if (msg.mentions.some(user => user.id === bot.user.id)) {
|
if (msg.mentions.some(user => user.id === bot.user.id)) {
|
||||||
// If the person who mentioned the modmail bot is on the modmail server, don't ping about it
|
// If the person who mentioned the modmail bot is on the modmail server, don't ping about it
|
||||||
if (utils.getModmailGuild(bot).members.get(msg.author.id)) return;
|
if (utils.getInboxGuild(bot).members.get(msg.author.id)) return;
|
||||||
|
|
||||||
blocked.isBlocked(msg.author.id).then(isBlocked => {
|
blocked.isBlocked(msg.author.id).then(isBlocked => {
|
||||||
if (isBlocked) return;
|
if (isBlocked) return;
|
||||||
|
|
||||||
bot.createMessage(utils.getModmailGuild(bot).id, {
|
bot.createMessage(utils.getLogChannel(bot).id, {
|
||||||
content: `@here Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`,
|
content: `@here Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`,
|
||||||
disableEveryone: false,
|
disableEveryone: false,
|
||||||
});
|
});
|
||||||
|
@ -119,7 +119,7 @@ Here's what their message contained:
|
||||||
\`\`\`${content}\`\`\`
|
\`\`\`${content}\`\`\`
|
||||||
`.trim();
|
`.trim();
|
||||||
|
|
||||||
bot.createMessage(utils.getModmailGuild(bot).id, {
|
bot.createMessage(utils.getLogChannel(bot).id, {
|
||||||
content: warningMessage,
|
content: warningMessage,
|
||||||
disableEveryone: false,
|
disableEveryone: false,
|
||||||
});
|
});
|
||||||
|
@ -160,7 +160,7 @@ Here's what their message contained:
|
||||||
|
|
||||||
// Send an automatic reply to the user informing them of the successfully created modmail thread
|
// Send an automatic reply to the user informing them of the successfully created modmail thread
|
||||||
msg.channel.createMessage(config.responseMessage || "Thank you for your message! Our mod team will reply to you here as soon as possible.").then(null, (err) => {
|
msg.channel.createMessage(config.responseMessage || "Thank you for your message! Our mod team will reply to you here as soon as possible.").then(null, (err) => {
|
||||||
bot.createMessage(utils.getModmailGuild(bot).id, {
|
bot.createMessage(utils.getLogChannel(bot).id, {
|
||||||
content: `There is an issue sending messages to ${msg.author.username}#${msg.author.discriminator} (id ${msg.author.id}); consider messaging manually`
|
content: `There is an issue sending messages to ${msg.author.username}#${msg.author.discriminator} (id ${msg.author.id}); consider messaging manually`
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -285,7 +285,7 @@ function reply(msg, text, anonymous = false) {
|
||||||
// These messages get relayed back to the DM thread between the bot and the user
|
// These messages get relayed back to the DM thread between the bot and the user
|
||||||
bot.registerCommand('reply', (msg, args) => {
|
bot.registerCommand('reply', (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
const text = args.join(' ').trim();
|
const text = args.join(' ').trim();
|
||||||
|
@ -297,7 +297,7 @@ bot.registerCommandAlias('r', 'reply');
|
||||||
// Anonymous replies only show the role, not the username
|
// Anonymous replies only show the role, not the username
|
||||||
bot.registerCommand('anonreply', (msg, args) => {
|
bot.registerCommand('anonreply', (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
const text = args.join(' ').trim();
|
const text = args.join(' ').trim();
|
||||||
|
@ -308,7 +308,7 @@ bot.registerCommandAlias('ar', 'anonreply');
|
||||||
|
|
||||||
bot.registerCommand('close', (msg, args) => {
|
bot.registerCommand('close', (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
threads.getByChannelId(msg.channel.id).then(thread => {
|
threads.getByChannelId(msg.channel.id).then(thread => {
|
||||||
|
@ -328,7 +328,7 @@ bot.registerCommand('close', (msg, args) => {
|
||||||
const closeMessage = `Modmail thread with ${thread.username} (${thread.userId}) was closed by ${msg.author.username}
|
const closeMessage = `Modmail thread with ${thread.username} (${thread.userId}) was closed by ${msg.author.username}
|
||||||
Logs: <${url}>`;
|
Logs: <${url}>`;
|
||||||
|
|
||||||
bot.createMessage(utils.getModmailGuild(bot).id, closeMessage);
|
bot.createMessage(utils.getLogChannel(bot).id, closeMessage);
|
||||||
threads.close(thread.channelId).then(() => msg.channel.delete());
|
threads.close(thread.channelId).then(() => msg.channel.delete());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -338,7 +338,7 @@ Logs: <${url}>`;
|
||||||
|
|
||||||
bot.registerCommand('block', (msg, args) => {
|
bot.registerCommand('block', (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
function block(userId) {
|
function block(userId) {
|
||||||
|
@ -362,7 +362,7 @@ bot.registerCommand('block', (msg, args) => {
|
||||||
|
|
||||||
bot.registerCommand('unblock', (msg, args) => {
|
bot.registerCommand('unblock', (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
function unblock(userId) {
|
function unblock(userId) {
|
||||||
|
@ -386,7 +386,7 @@ bot.registerCommand('unblock', (msg, args) => {
|
||||||
|
|
||||||
bot.registerCommand('logs', (msg, args) => {
|
bot.registerCommand('logs', (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
function getLogs(userId) {
|
function getLogs(userId) {
|
||||||
|
@ -425,7 +425,7 @@ bot.registerCommand('logs', (msg, args) => {
|
||||||
// Snippets
|
// Snippets
|
||||||
bot.on('messageCreate', async msg => {
|
bot.on('messageCreate', async msg => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
if (msg.author.bot) return;
|
if (msg.author.bot) return;
|
||||||
if (! msg.content) return;
|
if (! msg.content) return;
|
||||||
|
@ -441,7 +441,7 @@ bot.on('messageCreate', async msg => {
|
||||||
// Show or add a snippet
|
// Show or add a snippet
|
||||||
bot.registerCommand('snippet', async (msg, args) => {
|
bot.registerCommand('snippet', async (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
const shortcut = args[0];
|
const shortcut = args[0];
|
||||||
|
@ -474,7 +474,7 @@ bot.registerCommandAlias('s', 'snippet');
|
||||||
|
|
||||||
bot.registerCommand('delete_snippet', async (msg, args) => {
|
bot.registerCommand('delete_snippet', async (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
const shortcut = args[0];
|
const shortcut = args[0];
|
||||||
|
@ -493,7 +493,7 @@ bot.registerCommandAlias('ds', 'delete_snippet');
|
||||||
|
|
||||||
bot.registerCommand('edit_snippet', async (msg, args) => {
|
bot.registerCommand('edit_snippet', async (msg, args) => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
const shortcut = args[0];
|
const shortcut = args[0];
|
||||||
|
@ -517,7 +517,7 @@ bot.registerCommandAlias('es', 'edit_snippet');
|
||||||
|
|
||||||
bot.registerCommand('snippets', async msg => {
|
bot.registerCommand('snippets', async msg => {
|
||||||
if (! msg.channel.guild) return;
|
if (! msg.channel.guild) return;
|
||||||
if (msg.channel.guild.id !== utils.getModmailGuild(bot).id) return;
|
if (msg.channel.guild.id !== utils.getInboxGuild(bot).id) return;
|
||||||
if (! isStaff(msg.member)) return;
|
if (! isStaff(msg.member)) return;
|
||||||
|
|
||||||
const allSnippets = await snippets.all();
|
const allSnippets = await snippets.all();
|
||||||
|
|
|
@ -85,7 +85,7 @@ function getForUser(bot, user, allowCreate = true, originalMessage = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[NOTE] Creating new thread channel ${channelName}`);
|
console.log(`[NOTE] Creating new thread channel ${channelName}`);
|
||||||
return utils.getModmailGuild(bot).createChannel(`${channelName}`)
|
return utils.getInboxGuild(bot).createChannel(`${channelName}`)
|
||||||
.then(channel => {
|
.then(channel => {
|
||||||
const thread = {
|
const thread = {
|
||||||
channelId: channel.id,
|
channelId: channel.id,
|
||||||
|
|
26
src/utils.js
26
src/utils.js
|
@ -4,12 +4,13 @@ const publicIp = require('public-ip');
|
||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
let modMailGuild = null;
|
let inboxGuild = null;
|
||||||
let mainGuild = null;
|
let mainGuild = null;
|
||||||
|
let logChannel = null;
|
||||||
|
|
||||||
function getModmailGuild(bot) {
|
function getInboxGuild(bot) {
|
||||||
if (! modMailGuild) modMailGuild = bot.guilds.find(g => g.id === config.mailGuildId);
|
if (! inboxGuild) inboxGuild = bot.guilds.find(g => g.id === config.mailGuildId);
|
||||||
return modMailGuild;
|
return inboxGuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMainGuild(bot) {
|
function getMainGuild(bot) {
|
||||||
|
@ -17,6 +18,20 @@ function getMainGuild(bot) {
|
||||||
return mainGuild;
|
return mainGuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLogChannel(bot) {
|
||||||
|
const inboxGuild = getInboxGuild(bot);
|
||||||
|
|
||||||
|
if (! config.logChannelId) {
|
||||||
|
return inboxGuild.channels.get(inboxGuild.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! logChannel) {
|
||||||
|
logChannel = inboxGuild.channels.get(config.logChannelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return logChannel;
|
||||||
|
}
|
||||||
|
|
||||||
const userMentionRegex = /^<@\!?([0-9]+?)>$/;
|
const userMentionRegex = /^<@\!?([0-9]+?)>$/;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,8 +115,9 @@ function chunk(items, chunkSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getModmailGuild,
|
getInboxGuild,
|
||||||
getMainGuild,
|
getMainGuild,
|
||||||
|
getLogChannel,
|
||||||
getUserMention,
|
getUserMention,
|
||||||
getTimestamp,
|
getTimestamp,
|
||||||
disableLinkPreviews,
|
disableLinkPreviews,
|
||||||
|
|
Loading…
Reference in New Issue