Code Monkey home page Code Monkey logo

pk-help-bot's Introduction

PK-Help-Bot

A Node.js discord bot that matches messages to regex. Made to try help people if staff aren't around.

There are a few commands for ops built in, but nothing too fancy. Things like

  • !reload - reloads the config and the regex expressions
  • !bar @user - Prevents the bot from responding to that user. Can be used when people abuse the bot.
  • !unbar @user - Unbars the user.
  • !ping - See the latency of the bot

The bot also has a /core/modules and /core/commands folder that are loaded dynamically. They allow for easy additions for the bot.

Installation

This bot is built on Node.js, so you must have that installed along with npm.

  1. npm install
  2. npm install discord.js

You can then run the bot with node bot.js

Configuration

Main configuration

The main config file can be found at /config/config.json. It stores things such as blocked users, the command prefix, ignored channels, as well as 'roles' that are used in code.

The token for the bot should be placed in /config/token.txt

The bot has an optional MOTD on startup. This can be found in /config/motd.txt. Because being fancy is great!

Regex Responses

Regex responses are in JSON. They are composed of three components.

Triggers. What triggers the response. This is optional, and ones without triggers can be directed to through other responses via buttons. The trigger should be in regex format.

Response. What it should respond with. You can also use responses and provide an array of json objects. These objects will allow you to test the capture groups of the regex before replying with the corresponding response.

Buttons. These are buttons added to the response. If a URL is provided, it will direct users to that URL. But you can also direct users to another regex response file. This allows you to create chains of prompts for users to go through.

First Example

Features a response to a naturally worded question, as well as a manuall command trigger. It has a button leading to a URL as well as a button that leads to talking about a specific server host's limitations.

{
    "triggers": [
        "^\\.addons",
        "(((how|where).+(can i|do (you|i)).+(put|get|install|down ?load).+(addons|(custom|new).+abilit(y|ies))))"
    ],
    "response": "You can download addon abilties from the forums and then put them in your `/plugins/ProjectKorra/Abilities` directory. Click the button bellow for a link.\n\nSide plugins ALWAYS go into the `/plugins/` folder, and ability packs _generally_ go into the plugins folder. So read the installation guide on the resource page before installing. This includes things like JedCore, ProjectAddons, Hyperion, Spirits, BendingGUI, etc.",
    "buttons": [
        "Custom Abilities Category",
        "https://projectkorra.com/forum/resources/categories/custom-abilities.3/",
        "I'm on Aternos",
        "aternos.json"
    ]
}

Second Example

When someone asks if ProjectKorra is compatible with X version, this responds according to what version they ask about.

{
    "triggers": [
        "(?:does|is|can someone tell).+(?:pk|projectkorra|(?:this|the) plug(?: |-)?in).+(?:work|run|available|compatible).+(?:on|with|for).+(1\\.\\d{0,2}(?:\\.\\d)?(?:[?!.]{1,5}|$)"
    ],
    "responses": [
        {
            "condition": {
                "variable": "$1",
                "type": "equals",
                "values": [
                    "1.16",
                    "1.17",
                    "1.18",
                    "1.19"
                ]
            },
            "content": "Yes, ProjectKorra is compatible with Spigot/MC $1! The latest version works on 1.16 all the way through to 1.19.3!"
        },
        {
            "condition": {
                "variable": "$1",
                "type": "notequals",
                "values": [
                    "1.16",
                    "1.17",
                    "1.18",
                    "1.19",
                ]
            },
            "content": "The latest version of ProjectKorra only works between Spigot/MC 1.16 to 1.19.3. If you want to use an older version of Minecraft, you'll need to use an older version of PK.\n\nCheck the pins in support to see the versions compatible with what you want."
        }
    ]
}

pk-help-bot's People

Contributors

dependabot[bot] avatar geniusjam avatar strangeone101 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

geniusjam

pk-help-bot's Issues

Messages sent from the bot are checked for matching regex expressions

Issue

Replies that the bot sends out to users are also checked against the regex expressions used to help people. This can cause the bot to spam the same response if the response itself matches the regex query.

Solution

Make the bot not check regex queries if the message was sent from the bot

Stacktrace Reader

Description

A module that reads stacktraces people post and replies with basic information about the stacktrace for fellow helpers or the user themselves to read

It can read:

  • Uploaded *.log files
  • Logs posted in code blocks

It should be able to identify things such as:

  • If the java version is incorrect/Version major.minor mismatch errors (along with what version of java is required
  • Identify what plugin triggered the exception
  • If it is ProjectKorra, check if it's an addon based on the classpaths
  • Identify "plugin.yml" not found. Suggest that if that is an addon, put it in the abilities folder instead

Additional things it should do:

  • Reply as an embed with as much information as possible
  • Ignore java/sun/apache commons classpaths as they are unlikely to be the real issue
  • Identify the classpaths most likely the cause. Even if it isn't the topmost one
  • Recommend a course of action, including contacting the author (using the classpaths to guess the author)

This should be added as a module to the modules directory

Remove legacy stuff

Description

A lot of legacy stuff is in the bot that should be removed. This consists of

  • The pastebin regex parser
  • Quiet/Loud channels

The pastebin regex parser should have all the pastebin regex responses converted to the new JSON equivalent. And all outdated responses should be removed (all pre 1.13 stuff).

Additionally, the config should be stripped of all references to these things as they are no longer needed.

"Has Role" feature in the API/Config

Description

The config needs a new section where roles can be defined by plain text, and these can then be checked in code later on. For example, in the config, we might have:

"Roles": {
    "staff": [
        "414878520028954630",
        "300692373254569984"
    ]
}

Then in the code for a command we might have

if (!API.hasRole(member, "staff")) {
    message.reply("You don't have permission to run this command!");
    return;
}

Create some form of updater for the config

Description

An !update command that will fetch the latest configuration files from GitHub and download them.

This will exclude the config.json file as that is the one file that should not be updated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.