Skip to content

shinyfinder/chatot-smogon

Repository files navigation

Chatot

Supplemental Discord bot for Smogon, written in TypeScript.

Installation

This code assumes you have v.16.9.0 or later installed of NodeJs. 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

  1. Obtain a copy of the source code by downloading the zip of the repository or, if you have git installed, via the command line in your desired destination folder:

git clone https://github.com/shinyfinder/chatot.git

If you download the zip, extract the file into your desired directory.

  1. Open a command line and navigate to your installation directory. Install the dependencies via:

pnpm install

  1. Make a copy of the file .sample-env and rename the copy to .env. 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 these values.

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

Using the bot

This bot uses slash commands (a subset of application commands). Deployment of these commands is handled during startup of the bot witihn the /src/helpers/updateState.ts file. This script detects any changes in your command definitions and (re)deploys them as appropriate. The deployment scope is defined within the command definitions themselves with the following flags:

global: <boolean>
guilds: <string[]>

Setting the global flag to true will cause the command to be deployed globally (i.e. to every server the bot is in). Setting the global flag to false and providing a list of server IDs as strings within the guilds array will instead deploy the command as a guild command (i.e. only to that guild) to the listed servers. Note that if the bot is in 'dev' mode, the specified guild array will be overwritten with the dev guild id specifed in the .env.

Start the bot from the terminal with the following:

pnpm build
pnpm start

You should see that the bot is now online in Discord. To confirm it is responding to commands, post the following within Discord:

/ping

The bot should respond with "Pong!".

Tunneling to production

The bot supports tunneling into and making (read) queries against select production databases. To use this feature, you must be setup with SSH access to the production server. This is restricted to trusted developers, but if you believe you qualify, contact chaos.

To use this feature, first SSH into the server within the terminal. This creates a live connection (which can be killed with ctrl + c). Then, in a new terminal, set the SSH flag to true within your .env and run Chatot. SQL queries against the variablePool connection will now query against the production database. If the SSH flag is set to false, variablePool queries will default to the local database. See /src/helpers/createPool.ts.

Further Reading

Please refer to the Discord documentation for further information on adding, using, and deleting slash commands. For more in-depth information, see the devloper documentation on application commands.

Please see the wiki for detailed information regarding setup and usage of the bot.

License

This software is distributed under the MIT license.

About

Repo for developing Chatot for deployment on smogon servers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages