Add !alert
Using !alert in a modmail thread will ping you the next time the thread gets a new reply. Use !alert cancel to cancel.master
parent
93e856aa18
commit
5e1b5112a2
|
@ -0,0 +1,11 @@
|
|||
exports.up = async function (knex, Promise) {
|
||||
await knex.schema.table('threads', table => {
|
||||
table.string('alert_id', 20).nullable().defaultTo(null).after('scheduled_close_name');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = async function(knex, Promise) {
|
||||
await knex.schema.table('threads', table => {
|
||||
table.dropColumn('alert_id');
|
||||
});
|
||||
};
|
|
@ -19,6 +19,7 @@ const {THREAD_MESSAGE_TYPE, THREAD_STATUS} = require('./constants');
|
|||
* @property {String} scheduled_close_at
|
||||
* @property {String} scheduled_close_id
|
||||
* @property {String} scheduled_close_name
|
||||
* @property {String} alert_id
|
||||
* @property {String} created_at
|
||||
*/
|
||||
class Thread {
|
||||
|
@ -145,10 +146,12 @@ class Thread {
|
|||
|
||||
if (this.scheduled_close_at) {
|
||||
await this.cancelScheduledClose();
|
||||
await this.postSystemMessage({
|
||||
content: `<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`,
|
||||
disableEveryone: false
|
||||
});
|
||||
await this.postSystemMessage(`<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`);
|
||||
}
|
||||
|
||||
if (this.alert_id) {
|
||||
await this.setAlert(null);
|
||||
await this.postSystemMessage(`<@!${this.alert_id}> New message from ${this.user_name}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,6 +371,18 @@ class Thread {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} userId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async setAlert(userId) {
|
||||
await knex('threads')
|
||||
.where('id', this.id)
|
||||
.update({
|
||||
alert_id: userId
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<String>}
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,7 @@ const typingProxy = require('./modules/typingProxy');
|
|||
const version = require('./modules/version');
|
||||
const newthread = require('./modules/newthread');
|
||||
const idModule = require('./modules/id');
|
||||
const alert = require('./modules/alert');
|
||||
|
||||
const attachments = require("./data/attachments");
|
||||
const {ACCIDENTAL_THREAD_MESSAGES} = require('./data/constants');
|
||||
|
@ -183,6 +184,7 @@ module.exports = {
|
|||
await version(bot);
|
||||
await newthread(bot);
|
||||
await idModule(bot);
|
||||
await alert(bot);
|
||||
|
||||
// Connect to Discord
|
||||
console.log('Connecting to Discord...');
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
const threadUtils = require('../threadUtils');
|
||||
|
||||
module.exports = bot => {
|
||||
const addInboxServerCommand = (...args) => threadUtils.addInboxServerCommand(bot, ...args);
|
||||
|
||||
addInboxServerCommand('alert', async (msg, args, thread) => {
|
||||
if (! thread) return;
|
||||
|
||||
if (args[0] && args[0].startsWith('c')) {
|
||||
await thread.setAlert(null);
|
||||
await thread.postSystemMessage(`Cancelled new message alert`);
|
||||
} else {
|
||||
await thread.setAlert(msg.author.id);
|
||||
await thread.postSystemMessage(`Pinging ${msg.author.username}#${msg.author.discriminator} when this thread gets a new reply`);
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue