Expose web server express application to plugins

cshd
Dragory 2020-10-04 02:10:13 +03:00
parent e99352e2ac
commit 9048942ce9
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
5 changed files with 18 additions and 10 deletions

View File

@ -66,6 +66,7 @@ The first and only argument to the plugin function is an object with the followi
| `logs` | An object with functions to get attachment URLs/files and manage log storage types | | `logs` | An object with functions to get attachment URLs/files and manage log storage types |
| `hooks` | An object with functions to add *hooks* that are called at specific times, e.g. before a new thread is created | | `hooks` | An object with functions to add *hooks* that are called at specific times, e.g. before a new thread is created |
| `formats` | An object with functions that allow you to replace the default functions used for formatting messages and logs | | `formats` | An object with functions that allow you to replace the default functions used for formatting messages and logs |
| `webserver` | An [Express Application object](https://expressjs.com/en/api.html#app) that functions as the bot's web server |
See the auto-generated [Plugin API](plugin-api.md) page for details. See the auto-generated [Plugin API](plugin-api.md) page for details.

View File

@ -21,7 +21,7 @@ const logs = require("./modules/logs");
const move = require("./modules/move"); const move = require("./modules/move");
const block = require("./modules/block"); const block = require("./modules/block");
const suspend = require("./modules/suspend"); const suspend = require("./modules/suspend");
const webserver = require("./modules/webserver"); const { plugin: webserver } = require("./modules/webserver");
const greeting = require("./modules/greeting"); const greeting = require("./modules/greeting");
const typingProxy = require("./modules/typingProxy"); const typingProxy = require("./modules/typingProxy");
const version = require("./modules/version"); const version = require("./modules/version");

View File

@ -54,7 +54,6 @@ function serveAttachments(req, res) {
}) })
} }
module.exports = () => {
const server = express(); const server = express();
server.use(helmet()); server.use(helmet());
@ -65,5 +64,9 @@ module.exports = () => {
console.log("[WARN] Web server error:", err.message); console.log("[WARN] Web server error:", err.message);
}); });
module.exports = {
server,
plugin() {
server.listen(config.port); server.listen(config.port);
},
}; };

View File

@ -1,3 +1,4 @@
const express = require("express");
const { CommandManager } = require("knub-command-manager"); const { CommandManager } = require("knub-command-manager");
const { Client } = require("eris"); const { Client } = require("eris");
const Knex = require("knex"); const Knex = require("knex");
@ -12,6 +13,7 @@ const Knex = require("knex");
* @property {PluginLogsAPI} logs * @property {PluginLogsAPI} logs
* @property {PluginHooksAPI} hooks * @property {PluginHooksAPI} hooks
* @property {FormattersExport} formats * @property {FormattersExport} formats
* @property {express.Application} webserver
*/ */
/** /**

View File

@ -3,6 +3,7 @@ const logs = require("./data/logs");
const { beforeNewThread } = require("./hooks/beforeNewThread"); const { beforeNewThread } = require("./hooks/beforeNewThread");
const { afterThreadClose } = require("./hooks/afterThreadClose"); const { afterThreadClose } = require("./hooks/afterThreadClose");
const formats = require("./formatters"); const formats = require("./formatters");
const { server: webserver } = require("./modules/webserver");
module.exports = { module.exports = {
/** /**
@ -40,6 +41,7 @@ module.exports = {
afterThreadClose, afterThreadClose,
}, },
formats, formats,
webserver,
}; };
}, },