1.5.2 • Published 14 days ago

@mephisto5558/bot-website v1.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
14 days ago

Bot-Website

Activity License Lines of Code wakatime npm version npm downloads CodeQL Quality Gate Status Security Rating Maintainability Rating Reliability Rating Duplicated Lines (%) Bugs Vulnerabilities Code Smells Technical Debt

A website & dashboard for my discord bot with an easy way of adding new dashboard settings & pages.

Note that this library currently uses a deprecated (but working) library for its dashboard.

Requirements

Installation

To install the library, run the following command:

npm install @mephisto5558/bot-website

Usage

Import the module

First, you need to import the WebServer module into your JavaScript file:

const { WebServer } = require('@mephisto5558/bot-website');
// or
import { WebServer } from '@mephisto5558/bot-website'

After installing and importing the library, you can initialize the web server with the following code snippet:

const client = /* Your discord.js client instance */;
const db = /* Your database (@mephisto5558/mongoose-db) instance */;
const keys = {
 secret: /* Your Discord application secret */,
 dbdLicense: /* Your discord-dashboard license */,
 webhookURL: /* Your webhook URL for the voting system. This is optional. */
};

const webServer = new WebServer(client, db, keys);
await webServer.init();
console.log('Website is online.');

Configuration

The WebServer class accepts a configuration object that allows you to customize various aspects of the web server, including:

  • support: An object containing contact information for support.
  • port: The port on which the web server will listen.
  • domain: The domain name or IP address of the web server.
  • errorPagesDir: The directory containing custom error pages.
  • settingsPath: The path to the directory containing the settings for the dashboard. More info here
  • customPagesPath: The path to the directory containing custom pages for the website. More info here

Here's an example of how to configure the web server:

const webServer = new WebServer(client, db, keys, {
 support: {
    mail: 'support@example.com',
    discord: 'https://discord.gg/yourserver'
 },
 port: 8000,
 domain: 'https://example.com',
 errorPagesDir: './error-pages',
 settingsPath: './settings',
 customPagesPath: './custom-pages'
});

Settings parameter

For your convenience, you don't need to provide the settings as an object, instead you just need to create the correct files and provide the path to your settings when initializing the class.

The settings follow the following structure:

  • category 1
    • _index.json
    • setting_1.js
    • setting_2.js
  • category 2
    • ...

The _index.json has the following properties:

  • id: category id, settings are saved to the db under this id
  • name: the categorie's display name
  • description: the description for users
  • position: display position on the website, starting at 0

The settings.js have the following properties exported:

  • id: setting id, saved to the db under that id
  • name: display name
  • description: description for users
  • type:
    • the form type's name
    • the form type itself
    • a function returning the form type (can be a promise)
  • position: display position on the website, starting at 0

Custom pages

Custom pages have nothing todo with the dashboard and are handled separately.

For your convenience, you don't need to provide the pages as an object, instead you just need to create the correct files and provide the path to your custom pages when initializing the class.

Every folder in the custom pages folder is a part of the URL. For example, if you have file path project/customSites/api/v1/user.js with customSites set as the custom sites directory, the URL would look like this: https://example.com/api/v1/user

The pages can either be html files or anything that can be loaded by node.js require().


If the file is empty, it will be ignored. If it is a json or javascript file, it can have the following properties:

  • method: The allowed request method, (GET, POST, etc.) can be a string or an array or strings. Defaults to GET.
  • permissionCheck (JS files only): a function that should return false if the user should not access the page.
  • title: The page title, shown in the browser tab
  • static: A boolean if the data is static.
  • run: Any kind of data. gets called with the WebServer as this, response and request and the express.js next function. If it's not a function, gets turned into json. If run does not exist, will instead send the full file as json.

Other infos

Sessions

Currently, only one session per user is allowed, meaning if the user logs in from another browser/device, the old session will be deleted.

Favicon

A favicon can be set by creating a custom page called favicon.ico.js that redirects to an image url.

For example, if you want your discord client's avatar as favicon:

// favicon.ico.js
module.exports = {
  run: function (res) { return res.redirect(this.client.user.displayAvatarURL()); }
};

If you have any other questions or suggestions, please create an issue.

1.5.2

14 days ago

1.5.1

26 days ago

1.5.0

26 days ago

1.4.3-0

27 days ago

1.4.2

2 months ago

1.4.1

2 months ago

1.4.0

2 months ago

1.3.3

3 months ago

1.3.2

3 months ago

1.2.0

3 months ago

1.3.1

3 months ago

1.2.2

3 months ago

1.3.0

3 months ago

1.2.1

3 months ago

1.1.4

3 months ago

1.1.3

3 months ago

1.1.2

3 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago