This repository is what you need to run your own local Mochi bot
- Install node.js
- Install docker
- Install canvas packages
brew install pkg-config cairo pango libpng jpeg giflib librsvg
In the root of project folder
- Create file
.env
by cloning from.env-sample
cp .env-sample .env
- 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’
- Install dependencies
make install
- Run bot
make dev
- Feel free to pick any TODO for you from **Board View → Mochi → Backlog**
- Assign that item to your account
- Remember to update item’s status based on your working progress
Backlog
: not started yetIn Progress
: still working onIn Review
: Task done = PR has been merged todevelop
branch at leastCompleted
: Confirmation from the team that the TODO is completely finished
- When switching your TODO to
In Review
, remember to fill these in
**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
1. Project structure
All source code located under src/
, which contains multiple modules
adapters/
: where all API requests are invokedassets/
: static resources (fonts, images)commands/
: where all bot commands are located. Most of them are divided into 5 main groupsconfig
: 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 activitiesprofile
: 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’ handlersevents/
: where discord events are listened and handled (e.g. logging a text when the bot launched successfully with eventready
types/
: types’ definitions for usage across the project. There are 2 files needs to be noticedapi.ts
: auto-generated file byswagger-typescript-api
. Containing all model definitions from mochi-api’s swagger documentationcommon.ts
: contains 2 important typesCommand
(text command) andSlashCommand
. 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
A big thank to all who contributed to this project!
- Reach us at discord.
- Discuss development in the #build-with-us channel.
- Core team members and Contributors.