npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mephisto5558/bot-website

v1.7.2

Published

The website for my Discord Bot.

Downloads

628

Readme

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

Discord Server

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: '[email protected]',
    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.