Installation - shinyfinder/chatot-smogon GitHub Wiki

Note

The source code for Chatot has been moved to the main Smogon repo and does not pull from this repository anymore. However, these steps are still maintained. If you're looking to add Chatot to your servers, refer to the User Guide instead.

General comments

Note that the bot is hosted on a Linux system. Although the code can be run on any OS, ultimately that is the one used in production on the Smogon servers. While beyond the scope of this wiki, you may find it prudent to use Docker or, for Windows users, installation of WSL. Windows users are recommended to use WSL if they plan on contributing to development.

Whether you are planning on running a local copy or contributing to development, the first thing you'll need to do is install Node. This code assumes you have v.20.x.0 or later installed of NodeJs (at least the LTS). Please install or update that first before proceeding. The package manager of choice for this project is pnpm. It can be installed with npm (installed by default with node) with the following, or any of the other methods on their website.

npm install -g pnpm

Once you have installed Node and pnpm, you'll want to obtain a copy of the code. Please confer with chaos for access.

Installation of dependencies

Installing the packages required by the bot is easy. Within the command line, in the smogon.com directory run

pnpm install

The program will automatically install all of the required packages.

Setting up the developer environment

Environment Variables

In the root directory of the project (/smogon.com/), create a file called .env. The keys needed in this file can be found in the README(https://github.com/smogon/smogon.com/tree/master/chatot). Thie file contains the environment variables required for the bot to run. Never give out the values in this file! Please refer to the discord.js documentation for setting up your bot application and adding the bot to your server(s) to obtain your values.

For full functionality, the bot needs access to all 3 privileged intents (guild pressences, guild members, and message content).

Additions to the environment variables will need to be reflected in config.ts. These values are accessed within the bot as botConfig.VARIABLE_NAME.

Databases

Many of the functions of the bot rely on access to a PostgreSQL (PG/Postgres) database, and when interacting with the Smogon forums, a MySQL database. Postgres is an open source database system that extends the usage of SQL. If you aren't sure what that means, don't worry about it. If you're familiar with JS, you've likely come across JSON files, which are files commonly used to store data locally. Postgres is an alternative storage method in which data is stored in tables. Think of it like a big spreadsheet. The tables in this database are how the bot stores data between command executions and startups. As you work with it, you'll quickly find it a superior method to managing large datasets and filtering data.

Installation and usage of Postgres and MySQL is beyond the scope of this guide. However, you can find guides to these tasks across the internet, such as the official Postgres manual.

Chatot now runs in dev mode under testcontainers, eliminating the need for devs to install and manage their own SQL databases. This requires Docker to at least be installed (you do not need to create a Docker image, but you can if you want for your own purposes).

On shutdown, the program will create a database backup file in the directory of your choosing (see /chatot/src/startWithContainers.ts). Whatever name and path you choose, it's a good idea to add it to your personal gitignore file, located under project_directory/.git/info/exclude so you don't pollute the commit history.

Commands that access the Dex information require SSH access to the production server. Please confer with chaos for your options in obtaining this access.

More software...

By this point it is assumed you have already made a development server and bot application within the Discord developer portal, as linked above. If you are just trying to run a local copy, you can proceed to the Runtime and Code Management section. If you plan on contributing to development, read on.

It is strongly recommended (read: required) to use Git and a robust IDE such as VS Code when contributing to development. This section will assume you are using both. Proper usage of these tools is beyond the scope of this wiki, but some common commands in git you will need are

git pull
git add .
git commit -m 'commit message goes here'
git push origin main
git stash
git stash pop

For Windows users using WSL, Microsoft has a tutorial for setting up a WSL development environment. They have put a lot of effort into making the integration of Windows, Linux, and VS Code seamless, so following their guide is the best advice. Docker and GPU acceleration are not required, but you can look into that if you wish.

The only VS Code extension not covered in the above guide is ESLint. To ensure your additions to the code are consistent with the existing rules, install the ESLint extension if you are contributing to development. Linters analyze your code for format errors and best practices. While not required, it is nice to have and ensures a consistent experience no matter who contributes to development. Remember that linters are a guide and can be too strict for your needs. Sometimes you need to overrule them.