Ronhorn is Longhorn Riichi's Discord Bot, which supports two categories of slash commands:
- commands specific to Longhorn Riichi's club operations (
/register
,/enter_score
, etc.) - commands that provide utilities for online mahjong games like Mahjong Soul and Tenhou (
/skill
,/parse
, etc.)
The documentation for the Discord slash commands can be found here
It also has a passive component that automatically tracks and records online games played in the club's Mahjong Soul lobbies, which is a more advanced version of that of the UvUManager.
bot.py
: entry point of the Discord bot. Does the following:- imports
global_stuff.py
, which does the following:- load all the environment variables from
config.env
- initialize the Google Sheets interface
- initialize Mahjong Soul
AccountManager
- load all the environment variables from
- set up the non-slash Discord commands
- set up command error handlers (both slash and non-slash)
- imports
/ext/
: Discord bot extensions (each extension is a suite of slash commands and their helper functions)LobbyManagers
: has commands to pause, unpause, and terminate contest games from all 4 tournaments. Listens for finished games and records results. Automatically extends contest finish_time and reconnects when necessary.Utilities
: various utilities, including recording in-person games, managing club membership, fetching links to player stats on external websites, etc.InjusticeJudge
: has commands that rely on the InjusticJudge submodule, and the helpers that make efficient API calls. Caches the game logs in/cached_games
, up to 1 GB.
/modules/
: modules to be imported into the above extensionsInjusticeJudge
: houses the InjusticJudge submodulepymjsoul
: a modified version of mjsoul.py that providesMajsoulChannel
, a class for interfacing with Mahjong Soul's APImahjongsoul
: contains two wrappers ofMajsoulChannel
:ContestManager
: logs into the Chinese Mahjong Soul contest management server to monitor club tournamentsAccountManager
: logs into the Chinese Mahjong Soul game server to directly fetch game results/records
First, cp config.template.env config.env
.
- set up a bot account on Discord's developer portal (
New Application
).- (SETTINGS -> Bot) Privileged Gateway Intents:
SERVER MEMBERS INTENT
ANDMESSAGE CONTENT INTENT
- (SETTINGS -> Bot) Privileged Gateway Intents:
- invite the bot to the respective servers. You can use the developer portal's OAuth2 URL Generator (SETTINGS -> OAuth2 -> URL Generator):
- Scopes: bot
- Bot Permissions: Send Messages, Manage Messages, Use External Emojis (and more as we add more functionalities)
- fill in the
Discord Stuff
section of config.env. The bot token can be obtained through (SETTINGS -> Bot [-> Reset Token])
- set up a Google Cloud project. Enable Google Sheets API access, and make a service account. Generate a JSON key for that service account and save it as
gs_service_account.json
in the root directory - make a suitable Google Spreadsheet (example) and share the Spreadsheet with that service account.
- fill in the
Google Sheets Stuff
section of config.env
- fill in the
Mahjong Soul Stuff
section of config.env
Make an injustice_servers.json
in the root directory, with <server_name>: <server_ID>
pairs. The <server_name>
is for record-keeping only. Only servers whose <server_ID>
is specified here will have the /injustice
command available. Example:
{
"Longhorn Riichi": "111111111111111111",
"The Riichi Mahjong Association (UT Dallas)": "111111111111111111",
"Riichi Nomi": "111111111111111111"
}
Similarly, make a slash_commands_servers.json
in the root directory, for the servers that want the slash commands that are not exclusive to Longhorn Riichi (excluding /injustice
).
{
"Longhorn Riichi": "111111111111111111",
"The Riichi Mahjong Association (UT Dallas)": "111111111111111111",
"Main Mahjong Server": "111111111111111111",
"Riichi Nomi": "111111111111111111"
}
-
in a Unix shell:
pipenv install pipenv shell ./start.sh
-
in the relevant Discord server: run
rh/sync
to sync the slash commands for that server (rh/
is the regular command prefix).
- amae-koromo and amae-koromo-scripts
- Ronnie
- mjsoul.py (eventually we'll add our
mahjongsoul
module into themjsoul.py
package) - mahjong_soul_api