Add thread suspending
parent
11c4bc12da
commit
b8a5021dd5
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
## v2.4.0
|
||||
* Add thread suspending. A modmail thread can now be suspended with `!suspend`. Suspended threads will function as closed until unsuspended with `!unsuspend`.
|
||||
|
||||
## v2.3.2
|
||||
* Auto-close threads if their modmail channel is deleted
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ See [CHANGELOG.md](CHANGELOG.md)
|
|||
`!!shortcut` Reply with a snippet. Replace `shortcut` with the snippet's actual shortcut.
|
||||
`!move <category>` If `allowMove` is enabled, moves the thread channel to the specified category
|
||||
`!loglink` Shows the link to the current thread's log
|
||||
`!suspend` Suspend a thread. The thread will act as closed and not receive any messages until unsuspended.
|
||||
`!unsuspend` Unsuspend a thread
|
||||
|
||||
To automatically reply without using !reply or !r, enable `alwaysReply` in the config. `alwaysReplyAnon` sets whether to reply anonymously. If you do not wish to reply, it will ignore any message starting in the prefix (which defaults to !), such as !note
|
||||
|
||||
|
|
|
@ -307,6 +307,11 @@ class Thread {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} time
|
||||
* @param {Eris~User} user
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async scheduleClose(time, user) {
|
||||
await knex('threads')
|
||||
.where('id', this.id)
|
||||
|
@ -317,6 +322,9 @@ class Thread {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async cancelScheduledClose() {
|
||||
await knex('threads')
|
||||
.where('id', this.id)
|
||||
|
@ -327,6 +335,28 @@ class Thread {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async suspend() {
|
||||
await knex('threads')
|
||||
.where('id', this.id)
|
||||
.update({
|
||||
status: THREAD_STATUS.SUSPENDED
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async unsuspend() {
|
||||
await knex('threads')
|
||||
.where('id', this.id)
|
||||
.update({
|
||||
status: THREAD_STATUS.OPEN
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<String>}
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = {
|
||||
THREAD_STATUS: {
|
||||
OPEN: 1,
|
||||
CLOSED: 2
|
||||
CLOSED: 2,
|
||||
SUSPENDED: 3
|
||||
},
|
||||
|
||||
THREAD_MESSAGE_TYPE: {
|
||||
|
|
|
@ -154,6 +154,19 @@ async function findOpenThreadByChannelId(channelId) {
|
|||
return (thread ? new Thread(thread) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} channelId
|
||||
* @returns {Promise<Thread>}
|
||||
*/
|
||||
async function findSuspendedThreadByChannelId(channelId) {
|
||||
const thread = await knex('threads')
|
||||
.where('channel_id', channelId)
|
||||
.where('status', THREAD_STATUS.SUSPENDED)
|
||||
.first();
|
||||
|
||||
return (thread ? new Thread(thread) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} userId
|
||||
* @returns {Promise<Thread[]>}
|
||||
|
@ -203,6 +216,7 @@ module.exports = {
|
|||
findOpenThreadByUserId,
|
||||
findByChannelId,
|
||||
findOpenThreadByChannelId,
|
||||
findSuspendedThreadByChannelId,
|
||||
createNewThreadForUser,
|
||||
getClosedThreadsByUserId,
|
||||
findOrCreateThreadForUser,
|
||||
|
|
20
src/main.js
20
src/main.js
|
@ -414,6 +414,26 @@ addInboxServerCommand('loglink', async (msg, args, thread) => {
|
|||
thread.postNonLogMessage(`Log URL: ${logUrl}`);
|
||||
});
|
||||
|
||||
addInboxServerCommand('suspend', async (msg, args, thread) => {
|
||||
if (! thread) return;
|
||||
await thread.suspend();
|
||||
thread.postSystemMessage(`**Thread suspended!** This thread will act as closed until unsuspended with \`!unsuspend\``);
|
||||
});
|
||||
|
||||
addInboxServerCommand('unsuspend', async (msg, args) => {
|
||||
const thread = await threads.findSuspendedThreadByChannelId(msg.channel.id);
|
||||
if (! thread) return;
|
||||
|
||||
const otherOpenThread = await threads.findOpenThreadByUserId(thread.user_id);
|
||||
if (otherOpenThread) {
|
||||
thread.postSystemMessage(`Cannot unsuspend; there is another open thread with this user: <#${otherOpenThread.channel_id}>`);
|
||||
return;
|
||||
}
|
||||
|
||||
await thread.unsuspend();
|
||||
thread.postSystemMessage(`**Thread unsuspended!**`);
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
async start() {
|
||||
// Load plugins
|
||||
|
|
|
@ -14,7 +14,7 @@ function addInboxServerCommand(bot, cmd, commandHandler, opts) {
|
|||
if (! utils.messageIsOnInboxServer(msg)) return;
|
||||
if (! utils.isStaff(msg.member)) return;
|
||||
|
||||
const thread = await threads.findByChannelId(msg.channel.id);
|
||||
const thread = await threads.findOpenThreadByChannelId(msg.channel.id);
|
||||
commandHandler(msg, args, thread);
|
||||
}, opts);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue