Add afterThreadClose plugin hook
parent
9be6b2aa1f
commit
f5b6e46040
|
@ -7,6 +7,7 @@ const utils = require("../utils");
|
||||||
const config = require("../cfg");
|
const config = require("../cfg");
|
||||||
const attachments = require("./attachments");
|
const attachments = require("./attachments");
|
||||||
const { formatters } = require("../formatters");
|
const { formatters } = require("../formatters");
|
||||||
|
const { callAfterThreadCloseHooks } = require("../hooks/afterThreadClose");
|
||||||
|
|
||||||
const ThreadMessage = require("./ThreadMessage");
|
const ThreadMessage = require("./ThreadMessage");
|
||||||
|
|
||||||
|
@ -517,6 +518,8 @@ class Thread {
|
||||||
console.log(`Deleting channel ${this.channel_id}`);
|
console.log(`Deleting channel ${this.channel_id}`);
|
||||||
await channel.delete("Thread closed");
|
await channel.delete("Thread closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await callAfterThreadCloseHooks({ threadId: this.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
const Eris = require("eris");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef AfterThreadCloseHookData
|
||||||
|
* @property {string} threadId
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback AfterThreadCloseHookFn
|
||||||
|
* @param {AfterThreadCloseHookData} data
|
||||||
|
* @return {void|Promise<void>}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback AddAfterThreadCloseHookFn
|
||||||
|
* @param {AfterThreadCloseHookFn} fn
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type AfterThreadCloseHookFn[]
|
||||||
|
*/
|
||||||
|
const afterThreadCloseHooks = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {AddAfterThreadCloseHookFn}
|
||||||
|
*/
|
||||||
|
let afterThreadClose; // Workaround to inconsistent IDE bug with @type and anonymous functions
|
||||||
|
afterThreadClose = (fn) => {
|
||||||
|
afterThreadCloseHooks.push(fn);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AfterThreadCloseHookData} input
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
|
async function callAfterThreadCloseHooks(input) {
|
||||||
|
for (const hook of afterThreadCloseHooks) {
|
||||||
|
await hook(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
afterThreadClose,
|
||||||
|
callAfterThreadCloseHooks,
|
||||||
|
};
|
|
@ -31,4 +31,5 @@ const Knex = require("knex");
|
||||||
/**
|
/**
|
||||||
* @typedef {object} PluginHooksAPI
|
* @typedef {object} PluginHooksAPI
|
||||||
* @property {AddBeforeNewThreadHookFn} beforeNewThread
|
* @property {AddBeforeNewThreadHookFn} beforeNewThread
|
||||||
|
* @property {AddAfterThreadCloseHookFn} afterThreadClose
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const attachments = require("./data/attachments");
|
const attachments = require("./data/attachments");
|
||||||
const { beforeNewThread } = require("./hooks/beforeNewThread");
|
const { beforeNewThread } = require("./hooks/beforeNewThread");
|
||||||
|
const { afterThreadClose } = require("./hooks/afterThreadClose");
|
||||||
const formats = require("./formatters");
|
const formats = require("./formatters");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -28,6 +29,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
hooks: {
|
hooks: {
|
||||||
beforeNewThread,
|
beforeNewThread,
|
||||||
|
afterThreadClose,
|
||||||
},
|
},
|
||||||
formats,
|
formats,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue