Add !newthread
parent
4fd0929106
commit
4305609f0b
|
@ -40,10 +40,11 @@ async function findOpenThreadByUserId(userId) {
|
|||
/**
|
||||
* Creates a new modmail thread for the specified user
|
||||
* @param {Eris.User} user
|
||||
* @param {Boolean} quiet If true, doesn't ping mentionRole or reply with responseMessage
|
||||
* @returns {Promise<Thread>}
|
||||
* @throws {Error}
|
||||
*/
|
||||
async function createNewThreadForUser(user) {
|
||||
async function createNewThreadForUser(user, quiet = false) {
|
||||
const existingThread = await findOpenThreadByUserId(user.id);
|
||||
if (existingThread) {
|
||||
throw new Error('Attempted to create a new thread for a user with an existing open thread!');
|
||||
|
@ -79,17 +80,19 @@ async function createNewThreadForUser(user) {
|
|||
|
||||
const newThread = await findById(newThreadId);
|
||||
|
||||
// Ping moderators of the new thread
|
||||
if (config.mentionRole) {
|
||||
await newThread.postNonLogMessage({
|
||||
content: `${utils.getInboxMention()}New modmail thread (${newThread.user_name})`,
|
||||
disableEveryone: false
|
||||
});
|
||||
}
|
||||
if (! quiet) {
|
||||
// Ping moderators of the new thread
|
||||
if (config.mentionRole) {
|
||||
await newThread.postNonLogMessage({
|
||||
content: `${utils.getInboxMention()}New modmail thread (${newThread.user_name})`,
|
||||
disableEveryone: false
|
||||
});
|
||||
}
|
||||
|
||||
// Send auto-reply to the user
|
||||
if (config.responseMessage) {
|
||||
newThread.postToUser(config.responseMessage);
|
||||
// Send auto-reply to the user
|
||||
if (config.responseMessage) {
|
||||
newThread.postToUser(config.responseMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// Post some info to the beginning of the new thread
|
||||
|
|
|
@ -18,6 +18,8 @@ const webserver = require('./modules/webserver');
|
|||
const greeting = require('./modules/greeting');
|
||||
const typingProxy = require('./modules/typingProxy');
|
||||
const version = require('./modules/version');
|
||||
const newthread = require('./modules/newthread');
|
||||
|
||||
const attachments = require("./data/attachments");
|
||||
const {ACCIDENTAL_THREAD_MESSAGES} = require('./data/constants');
|
||||
|
||||
|
@ -169,6 +171,7 @@ module.exports = {
|
|||
await webserver(bot);
|
||||
await typingProxy(bot);
|
||||
await version(bot);
|
||||
await newthread(bot);
|
||||
|
||||
// Connect to Discord
|
||||
console.log('Connecting to Discord...');
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
const utils = require("../utils");
|
||||
const threadUtils = require("../threadUtils");
|
||||
const threads = require("../data/threads");
|
||||
|
||||
module.exports = bot => {
|
||||
const addInboxServerCommand = (...args) => threadUtils.addInboxServerCommand(bot, ...args);
|
||||
|
||||
addInboxServerCommand('newthread', async (msg, args, thread) => {
|
||||
if (args.length === 0) return;
|
||||
|
||||
const userId = utils.getUserMention(args[0]);
|
||||
if (! userId) return;
|
||||
|
||||
const user = bot.users.get(userId);
|
||||
if (! user) {
|
||||
utils.postSystemMessageWithFallback(msg.channel, thread, 'User not found!');
|
||||
return;
|
||||
}
|
||||
|
||||
const existingThread = await threads.findOpenThreadByUserId(user.id);
|
||||
if (existingThread) {
|
||||
utils.postSystemMessageWithFallback(msg.channel, thread, `Cannot create a new thread; there is another open thread with this user: <#${existingThread.channel_id}>`);
|
||||
return;
|
||||
}
|
||||
|
||||
const createdThread = await threads.createNewThreadForUser(user, true);
|
||||
createdThread.postSystemMessage(`Thread was opened by ${msg.author.username}#${msg.author.discriminator}`);
|
||||
|
||||
if (thread) {
|
||||
msg.delete();
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue