Coder Social home page Coder Social logo

tropicaldog17 / mochi-discord Goto Github PK

View Code? Open in Web Editor NEW

This project forked from consolelabs/mochi-discord

0.0 0.0 0.0 32.68 MB

License: GNU General Public License v3.0

Shell 0.16% JavaScript 0.17% TypeScript 99.56% Makefile 0.07% Dockerfile 0.04%

mochi-discord's Introduction

⚙️ Setup

If you're already familiar with the discord bot development workflow, skip right to step 8, otherwise follow these steps below:

  1. Go to the Discord Developer Portal and login (register an account if needed)
  2. On the top right corner, click New Application to create a new application
  3. On the left side menu, the General Information displays information about your application, notice the Application ID, you will need it later
  4. Navigate to Bot tab > Add Bot
  5. After adding you will see the Token for your bot, note it down, you will need it later
  6. At the Privileged Gateway Intents, enable all 3 options, bot permission is Administrator (8)
  7. To add the bot for local development, copy this link and replace the APPLICATION_ID in the url with your application id
  8. Enable dev mode in Discord, this basically lets you copy id of a bunch of things (channels, guilds, messages, etc...). To do it, navigate to Setting > Advanced > Developer Mode > Enable
  9. Finally, send your guild's id to one of the member of Console Labs (if you're developing locally but using the staging api endpoint)

This step is optional, if you can run the source, great. If not, it might be related to canvas native libraby because Mochi internally uses a canvas dependency to render response

  1. Install pkg needed for canvas if needed: brew install pkg-config cairo pango libpng jpeg giflib librsvg

♻️ Environment Variables

Show table
Required Name Description
DISCORD_TOKEN Without this the bot cannot run. To get one, refer to Setup
APPLICATION_ID Used to register slash commands on bot startup. To get one, refer to Setup
API_SERVER_HOST Base API endpoint for most of Mochi's command, for detail see API
INDEXER_API_SERVER_HOST Indexer API endpoint for Mochi's profile command, for detail see API
PT_API_SERVER_HOST Specific API of Pod Town, used to integrate new character into the verse
LOCAL_EXPERIMENTAL_CATEGORY_ID Experimental category id for when developing experimental command, for more detail see Experimental commands
MOCHI_GUILD_ID The guild where all Mochi's internal logs are sent to, default to the Web3 Console guild. If you're developing locally, you should set it to your test guild's id
LOG_CHANNEL_ID All logs are sent to this channel, set to your test channel if developing locally
ALERT_CHANNEL_ID All error log are sent to this channel, set to your test channel if developing locally
WEBSITE_ENDPOINT Mochi's website, used in verify command
GAME_TRIPOD_CHANNEL_IDS List of channel ids that are allowed to run the game Tripod
FIRESTORE_KEY Firestore service account key, used in Tripod game
TWITTER_TOKEN Twitter API bearer token, used in TwitterStream module

🏃 Run project

Change .env-sample file to .env, fill some required secrets

Install packages

pnpm install

Run bot in dev mode (incremental build on file changes)

pnpm dev

Run tests

pnpm test

📜 Logging

There are 2 streams/kinds of logs that we use to debug whenever something happens

  1. Terminal: we use pino as the logger

    Example

    terminal-log


  2. Alert: error logs are sent to the log channel when something went wrong, refer to the env table for how to setup

    Example

    alert

📝 Log format

As for the format, the log generally need to show 2 Ws and 1 H:

  • Where: the command/event that triggered this error, which channel and guild did the error occurred in, which user is having that error
  • What: what the error is about along with the data when that error occured (if any)
  • How: how to reproduce that error, in the case of a command it's the original command text (e.g $profile), otherwise if it's an API error then a curl must be present

🤖 API

Name Value Documentation Note
API_SERVER_HOST Link Swagger The main api, 90% of the time you will be interacting with this endpoint
PT_API_SERVER_HOST Link Pod Town's api, only used for integrating character into the verse
INDEXER_API_SERVER_HOST Link Swagger Indexer api, only used for profile command

⛓️ Third-party services

  • Twitter API: used in the tweet watcher module, create rules and receive tweets in real-time

🔬 Experimental commands

Experimental commands are what we came up to enable fast delivery of features or because sometimes we want to safely test the feature in production environment. Experimental commands is only accessible via special channels, end-users won't be to see it nor use it

🚀 Project components

        Discord                API
    ---------------          -------
    |             |             |
======================================
[commands] <-> [events]     [handlers]
    |             |             |
    └---------------------------┘
                  |
              [modules]

  • commands: handle !neko commands on discord
  • events: handle discord events
  • modules: core objects used by components above
  • adapters: create api call
  • errors: define errors

🙏 Credits

A big thank to all who contributed to this project!

If you'd like to contribute, please check out the contributing guide.

Contributing

mochi-discord's People

Contributors

tuanddd avatar anhnh12 avatar trkhoi avatar catngh avatar haongo138 avatar hoangharry avatar phucledien avatar nguyennh4522 avatar quanghuynguyen1902 avatar lmquang avatar jphuc96 avatar huynguyenh avatar baenv avatar phuwn avatar nminhdai avatar thminhvn avatar nguyenhuy1812 avatar namnhce avatar semantic-release-bot avatar vdhieu avatar ngolapnguyen avatar thanhpn 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.