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,6 +80,7 @@ async function createNewThreadForUser(user) {
|
|||
|
||||
const newThread = await findById(newThreadId);
|
||||
|
||||
if (! quiet) {
|
||||
// Ping moderators of the new thread
|
||||
if (config.mentionRole) {
|
||||
await newThread.postNonLogMessage({
|
||||
|
@ -91,6 +93,7 @@ async function createNewThreadForUser(user) {
|
|||
if (config.responseMessage) {
|
||||
newThread.postToUser(config.responseMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// Post some info to the beginning of the new thread
|
||||
const mainGuild = utils.getMainGuild();
|
||||
|
|
|
@ -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