Skip to content

Latest commit

 

History

History
162 lines (120 loc) · 7.92 KB

README.md

File metadata and controls

162 lines (120 loc) · 7.92 KB

⚙️ 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