Skip to content

How to Contribute

Mycroft Kang edited this page Jan 28, 2024 · 22 revisions

Contributing to Mulgyeol MK Bot

There are many ways to contribute to the MK Bot project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

After cloning and building the repo, check out the issues list. Issues labeled help wanted are good issues to submit a PR for. Issues labeled good first issue are great candidates to pick up if you are in the code for the first time. If you are contributing significant changes, please discuss with the assignee of the issue first before starting to work on the issue.

Prerequisites

In order to download necessary tools, clone the repository, and install dependencies

You'll need the following tools:

Tip

It is recommended to install poetry as follows.

python -m pip install --user pipx
python -m pipx ensurepath

pipx install poetry
  • msbuild, at least version 16.5 (Optional)
  • Visual Studio Code (Optional)
  • FFmpeg (Optional)

Note

You need to install FFmpeg to use voice.

  • Inno Setup, at least version 6.2 (Optional)

Getting the sources

First, fork the MK Bot repository so that you can make a pull request. Then, clone your fork locally:

git clone https://github.com/<<<your-github-account>>>/mkbot.git

Occasionally you will want to merge changes in the upstream repository (the official mkbot repo) with your fork.

cd mkbot
git checkout main
git pull https://github.com/mgylabs/mkbot.git main

Manage any merge conflicts, commit them, and then push them to your fork.

Build and Run

Prerequisites

  1. Enter the following commands in terminal.
Windows
.\scripts\dep.bat
.\scripts\prepare.bat
Linux
./scripts/dep.sh
./scripts/prepare.sh
  1. Edit config.json, mgcert.json at src\data directory.
  • config.json
{
  "discordToken": "Your Bot TOKEN",
}
  • mgcert.json
{
  "adminUsers": ["admin_username#0000"],
  "trustedUsers": ["trusted_username#0000"]
}

Discord Host

Enter the following a command in a terminal:

poetry run python mkbot.py

Console + Discord Host

Important

Console + Discord Host builds are only supported on win32-x64.

Build

  1. Enter the following commands in terminal.
Windows
cd mkbot
.\scripts\dep.bat
  1. Go into vscode, press Ctrl+Shift+B and select build to start the build task.

Run

Windows
.\scripts\mkbot.bat

preview

Debugging

Using VS Code Debugger

  1. Open the vscode repository folder.
  2. Choose the Python: mkbot.py launch configuration from the launch dropdown in the Debug viewlet and press F5.
  3. Enter the following command in a terminal:
poetry run python mkbot.py --debug

Note

Run discord_host with the above command, and when the python files in the src folder are changed, the discord_host is automatically restarted.

Tip

To use discord_host that automatically reloads changes to Python files without using a debugger, enter the following command in the terminal:

poetry run python mkbot.py

Unit Testing

Run the tests directly from a terminal by running poetry run pytest from the mkbot folder.

Validate hook files

Testing in Packaged Application

If your changes contain dependency changes, you should perform manual testing in packaged application as follows:

  1. Go into vscode, press Ctrl+Shift+B and select Test in Packaged Application to manually test packaged application.
  2. If there are errors caused by the dependency changes, you may need to add hook files. See, Add hook files for more details.

image

Add hook files

A hook file is a Python script, and can use all Python features. It can also import helper methods from PyInstaller.utils.hooks and useful variables from PyInstaller.compat.

The name of a hook file is hook-full.import.name.py, where full.import.name is the fully-qualified name of an imported script or module. You can browse through the existing hooks in the hooks folder of the PyInstaller distribution folder and see the names of the packages for which hooks have been written. For example hook-PyQt5.QtCore.py is a hook file telling about hidden imports needed by the module PyQt5.QtCore. When your script contains import PyQt5.QtCore (or from PyQt5 import QtCore), Analysis notes that hook-PyQt5.QtCore.py exists, and will call it.

The hook files of the MK Bot project is located in src/hooks.

See, Understanding PyInstaller Hooks for more details.

binaries

from PyInstaller.utils.hooks import collect_dynamic_libs

binaries = collect_dynamic_libs('module_name')

datas

from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files('module_name')

hiddenimports

hiddenimports = ['hidden_module_name']

Packaging

MK Bot can be packaged for the following platform: win32-x64

  1. When build task is complete, press Ctrl+Shift+B and select package.
  2. Run MKBotSetup-Pre.exe to install MK Bot.

Note

If you install MK Bot manually, MK Bot will not auto-update when new builds are released so you will need to regularly build and install from source to receive all the latest fixes and improvements.

Reference

MK Bot Wiki

Discord

Kakao

Python

Pyinstaller