Lexa307 / DiscordCardBot

Bot that can give a collectible card for server member every day
MIT License
8 stars 2 forks source link
cards collection discord discord-bot discord-js discordjs nodejs

DiscordCardBot

A simple bot that allows you to collect cards by server participants. Project Setup ru-README

Description

Commands available to discord server participants:

When adding a user mention as an argument (via @), the inventory of the specified user will be shown (provided that the admin has enabled this feature in the config: INVENTORY_PUBLIC_ACCESS = 1 )

The inventory has a page interface, where the pages are changed by adding the reactions of arrows ( ⬅️ and ➡️ ) that the bot offers, the pages change only if the response under the message with the inventory was left by the author of the sent command. After some time (which is configured in the config: INVENTORY_TIME), when the inventory is inactive, there is no active page switching, the inventory stops working, and in order to view it again, you need to enter the necessary command again.

profile [@UserMention]

Shows the profile of the specified user or the author of the message with statistics of the collected cards for all time.

help

Displays a list of all commands available to the author of the message. If the server administrator has requested help, the bot will display an expanded list of commands.

undiscovered

Displays the number of cards that none of the registered participants have.

giveacard @UserMention CardName

Gives the specified user a card found by the entered name (or part of the name).

The command can be used only by the server administrator. To use this function, you need 2 required arguments:

activate Code

Activation of the code created by the administrator, upon successful activation by the user, resets his cooldown for using the drop command

createcode [-c] [-u] [-d]

Creates a special code that users can activate to be able to reset the cooldown of the drop command This command can only be used by the administrator, while 3 optional parameters are available to him for use, which can be used in any order to set restrictions on the use of the code:

By default, an automatically generated code is created with no expiration date for 1 use.

deletecard CardName

The admin command that removes the specified card from the system and from all users.

This command requires 1 mandatory argument - the full name of the card.

If there is a space in the name of the card, then use ";" instead, because the space is used to separate arguments.

addcard CardName ClassNumber [ImageSourceLink]

The server admin can create a new card that is automatically placed in the card drop pool. Command arguments:

editcard CardName editCardName editClassNumber [editImageSourceLink]

A command accessible only to the administrator, created to change the data of existing maps, requires the following arguments:

resetdrop [@UserMention]

Resets the cooldown of the drop command for all users or only the specified one. (Available only to the administrator)

News

a small update from 09.25.2022

feature from 06.10.2021

feature from 09.26.2021

feature from 11.06.2021

Project Setup

  1. Clone the project.

  2. Make sure that you have installed:

    • Node.js 10.0.0 or higher.
  3. Create a configuration file and enter the necessary information into it.

Creating a config

In the root of the project, create a configuration file .env Example of the .env file :

TOKEN = "your bot token"
PREFIX = '!' 
PAGE_SIZE = 7
INVENTORY_TIME = 60000
INVENTORY_PUBLIC_ACCESS = 1
RARE_CLASS_NUMBER = 5
CLASS_SYMBOL_FILL = ":star:"
CLASS_SYMBOL_OF_VOID = ":small_orange_diamond:"
RESET_LOCAL_TIME = ""
SPACE_SYMBOL = "__"
LOCALES = "en"

PAGE_SIZE - the number of items that will fit on one inventory page when displayed

INVENTORY_TIME - the idle time of the inventory, after which the bot stops flipping pages, is indicated in milliseconds

INVENTORY_PUBLIC_ACCESS - access to another user's inventory 1 - you can use show @UserMention, 0 - other users can only show their inventory themselves in the chat

RESET_LOCAL_TIME - the local time of the server during which the timer is reset for drop to all users at the same time. Field value format: "hh:mm:ss", for example RESET_LOCAL_TIME = "16:45:00". If "" - then when using drop, the bot will set the reset time for each user individually.

LOCALES - setting up the localization of the bot en - English, ru - Russian

SPACE_SYMBOL - Symbol(s) should use instead of SPACE in commands, because ' ' by default is using for splitting arguments

RARE_CLASS_NUMBER - number of rarity/value classes

CLASS_SYMBOL_FILL - Discord emoji to fill in the rarity/value scale

CLASS_SYMBOL_OF_VOID - Discord emoji to fill the void of the rarity/value scale

The illustration below is to understand the essence of the last 3 parameters:

  1. Add the necessary content for your server.

Content preparation

Open /storage/db.json

{
    "users": [], // Contains data of server participants and their inventory 
    "cards": [], // Contains data about cards that may fall out on the server
    "codes": [], // Contains information about event codes for users
}

Data about server users will be automatically added as the bot commands are used. You can fill in the card data by yourself. Example of adding a map to db.json

cards: [
    {
        "name": "test_card", // Name of the card
        "class": 1, // the value of the card is determined from 1 to RARE_CLASS_NUMBER inclusive
        "active": true, // Flag that determines whether the card can fall to the server participants
        "url": "url_string.png"  // Link to the card image
    }, 
]

If you have only cloned the project, then you may find that in db.json already has information about test cards with a rarity from 1 to 6 where cards with class from 1 to 5 are standard and the one with class 6 is non-standard (Which means its value will not be displayed using CLASS_SYMBOL_FILL and CLASS_SYMBOL_OF_VOID, keep this in mind, if you want to somehow mark its value with symbols/emojis, you can write them in the card name field, as in db.json of the repository).

  1. Download the necessary modules for the project to work.

Download dependencies

Open the terminal in the root of the project, then write the following commands:

npm i 
  1. After all the steps have been successfully completed, you can start the bot by writing a command in the terminal.

    Project launch

    npm start