Skip to content

Latest commit

 

History

History
218 lines (168 loc) · 6.6 KB

CONTRIBUTING.md

File metadata and controls

218 lines (168 loc) · 6.6 KB

Mochi Bot

Overview

This repository is what you need to run your own local Mochi bot

How to contribute

Prerequisites

  1. Install node.js
  2. Install docker
  3. Install canvas packages
brew install pkg-config cairo pango libpng jpeg giflib librsvg
  1. Set up discord bot

How to run source code locally

In the root of project folder

  1. Create file .env by cloning from .env-sample
cp .env-sample .env
  1. Update these in .env with your own configurations
DISCORD_TOKEN='your discord bot token’
APPLICATION_ID=‘your application id’
LOG_CHANNEL_ID='YOUR CHANNEL ID’
MOCHI_GUILD_ID=‘YOUR GUILD ID’
  1. Install dependencies
make install
  1. Run bot
make dev

How to work on a TODO

  1. Feel free to pick any TODO for you from **Board View → Mochi → Backlog**
  2. Assign that item to your account
  3. Remember to update item’s status based on your working progress
    • Backlog: not started yet
    • In Progress: still working on
    • In Review: Task done = PR has been merged to develop branch at least
    • Completed: Confirmation from the team that the TODO is completely finished
  4. When switching your TODO to In Review, remember to fill these in Untitled

PR Template

**What does this PR do?**

- [x] New command `$abc` or `/abc` to ...
- [x] Update command flow ...
- [x] Fix error ...

**How to test** (optional)
Can be replaced by **Demo** section with a demo video

**Flowchart** (optional)
Should have if the flow is complex

**Media** (Demo)
Attach images or demo videos
Can insert video URL in case the size exceeds github limit

Technical Document

1. Project structure

All source code located under src/, which contains multiple modules

  • adapters/: where all API requests are invoked
  • assets/: static resources (fonts, images)
  • commands/: where all bot commands are located. Most of them are divided into 5 main groups
    • config: mostly commands related to guild’s settings (e.g. reaction-role)
    • defi: crypto-related commands (crypto tracking, wallet tx, etc.)
    • community: set up channels and other add-ins to facilitate activities
    • profile: personal things (e.g. profile, verify wallet)
    • And other commands which do not belong to any group (e.g. help.ts)
    • index.ts: contains all available commands and functions to validate, authorize and route user’s input to the respective command handler
  • errors/: custom bot errors’ handlers
  • events/: where discord events are listened and handled (e.g. logging a text when the bot launched successfully with event ready
  • types/: types’ definitions for usage across the project. There are 2 files needs to be noticed
    • api.ts: auto-generated file by swagger-typescript-api. Containing all model definitions from mochi-api’s swagger documentation
    • common.ts: contains 2 important types Command (text command) and SlashCommand. Will go deeper in next section
  • utils: utility methods for general usages (e.g. composeEmbedMessage())

2. Command structure

a. Text command (prefix $)

export type Command = {
  // unique command ID
  id: string;
  command: string;
  category: Category;
  // brief description of the command
  // this will be shown in command's help messagae
  brief: string;
  // flag to enable (true) only-admin command
  onlyAdministrator?: boolean;
  // command's handler
  run: (
    msg: Message,
    action?: string,
  ) => Promise<
    | RunResult<MessageOptions>
    | MultipleResult<Message>
    | void
    | null
    | undefined
  >;
  // command's help message ($help ticker)
  getHelpMessage: (msg: Message, action?: string) => Promise<MessageOptions>;
  // command's aliases ($reactionrole = $rr)
  aliases?: string[];
  // flag to determine whether command can run without sub-command
  // e.g. reactionrole
  // $rr -> show help message because of invalid command
  // $rr list -> show list of reaction-roles
  canRunWithoutAction?: boolean;
  // can only run in admin/team channels
  experimental?: boolean;
  // list of sub-commands
  actions?: Record<string, Command>;
  // allow command to be able to used in DM
  allowDM?: boolean;
  // command's color
  colorType: ColorType;
  // number of min arguments (including the command itself)
  // e.g. $wl add eth = 3 arguments
  // if the input is lack of arguments, show help message
  minArguments?: number;
};

b. Slash command (prefix /)

export type SlashCommand = {
  name: string;
  category: Category;
  onlyAdministrator?: boolean;
  // auto-complete suggestions for command's arguments
  prepare: (
    slashCommands?: Record<string, SlashCommand>,
  ) =>
    | Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">
    | SlashCommandSubcommandBuilder;
  run: (
    interaction: CommandInteraction,
  ) => Promise<
    | RunResult<MessageOptions>
    | MultipleResult<CommandInteraction>
    | void
    | null
    | undefined
  >;
  help: (interaction: CommandInteraction) => Promise<MessageOptions>;
  // flag to determine if the response message is privately shown to user
  ephemeral?: boolean;
  colorType: ColorType;
};

3. Modules references

Credits

A big thank to all who contributed to this project! Untitled

Keep in touch