initial update

This commit is contained in:
murm 2023-03-15 10:09:09 -04:00
parent 3272429cf6
commit db9b70bf66
280 changed files with 11772 additions and 11966 deletions

View file

@ -1,78 +1,78 @@
# Config
esmBot uses a mix of environment variables and JSON for configuration.
## Environment Variables (.env)
To make managing environment variables easier, an example `.env` file is included with the bot at `.env.example` and can be used to load the variables on startup.
### Required
- `NODE_ENV`: Used for tuning the bot to different environments. If you don't know what to set it to, leave it as is.
- `TOKEN`: Your bot's token. You can find this [here](https://discord.com/developers/applications) under your application's Bot tab.
- `DB`: The database connection string. By default the `sqlite` and `postgresql` protocols are available, but this can be expanded by putting proper DB driver scripts into `utils/database/`.
- `OWNER`: Your Discord user ID. This is used for granting yourself access to certain management commands. Adding multiple users is supported by separating the IDs with a comma; however, this is not recommended for security purposes.
- `PREFIX`: The bot's default command prefix for classic commands. Note that servers can set their own individual prefixes via the `prefix` command.
### Optional
These variables that are not necessarily required for the bot to run, but can greatly enhance its functionality:
- `STAYVC`: Set this to true if you want the bot to stay in voice chat after playing music/a sound effect. You can make it leave by using the stop command.
- `TENOR`: An API token from [Tenor](https://tenor.com/gifapi). This is required for using GIFs from Tenor.
- `OUTPUT`: A directory to output the help documentation in Markdown format to. It's recommended to set this to a directory being served by a web server.
- `TEMPDIR`: A directory that will store generated images larger than 8MB. It's recommended to set this to a directory being served by a web server.
- `TMP_DOMAIN`: The root domain/directory that the images larger than 8MB are stored at. Example: `https://projectlounge.pw/tmp`
- `THRESHOLD`: A filesize threshold that the bot will start deleting old files in `TEMPDIR` at.
- `METRICS`: The HTTP port to serve [Prometheus](https://prometheus.io/)-compatible metrics on.
- `API_TYPE`: Set this to "none" if you want to process all images locally. Alternatively, set it to "ws" to use an image API server specified in the `image` block of `config/servers.json`.
- `ADMIN_SERVER`: A Discord server/guild ID to limit owner-only commands such as eval to.
## JSON
The JSON-based configuration files are located in `config/`.
### commands.json
```js
{
"types": {
"classic": false, // Enable/disable "classic" (prefixed) commands, note that classic commands in direct messages will still work
"application": true // Enable/disable application commands (slash and context menu commands)
},
"blacklist": [
// Names of commands that you don't want the bot to load
]
}
```
### messages.json
```js
{
"emotes": [
// Discord emote strings to use in the "Processing... this may take a while" messages, e.g. "<a:processing:818243325891051581>" or "⚙️"
],
"messages": [
// Strings to use in the bot's activity message/playing status
]
}
```
### servers.json
```js
{
"lava": [ // Objects containing info for connecting to Lavalink audio server(s)
{
"name": "test", // A human-friendly name for the server
"url": "localhost:2333", // IP address/domain name and port for the server
"auth": "youshallnotpass", // Password/authorization code for the server
"local": false // Whether or not the esmBot "assets" folder is located next to the Lavalink jar file
}
],
"image": [ // Objects containing info for connecting to WS image server(s)
{
"server": "localhost", // IP address or domain name for the server
"auth": "verycoolpass100", // Password/authorization code for the server
"tls": false // Whether or not this is a secure TLS/wss connection
}
],
"searx": [
// URLs for Searx/SearXNG instances used for image/YouTube searches, e.g. "https://searx.projectlounge.pw"
// Note: instances must support getting results over JSON
]
}
```
# Config
esmBot uses a mix of environment variables and JSON for configuration.
## Environment Variables (.env)
To make managing environment variables easier, an example `.env` file is included with the bot at `.env.example` and can be used to load the variables on startup.
### Required
- `NODE_ENV`: Used for tuning the bot to different environments. If you don't know what to set it to, leave it as is.
- `TOKEN`: Your bot's token. You can find this [here](https://discord.com/developers/applications) under your application's Bot tab.
- `DB`: The database connection string. By default the `sqlite` and `postgresql` protocols are available, but this can be expanded by putting proper DB driver scripts into `utils/database/`.
- `OWNER`: Your Discord user ID. This is used for granting yourself access to certain management commands. Adding multiple users is supported by separating the IDs with a comma; however, this is not recommended for security purposes.
- `PREFIX`: The bot's default command prefix for classic commands. Note that servers can set their own individual prefixes via the `prefix` command.
### Optional
These variables that are not necessarily required for the bot to run, but can greatly enhance its functionality:
- `STAYVC`: Set this to true if you want the bot to stay in voice chat after playing music/a sound effect. You can make it leave by using the stop command.
- `TENOR`: An API token from [Tenor](https://tenor.com/gifapi). This is required for using GIFs from Tenor.
- `OUTPUT`: A directory to output the help documentation in Markdown format to. It's recommended to set this to a directory being served by a web server.
- `TEMPDIR`: A directory that will store generated images larger than 8MB. It's recommended to set this to a directory being served by a web server.
- `TMP_DOMAIN`: The root domain/directory that the images larger than 8MB are stored at. Example: `https://projectlounge.pw/tmp`
- `THRESHOLD`: A filesize threshold that the bot will start deleting old files in `TEMPDIR` at.
- `METRICS`: The HTTP port to serve [Prometheus](https://prometheus.io/)-compatible metrics on.
- `API_TYPE`: Set this to "none" if you want to process all images locally. Alternatively, set it to "ws" to use an image API server specified in the `image` block of `config/servers.json`.
- `ADMIN_SERVER`: A Discord server/guild ID to limit owner-only commands such as eval to.
## JSON
The JSON-based configuration files are located in `config/`.
### commands.json
```js
{
"types": {
"classic": false, // Enable/disable "classic" (prefixed) commands, note that classic commands in direct messages will still work
"application": true // Enable/disable application commands (slash and context menu commands)
},
"blacklist": [
// Names of commands that you don't want the bot to load
]
}
```
### messages.json
```js
{
"emotes": [
// Discord emote strings to use in the "Processing... this may take a while" messages, e.g. "<a:processing:818243325891051581>" or "⚙️"
],
"messages": [
// Strings to use in the bot's activity message/playing status
]
}
```
### servers.json
```js
{
"lava": [ // Objects containing info for connecting to Lavalink audio server(s)
{
"name": "test", // A human-friendly name for the server
"url": "localhost:2333", // IP address/domain name and port for the server
"auth": "youshallnotpass", // Password/authorization code for the server
"local": false // Whether or not the esmBot "assets" folder is located next to the Lavalink jar file
}
],
"image": [ // Objects containing info for connecting to WS image server(s)
{
"server": "localhost", // IP address or domain name for the server
"auth": "verycoolpass100", // Password/authorization code for the server
"tls": false // Whether or not this is a secure TLS/wss connection
}
],
"searx": [
// URLs for Searx/SearXNG instances used for image/YouTube searches, e.g. "https://searx.projectlounge.pw"
// Note: instances must support getting results over JSON
]
}
```

View file

@ -1,88 +1,88 @@
# Custom Commands
esmBot has a powerful and flexible command handler, allowing you to create new commands and categories simply by creating new files. This page will provide a reference for creating new commands.
## Directory Structure
The bot loads commands from subdirectories inside of the `commands` directory, which looks something like this by default:
```
commands/
- fun
> cat.js
> ...
- general
> help.js
> ping.js
> ...
- image-editing
> caption.js
> speed.js
> ...
```
As you can see, each command is grouped into categories, which are represented by subdirectories. To create a new category, you can simply create a new directory inside of the `commands` directory, and to create a new command, you can create a new JS file under one of those subdirectories.
!!! tip
The `message` category is special; commands in here act as right-click context menu message commands instead of "classic" or slash commands.
## Command Structure
It's recommended to use the `Command` class located in `classes/command.js` to create a new command in most cases. This class provides various parameters and fields that will likely be useful when creating a command. Here is a simple example of a working command file:
```js
import Command from "../../classes/command.js";
class HelloCommand extends Command {
async run() {
return "Hello world!";
}
static description = "A simple command example";
static aliases = ["helloworld"];
}
export default HelloCommand;
```
As you can see, the first thing we do is import the Command class. We then create a new class for the command that extends that class to provide the needed parameters. We then define the command function, which is named `run`. Some static parameters, including the command description and an alias for the command, `helloworld`, are also defined. Finally, once everything in the command class is defined, we export the new class to be loaded as a module by the command handler.
The default command name is the same as the filename that you save it as, excluding the `.js` file extension. If you ever want to change the name of the command, just rename the file.
The parameters available to your command consist of the following:
- `this.client`: An instance of an Oceanic [`Client`](https://docs.oceanic.ws/dev/classes/Client.Client.html), useful for getting info or performing lower-level communication with the Discord API.
- `this.origOptions`: The raw options object provided to the command by the command handler.
- `this.type`: The type of message that activated the command. Can be "classic" (a regular message) or "application" (slash/context menu commands).
- `this.channel`: An Oceanic [`TextChannel`](https://docs.oceanic.ws/dev/classes/TextChannel.TextChannel.html) object of the channel that the command was run in, useful for getting info about a server and how to respond to a message.
- `this.guild`: An Oceanic [`Guild`](https://docs.oceanic.ws/dev/classes/Guild.Guild.html) object of the guild that the command was run in. This is undefined in DMs.
- `this.author`: An Oceanic [`User`](https://docs.oceanic.ws/dev/classes/User.User.html) object of the user who ran the command, or a [`Member`](https://docs.oceanic.ws/dev/classes/Member.Member.html) object identical to `this.member` if run in a server as a slash command.
- `this.member`: An Oceanic [`Member`](https://docs.oceanic.ws/dev/classes/Member.Member.html) object of the server member who ran the command. When running the command outside of a server, this parameter is undefined when run as a "classic" command or a [`User`](https://docs.oceanic.ws/dev/classes/User.User.html) object identical to `this.author` when run as a slash command.
- `this.options`: When run as a "classic" command, this is an object of special arguments (e.g. `--argument=true`) passed to the command. These arguments are stored in a key/value format, so following the previous example, `this.options.argument` would return true. When run as a slash command, this is an object of every argument passed to the command.
Some options are only available depending on the context/original message type, which can be checked with `this.type`. The options only available with "classic" messages are listed below:
- `this.message`: An Oceanic [`Message`](https://docs.oceanic.ws/dev/classes/Message.Message.html) object of the message that the command was run from, useful for interaction.
- `this.args`: An array of text arguments passed to the command.
- `this.content`: A string of the raw content of the command message, excluding the prefix and command name.
- `this.reference`: An object that's useful if you ever decide to reply to a user inside the command. You can use [`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to combine your message content with this parameter.
The options only available with application (slash and context menu) commands are listed below:
- `this.interaction`: An Oceanic [`CommandInteraction`](https://docs.oceanic.ws/dev/classes/CommandInteraction.CommandInteraction.html) object of the incoming slash command data.
- `this.optionsArray`: A raw array of command options. Should rarely be used.
- `this.success`: A boolean value that causes the bot to respond with a normal message when `true`, or an "ephemeral" message (a message that's only visible to the person who ran the command) when `false`.
Some static fields are also available and can be set depending on your command. These fields are listed below:
- `description`: Your command's description, which is shown in the help command.
- `aliases`: An array of command aliases. People will be able to run the command using these as well as the normal command name.
- `arguments`: An array of command argument types, which are shown in the help command.
- `flags`: An array of objects specifying command flags, or special arguments, that will be shown when running `help <command>` or a slash command. Example:
```js
static flags = [{
name: "argument",
type: Constants.ApplicationCommandOptionTypes.STRING, // translates to 3, see https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type
description: "Does a thing",
...
}];
```
- `slashAllowed`: Specifies whether or not the command is available via slash commands.
- `directAllowed`: Specifies whether or not a command is available in direct messages.
- `adminOnly`: Specifies whether or not a command should be limited to the bot owner(s).
## The `run` Function
# Custom Commands
esmBot has a powerful and flexible command handler, allowing you to create new commands and categories simply by creating new files. This page will provide a reference for creating new commands.
## Directory Structure
The bot loads commands from subdirectories inside of the `commands` directory, which looks something like this by default:
```
commands/
- fun
> cat.js
> ...
- general
> help.js
> ping.js
> ...
- image-editing
> caption.js
> speed.js
> ...
```
As you can see, each command is grouped into categories, which are represented by subdirectories. To create a new category, you can simply create a new directory inside of the `commands` directory, and to create a new command, you can create a new JS file under one of those subdirectories.
!!! tip
The `message` category is special; commands in here act as right-click context menu message commands instead of "classic" or slash commands.
## Command Structure
It's recommended to use the `Command` class located in `classes/command.js` to create a new command in most cases. This class provides various parameters and fields that will likely be useful when creating a command. Here is a simple example of a working command file:
```js
import Command from "../../classes/command.js";
class HelloCommand extends Command {
async run() {
return "Hello world!";
}
static description = "A simple command example";
static aliases = ["helloworld"];
}
export default HelloCommand;
```
As you can see, the first thing we do is import the Command class. We then create a new class for the command that extends that class to provide the needed parameters. We then define the command function, which is named `run`. Some static parameters, including the command description and an alias for the command, `helloworld`, are also defined. Finally, once everything in the command class is defined, we export the new class to be loaded as a module by the command handler.
The default command name is the same as the filename that you save it as, excluding the `.js` file extension. If you ever want to change the name of the command, just rename the file.
The parameters available to your command consist of the following:
- `this.client`: An instance of an Oceanic [`Client`](https://docs.oceanic.ws/dev/classes/Client.Client.html), useful for getting info or performing lower-level communication with the Discord API.
- `this.origOptions`: The raw options object provided to the command by the command handler.
- `this.type`: The type of message that activated the command. Can be "classic" (a regular message) or "application" (slash/context menu commands).
- `this.channel`: An Oceanic [`TextChannel`](https://docs.oceanic.ws/dev/classes/TextChannel.TextChannel.html) object of the channel that the command was run in, useful for getting info about a server and how to respond to a message.
- `this.guild`: An Oceanic [`Guild`](https://docs.oceanic.ws/dev/classes/Guild.Guild.html) object of the guild that the command was run in. This is undefined in DMs.
- `this.author`: An Oceanic [`User`](https://docs.oceanic.ws/dev/classes/User.User.html) object of the user who ran the command, or a [`Member`](https://docs.oceanic.ws/dev/classes/Member.Member.html) object identical to `this.member` if run in a server as a slash command.
- `this.member`: An Oceanic [`Member`](https://docs.oceanic.ws/dev/classes/Member.Member.html) object of the server member who ran the command. When running the command outside of a server, this parameter is undefined when run as a "classic" command or a [`User`](https://docs.oceanic.ws/dev/classes/User.User.html) object identical to `this.author` when run as a slash command.
- `this.options`: When run as a "classic" command, this is an object of special arguments (e.g. `--argument=true`) passed to the command. These arguments are stored in a key/value format, so following the previous example, `this.options.argument` would return true. When run as a slash command, this is an object of every argument passed to the command.
Some options are only available depending on the context/original message type, which can be checked with `this.type`. The options only available with "classic" messages are listed below:
- `this.message`: An Oceanic [`Message`](https://docs.oceanic.ws/dev/classes/Message.Message.html) object of the message that the command was run from, useful for interaction.
- `this.args`: An array of text arguments passed to the command.
- `this.content`: A string of the raw content of the command message, excluding the prefix and command name.
- `this.reference`: An object that's useful if you ever decide to reply to a user inside the command. You can use [`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to combine your message content with this parameter.
The options only available with application (slash and context menu) commands are listed below:
- `this.interaction`: An Oceanic [`CommandInteraction`](https://docs.oceanic.ws/dev/classes/CommandInteraction.CommandInteraction.html) object of the incoming slash command data.
- `this.optionsArray`: A raw array of command options. Should rarely be used.
- `this.success`: A boolean value that causes the bot to respond with a normal message when `true`, or an "ephemeral" message (a message that's only visible to the person who ran the command) when `false`.
Some static fields are also available and can be set depending on your command. These fields are listed below:
- `description`: Your command's description, which is shown in the help command.
- `aliases`: An array of command aliases. People will be able to run the command using these as well as the normal command name.
- `arguments`: An array of command argument types, which are shown in the help command.
- `flags`: An array of objects specifying command flags, or special arguments, that will be shown when running `help <command>` or a slash command. Example:
```js
static flags = [{
name: "argument",
type: Constants.ApplicationCommandOptionTypes.STRING, // translates to 3, see https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type
description: "Does a thing",
...
}];
```
- `slashAllowed`: Specifies whether or not the command is available via slash commands.
- `directAllowed`: Specifies whether or not a command is available in direct messages.
- `adminOnly`: Specifies whether or not a command should be limited to the bot owner(s).
## The `run` Function
The main JS code of your command is specified in the `run` function. This function should return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) of your command output, which is why the `run` function [is an async function by default](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function). The return value inside the `Promise` should be either a string or an object; you should return a string whenever you intend to reply with plain text, or an object if you intend to reply with something else, such as an embed or attachment.

View file

@ -1,27 +1,27 @@
# Docker
You can run the bot as well as its dependencies as a series of Docker containers. However, the manual setup is still recommended if you want more control over the bot.
[To start, install Docker on your system via the instructions here.](https://docs.docker.com/engine/install/#server)
Once you've installed Docker, you should clone the esmBot repo:
```sh
cd ~
git clone --recurse-submodules https://github.com/esmBot/esmBot
cd esmBot
```
Modify the `.env` file as described in step 7 of the manual setup. Make sure to change the `DB` option to this, however:
```
DB=postgresql://esmbot:verycoolpass100@postgres:5432/esmbot
```
You should then modify the `config/servers.json` file to change the IP addresses of the servers to match the Docker containers. Example:
```json
{
"lava": [
{ "name": "localhost", "url": "lavalink:2333", "auth": "youshallnotpass", "local": true }
],
"image": [
{ "server": "api", "auth": "verycoolpass100", "tls": false }
]
}
```
# Docker
You can run the bot as well as its dependencies as a series of Docker containers. However, the manual setup is still recommended if you want more control over the bot.
[To start, install Docker on your system via the instructions here.](https://docs.docker.com/engine/install/#server)
Once you've installed Docker, you should clone the esmBot repo:
```sh
cd ~
git clone --recurse-submodules https://github.com/esmBot/esmBot
cd esmBot
```
Modify the `.env` file as described in step 7 of the manual setup. Make sure to change the `DB` option to this, however:
```
DB=postgresql://esmbot:verycoolpass100@postgres:5432/esmbot
```
You should then modify the `config/servers.json` file to change the IP addresses of the servers to match the Docker containers. Example:
```json
{
"lava": [
{ "name": "localhost", "url": "lavalink:2333", "auth": "youshallnotpass", "local": true }
],
"image": [
{ "server": "api", "auth": "verycoolpass100", "tls": false }
]
}
```
Finally, start the bot by running `docker-compose up -d`.

View file

@ -1,3 +1,3 @@
Welcome to the esmBot documentation site!
Welcome to the esmBot documentation site!
You're probably looking for the [Setup](setup.md) page. If you're an end user looking to invite the bot, head over to [https://esmbot.net/invite](https://esmbot.net/invite).

View file

@ -1,65 +1,65 @@
# PostgreSQL
Here are some instructions for setting up PostgreSQL for use with esmBot.
### 1. Install PostgreSQL.
=== "Debian/Ubuntu"
```sh
sudo apt-get install postgresql postgresql-client
```
=== "Fedora/RHEL"
```sh
sudo dnf install postgresql postgresql-server
```
=== "Alpine"
```sh
doas apk add postgresql
```
=== "Arch/Manjaro"
```sh
sudo pacman -S postgresql
```
***
### 2. (Optional) Tune PostgreSQL.
[PGTune](https://pgtune.leopard.in.ua/) is a useful tool for generating configuration files for your PostgreSQL database. It is highly recommended that you generate a config using this tool as it can increase stability and performance.
***
### 3. Create the bot user and database.
When you install PostgreSQL, it'll create a new user on your system that acts as the "superuser" of the database. You'll need to run Postgres commands as this user; however, you can run a command as that user without switching to it by using `sudo`.
First, you'll need to create a user that the bot can interact with as well as the database itself:
```sh
sudo su - postgres -c "createuser esmbot"
sudo su - postgres -c "createdb esmbot"
```
Then, launch the PostgreSQL shell for the next few commands:
```sh
sudo -u postgres psql
```
If you want to give the user a password, you can do so like this:
```sql
ALTER USER esmbot WITH PASSWORD 'new_password';
```
Once you're inside the shell, you'll need to make sure the bot owns the database and has permissions:
```sql
ALTER DATABASE esmbot OWNER TO esmbot;
```
You're done!
***
### Troubleshooting
If you get an error like `error: permission denied for table counts` when attempting to run the bot, try running these commands in the PostgreSQL shell:
```sql
\c esmbot
GRANT ALL PRIVILEGES ON guilds TO esmbot;
GRANT ALL PRIVILEGES ON counts TO esmbot;
GRANT ALL PRIVILEGES ON tags TO esmbot;
\q
```
# PostgreSQL
Here are some instructions for setting up PostgreSQL for use with esmBot.
### 1. Install PostgreSQL.
=== "Debian/Ubuntu"
```sh
sudo apt-get install postgresql postgresql-client
```
=== "Fedora/RHEL"
```sh
sudo dnf install postgresql postgresql-server
```
=== "Alpine"
```sh
doas apk add postgresql
```
=== "Arch/Manjaro"
```sh
sudo pacman -S postgresql
```
***
### 2. (Optional) Tune PostgreSQL.
[PGTune](https://pgtune.leopard.in.ua/) is a useful tool for generating configuration files for your PostgreSQL database. It is highly recommended that you generate a config using this tool as it can increase stability and performance.
***
### 3. Create the bot user and database.
When you install PostgreSQL, it'll create a new user on your system that acts as the "superuser" of the database. You'll need to run Postgres commands as this user; however, you can run a command as that user without switching to it by using `sudo`.
First, you'll need to create a user that the bot can interact with as well as the database itself:
```sh
sudo su - postgres -c "createuser esmbot"
sudo su - postgres -c "createdb esmbot"
```
Then, launch the PostgreSQL shell for the next few commands:
```sh
sudo -u postgres psql
```
If you want to give the user a password, you can do so like this:
```sql
ALTER USER esmbot WITH PASSWORD 'new_password';
```
Once you're inside the shell, you'll need to make sure the bot owns the database and has permissions:
```sql
ALTER DATABASE esmbot OWNER TO esmbot;
```
You're done!
***
### Troubleshooting
If you get an error like `error: permission denied for table counts` when attempting to run the bot, try running these commands in the PostgreSQL shell:
```sql
\c esmbot
GRANT ALL PRIVILEGES ON guilds TO esmbot;
GRANT ALL PRIVILEGES ON counts TO esmbot;
GRANT ALL PRIVILEGES ON tags TO esmbot;
\q
```

View file

@ -1,2 +1,2 @@
mkdocs-glightbox
mkdocs-glightbox
mkdocs-git-revision-date-localized-plugin

View file

@ -1,237 +1,237 @@
# Setup
Here are some instructions to get esmBot up and running from source.
??? check "Recommended system requirements"
- 64-bit CPU/operating system
- Quad-core CPU or better
- 1GB or more of RAM
- Linux-based operating system or virtual machine ([Ubuntu 22.04 LTS](https://ubuntu.com/download/server) or [Fedora 36](https://getfedora.org/) are recommended)
!!! warning
If you want to run the bot on Windows, [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) is recommended. This guide is somewhat Linux-centric, so for now you're mostly on your own if you decide not to use WSL.
If you have any further questions regarding setup, feel free to ask in the #support channel on the [esmBot Support server](https://esmbot.net/support).
!!! tip
You can run the bot using Docker for a somewhat simpler setup experience. [Click here to go to the Docker setup guide.](https://docs.esmbot.net/docker)
### 1. Install the required native dependencies.
Choose the distro you're using below for insallation instructions.
=== "Debian/Ubuntu"
These instructions apply to Debian version 12 (bookworm) or Ubuntu version 22.04 (jammy) or later.
```sh
sudo apt-get install git curl build-essential cmake ffmpeg sqlite3 ttf-mscorefonts-installer libmagick++-dev libvips-dev libcgif-dev libgirepository1.0-dev fonts-noto-color-emoji libimagequant-dev meson
```
On older Debian/Ubuntu versions, you may need to install some of these packages (notably libcgif-dev and meson) through alternative methods.
=== "Fedora/RHEL"
These instructions apply to Fedora 36/RHEL 9 or later.
Some of these packages require that you add the RPM Fusion and/or EPEL repositories. You can find instructions on how to add them [here](https://rpmfusion.org/Configuration).
```sh
sudo dnf install git curl cmake ffmpeg sqlite gcc-c++ libcgif-devel ImageMagick-c++-devel vips-devel libimagequant-devel gobject-introspection-devel google-noto-emoji-color-fonts meson
```
On RHEL-based distros like AlmaLinux and Rocky Linux, you may need to add [Remi's RPM Repository](https://rpms.remirepo.net) for the vips package.
=== "Alpine"
These instructions apply to the current Edge versions.
```sh
doas apk add git curl msttcorefonts-installer python3 sqlite3 alpine-sdk cmake ffmpeg imagemagick-dev vips-dev font-noto-emoji gobject-introspection-dev cgif-dev libimagequant-dev meson
```
=== "Arch/Manjaro"
```sh
sudo pacman -S git curl cmake pango ffmpeg npm imagemagick libvips sqlite3 libltdl noto-fonts-emoji gobject-introspection libcgif libimagequant meson
```
You'll also need to install [`ttf-ms-win10-auto`](https://aur.archlinux.org/packages/ttf-ms-win10-auto/) from the AUR.
***
### 2. Install libvips.
[libvips](https://github.com/libvips/libvips) is the core of esmBot's image processing commands. Version 8.13.0 or higher is recommended because it contains fixes to GIF handling and support for the freeze command; however, this version isn't packaged for most distros yet. To fix this, you'll need to build libvips from source.
!!! note
Alpine, Arch, RHEL **(not Fedora!)**, and Ubuntu 22.10 (Kinetic Kudu) users can skip this step, since these distros now have 8.13.0 packaged.
First, download the source and move into it:
```sh
git clone https://github.com/libvips/libvips
cd libvips
```
From here, you can set up the build:
```sh
meson setup --prefix=/usr --buildtype=release -Dnsgif=true build
```
If that command finishes with no errors, you can compile and install it:
```sh
cd build
meson compile
sudo meson install
```
***
### 3. Install Node.js.
Node.js is the runtime that esmBot is built on top of. The bot requires version 16 or above to run.
First things first, we'll need to install pnpm, the package manager used by the bot. Run the following to install it:
```sh
curl -fsSL https://get.pnpm.io/install.sh | sh -
```
Once you've done that, continue with the instructions for your operating system below.
=== "Debian/Ubuntu"
You'll need a more recent version than what's provided in most Debian/Ubuntu-based distros. You can add a repository that contains a supported version by running this command:
```sh
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo bash -
```
After that, you can install Node.js with this command:
```sh
sudo apt-get install nodejs
```
=== "Fedora/RHEL"
```sh
sudo dnf install nodejs
```
=== "Alpine"
```sh
doas apk add nodejs
```
=== "Arch/Manjaro"
```sh
sudo pacman -S nodejs
```
***
### 4. Set up the database.
esmBot officially supports two database systems: SQLite and PostgreSQL. While SQLite is smaller and requires no initial setup, PostgreSQL has better performance (especially in large environments).
!!! tip
If you're new to databases and self-hosting, choose SQLite.
If you would like to use the SQLite database, no configuration is needed and you can move on to the next step.
If you would like to use the PostgreSQL database, view the setup instructions [here](https://docs.esmbot.net/postgresql) and come back here when you're finished.
***
### 5. Clone the repo and install the required Node modules.
```sh
cd ~
git clone --recursive https://github.com/esmBot/esmBot
cd esmBot
pnpm i -g node-gyp
pnpm install
pnpm build
```
***
### 6. (Optional) Set up Lavalink.
Lavalink is the audio server used by esmBot for soundboard commands and music playback. If you do not plan on using these features, you can safely skip this step.
!!! warning
There are websites out there providing lists of public Lavalink instances that can be used with the bot. However, these are not recommended due to performance/security concerns and missing features, and it is highly recommended to set one up yourself instead using the steps below.
Lavalink requires a Java (11 or later) installation. You can use [SDKMAN](https://sdkman.io) to install Eclipse Temurin, a popular Java distribution:
```sh
sdk install java 11.0.15-tem
```
Initial setup is like this:
```sh
cd ~
mkdir Lavalink
cd Lavalink
curl -OL https://github.com/freyacodes/Lavalink/releases/latest/download/Lavalink.jar
cp ~/esmBot/application.yml .
ln -s ~/esmBot/assets assets
```
To run Lavalink, you can use this command:
```sh
java -Djdk.tls.client.protocols=TLSv1.2 -jar Lavalink.jar
```
!!! info
You'll need to run Lavalink alongside the bot in order to use it. There are a few methods to do this, such as the `screen` command, creating a new systemd service, or simply just opening a new terminal session alongside your current one.
***
### 7. Configure the bot.
Configuration is done via environment variables which can be specified through a `.env` file. Copy `.env.example` to get a starter config file:
```sh
cp .env.example .env
```
!!! tip
If you can't see either of these files, don't worry - Linux treats files whose names start with a . as hidden files.
To edit this file in the terminal, run this command:
```sh
nano .env
```
This will launch a text editor with the file ready to go. Create a Discord application [here](https://discord.com/developers/applications) and select the Bot tab on the left, then create a bot user. Once you've done this, copy the token it gives you and put it in the `TOKEN` variable.
When you're finished editing the file, press Ctrl + X, then Y and Enter.
An overview of each of the variables in the `.env` file can be found [here](https://docs.esmbot.net/config).
***
### 8. Run the bot.
Once everything else is set up, you can start the bot like so:
```sh
pnpm start
```
If the bot starts successfully, you're done! You can invite the bot to your server by generating an invite link under OAuth -> URL Generator in the Discord application dashboard.
!!! note
You will need to select the `bot` and `applications.commands` scopes.
The following permissions are needed in most cases for the bot to work properly:
<figure markdown>
![Required permissions](assets/permissions.png){ loading=lazy, width=500 }
<figcaption>click to enlarge</figcaption>
</figure>
If you want the bot to run 24/7, you can use the [PM2](https://pm2.keymetrics.io) process manager. Install it using the following command:
```sh
pnpm add -g pm2
```
Once you've done that, you can start the bot using the following command:
```sh
pm2 start ecosystem.config.cjs
```
!!! tip
If you wish to update the bot to the latest version/commit at any time, just run `git pull` and `pnpm install`.
***
## Troubleshooting
??? faq "Error: Cannot find module './build/Release/image.node'"
The native image functions haven't been built. Run `pnpm run build` to build them.
??? faq "`pnpm install` or `pnpm build` fails with error 'ELIFECYCLE Command failed.'"
You seem to be missing node-gyp. This can be fixed by running:
```sh
pnpm i -g node-gyp
rm -rf node_modules
pnpm install
```
??? faq "Error: connect ECONNREFUSED 127.0.0.1:5432"
PostgreSQL isn't running, you should be able to start it with `sudo systemctl start postgresql`. If you don't intend to use PostgreSQL, you should take another look at your `DB` variable in the .env file.
??? faq "Gifs from Tenor result in a "no decode delegate for this image format" or "improper image header" error"
Tenor GIFs are actually stored as MP4s, which libvips can't decode most of the time. You'll need to get a Tenor API key from [here](https://developers.google.com/tenor/guides/quickstart) and put it in the `TENOR` variable in .env.
***
If you have any further questions regarding self-hosting, feel free to ask in the #support channel on the [esmBot Support server](https://esmbot.net/support).
# Setup
Here are some instructions to get esmBot up and running from source.
??? check "Recommended system requirements"
- 64-bit CPU/operating system
- Quad-core CPU or better
- 1GB or more of RAM
- Linux-based operating system or virtual machine ([Ubuntu 22.04 LTS](https://ubuntu.com/download/server) or [Fedora 36](https://getfedora.org/) are recommended)
!!! warning
If you want to run the bot on Windows, [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) is recommended. This guide is somewhat Linux-centric, so for now you're mostly on your own if you decide not to use WSL.
If you have any further questions regarding setup, feel free to ask in the #support channel on the [esmBot Support server](https://esmbot.net/support).
!!! tip
You can run the bot using Docker for a somewhat simpler setup experience. [Click here to go to the Docker setup guide.](https://docs.esmbot.net/docker)
### 1. Install the required native dependencies.
Choose the distro you're using below for insallation instructions.
=== "Debian/Ubuntu"
These instructions apply to Debian version 12 (bookworm) or Ubuntu version 22.04 (jammy) or later.
```sh
sudo apt-get install git curl build-essential cmake ffmpeg sqlite3 ttf-mscorefonts-installer libmagick++-dev libvips-dev libcgif-dev libgirepository1.0-dev fonts-noto-color-emoji libimagequant-dev meson
```
On older Debian/Ubuntu versions, you may need to install some of these packages (notably libcgif-dev and meson) through alternative methods.
=== "Fedora/RHEL"
These instructions apply to Fedora 36/RHEL 9 or later.
Some of these packages require that you add the RPM Fusion and/or EPEL repositories. You can find instructions on how to add them [here](https://rpmfusion.org/Configuration).
```sh
sudo dnf install git curl cmake ffmpeg sqlite gcc-c++ libcgif-devel ImageMagick-c++-devel vips-devel libimagequant-devel gobject-introspection-devel google-noto-emoji-color-fonts meson
```
On RHEL-based distros like AlmaLinux and Rocky Linux, you may need to add [Remi's RPM Repository](https://rpms.remirepo.net) for the vips package.
=== "Alpine"
These instructions apply to the current Edge versions.
```sh
doas apk add git curl msttcorefonts-installer python3 sqlite3 alpine-sdk cmake ffmpeg imagemagick-dev vips-dev font-noto-emoji gobject-introspection-dev cgif-dev libimagequant-dev meson
```
=== "Arch/Manjaro"
```sh
sudo pacman -S git curl cmake pango ffmpeg npm imagemagick libvips sqlite3 libltdl noto-fonts-emoji gobject-introspection libcgif libimagequant meson
```
You'll also need to install [`ttf-ms-win10-auto`](https://aur.archlinux.org/packages/ttf-ms-win10-auto/) from the AUR.
***
### 2. Install libvips.
[libvips](https://github.com/libvips/libvips) is the core of esmBot's image processing commands. Version 8.13.0 or higher is recommended because it contains fixes to GIF handling and support for the freeze command; however, this version isn't packaged for most distros yet. To fix this, you'll need to build libvips from source.
!!! note
Alpine, Arch, RHEL **(not Fedora!)**, and Ubuntu 22.10 (Kinetic Kudu) users can skip this step, since these distros now have 8.13.0 packaged.
First, download the source and move into it:
```sh
git clone https://github.com/libvips/libvips
cd libvips
```
From here, you can set up the build:
```sh
meson setup --prefix=/usr --buildtype=release -Dnsgif=true build
```
If that command finishes with no errors, you can compile and install it:
```sh
cd build
meson compile
sudo meson install
```
***
### 3. Install Node.js.
Node.js is the runtime that esmBot is built on top of. The bot requires version 16 or above to run.
First things first, we'll need to install pnpm, the package manager used by the bot. Run the following to install it:
```sh
curl -fsSL https://get.pnpm.io/install.sh | sh -
```
Once you've done that, continue with the instructions for your operating system below.
=== "Debian/Ubuntu"
You'll need a more recent version than what's provided in most Debian/Ubuntu-based distros. You can add a repository that contains a supported version by running this command:
```sh
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo bash -
```
After that, you can install Node.js with this command:
```sh
sudo apt-get install nodejs
```
=== "Fedora/RHEL"
```sh
sudo dnf install nodejs
```
=== "Alpine"
```sh
doas apk add nodejs
```
=== "Arch/Manjaro"
```sh
sudo pacman -S nodejs
```
***
### 4. Set up the database.
esmBot officially supports two database systems: SQLite and PostgreSQL. While SQLite is smaller and requires no initial setup, PostgreSQL has better performance (especially in large environments).
!!! tip
If you're new to databases and self-hosting, choose SQLite.
If you would like to use the SQLite database, no configuration is needed and you can move on to the next step.
If you would like to use the PostgreSQL database, view the setup instructions [here](https://docs.esmbot.net/postgresql) and come back here when you're finished.
***
### 5. Clone the repo and install the required Node modules.
```sh
cd ~
git clone --recursive https://github.com/esmBot/esmBot
cd esmBot
pnpm i -g node-gyp
pnpm install
pnpm build
```
***
### 6. (Optional) Set up Lavalink.
Lavalink is the audio server used by esmBot for soundboard commands and music playback. If you do not plan on using these features, you can safely skip this step.
!!! warning
There are websites out there providing lists of public Lavalink instances that can be used with the bot. However, these are not recommended due to performance/security concerns and missing features, and it is highly recommended to set one up yourself instead using the steps below.
Lavalink requires a Java (11 or later) installation. You can use [SDKMAN](https://sdkman.io) to install Eclipse Temurin, a popular Java distribution:
```sh
sdk install java 11.0.15-tem
```
Initial setup is like this:
```sh
cd ~
mkdir Lavalink
cd Lavalink
curl -OL https://github.com/freyacodes/Lavalink/releases/latest/download/Lavalink.jar
cp ~/esmBot/application.yml .
ln -s ~/esmBot/assets assets
```
To run Lavalink, you can use this command:
```sh
java -Djdk.tls.client.protocols=TLSv1.2 -jar Lavalink.jar
```
!!! info
You'll need to run Lavalink alongside the bot in order to use it. There are a few methods to do this, such as the `screen` command, creating a new systemd service, or simply just opening a new terminal session alongside your current one.
***
### 7. Configure the bot.
Configuration is done via environment variables which can be specified through a `.env` file. Copy `.env.example` to get a starter config file:
```sh
cp .env.example .env
```
!!! tip
If you can't see either of these files, don't worry - Linux treats files whose names start with a . as hidden files.
To edit this file in the terminal, run this command:
```sh
nano .env
```
This will launch a text editor with the file ready to go. Create a Discord application [here](https://discord.com/developers/applications) and select the Bot tab on the left, then create a bot user. Once you've done this, copy the token it gives you and put it in the `TOKEN` variable.
When you're finished editing the file, press Ctrl + X, then Y and Enter.
An overview of each of the variables in the `.env` file can be found [here](https://docs.esmbot.net/config).
***
### 8. Run the bot.
Once everything else is set up, you can start the bot like so:
```sh
pnpm start
```
If the bot starts successfully, you're done! You can invite the bot to your server by generating an invite link under OAuth -> URL Generator in the Discord application dashboard.
!!! note
You will need to select the `bot` and `applications.commands` scopes.
The following permissions are needed in most cases for the bot to work properly:
<figure markdown>
![Required permissions](assets/permissions.png){ loading=lazy, width=500 }
<figcaption>click to enlarge</figcaption>
</figure>
If you want the bot to run 24/7, you can use the [PM2](https://pm2.keymetrics.io) process manager. Install it using the following command:
```sh
pnpm add -g pm2
```
Once you've done that, you can start the bot using the following command:
```sh
pm2 start ecosystem.config.cjs
```
!!! tip
If you wish to update the bot to the latest version/commit at any time, just run `git pull` and `pnpm install`.
***
## Troubleshooting
??? faq "Error: Cannot find module './build/Release/image.node'"
The native image functions haven't been built. Run `pnpm run build` to build them.
??? faq "`pnpm install` or `pnpm build` fails with error 'ELIFECYCLE Command failed.'"
You seem to be missing node-gyp. This can be fixed by running:
```sh
pnpm i -g node-gyp
rm -rf node_modules
pnpm install
```
??? faq "Error: connect ECONNREFUSED 127.0.0.1:5432"
PostgreSQL isn't running, you should be able to start it with `sudo systemctl start postgresql`. If you don't intend to use PostgreSQL, you should take another look at your `DB` variable in the .env file.
??? faq "Gifs from Tenor result in a "no decode delegate for this image format" or "improper image header" error"
Tenor GIFs are actually stored as MP4s, which libvips can't decode most of the time. You'll need to get a Tenor API key from [here](https://developers.google.com/tenor/guides/quickstart) and put it in the `TENOR` variable in .env.
***
If you have any further questions regarding self-hosting, feel free to ask in the #support channel on the [esmBot Support server](https://esmbot.net/support).