Coder Social home page Coder Social logo

wodcz / utility-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nestjs-discord/utility-bot

0.0 0.0 0.0 203 KB

A Discord bot designed to streamline the support process on the official NestJS Discord server

Home Page: https://discord.gg/nestjs

License: MIT License

Go 98.10% Dockerfile 1.90%

utility-bot's Introduction

Utility Bot

build-and-test CodeFactor Go Report Card

A Discord bot designed to streamline the support process on the official NestJS Discord server.

As people who usually answer questions on the official NestJS Discord server, we've experienced that sometimes users ask questions that have already been answered many times before.

There are some common cases, like when they post a new support request, they don't provide a minimal reproduction code, or sometimes they don't even share their code, and even if they do, they don't know how to put them in code blocks properly.

So we devised the idea of having a Discord bot with predefined and well-written Markdown content as slash commands to reply to users instead of repeatedly writing and explaining.

Configuration

cp .env.example .env

Three DISCORD_APP_ID, DISCORD_BOT_TOKEN, and DISCORD_GUILD_ID environment variables are required, and rest of the configuration is located in config.yml.

Currently, the bot doesn't support hot-reloading. Instead, the application should restart to apply the changes.

Build

To build this project, you must install Golang in your system and execute the following command.

go build -trimpath -buildvcs=false -ldflags "-w" -o ./bin/utility-bot ./main.go

Adding the bot to the server

Please add the bot to the server using the invite link generated by the discord:invite CLI command, as the permissions within the link will likely change based on the features we may add.

Docker usage

docker compose --env-file ./.env up -d --build

# Generates an invite link to add the bot to servers
docker compose exec utility-bot ./utility-bot discord:invite

# Graceful shutdown
# docker compose down

# Removing the registered slash commands (in case of inconsistency between the configuration and the production)
# docker compose exec utility-bot ./utility-bot discord:clean

Notes

  • Slash commands
    • Once slash commands are registered, Discord will sort them alphabetically, regardless of their initial order in config.yml.
    • Once slash commands are registered or removed, they get updated instantly for the end-user because this project uses guild commands instead of global commands.
    • Discord has a global rate limit of 200 application command creations per day, per guild.
    • Bot will automatically register non-registered slash commands on bootstrap.
    • Registered slash commands can be removed by discord:clean command.
    • Only one sub-command level is supported; for example, foo bar is valid.
  • Markdown content
    • Content within the slash commands can have a maximum of 2000 characters.
    • The bot will cache Markdown content on memory to avoid spamming I/O.
  • Moderators
    • They can be defined by their unique Discord ID in config.yml.
    • They bypass rate-limit policies.
    • They can execute protected commands in config.yml.

Running tests

go test -v ./...

Dependencies overview

  • DiscordGo - Provides low level bindings to the Discord chat client API
  • Cobra - Commander for modern Go CLI interactions
  • Viper - Complete configuration solution for Go applications
  • Validator - Implements value validations for structs based on tags
  • Zerolog - Zero allocation JSON logger
  • Go-humanize - Formatters for units to human friendly sizes
  • Testify - A toolkit with common assertions and mocks
  • Prometheus Golang - Prometheus instrumentation library for Go apps

utility-bot's People

Contributors

erosdesire avatar dependabot[bot] avatar

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.