Skip to content

Running

Nadyita edited this page May 4, 2022 · 11 revisions

Running the bot

Compatibility

Operating system

Nadybot is tested to run on:

  • Linux 32bit i386
  • Linux ARMv7
  • Linux ARMv8
  • Linux 64bit x86-64
  • Windows 64bit x86-64

It's been reported running on:

  • FreeBSD

PHP

Nadybot requires PHP version 7.4 or newer. It has been tested to work on 7.4 and 8.0 with 32bit and 64bit PHP

Database

Nadybot has been tested to run on the following databases:

  • SQLite 3. Version 3.24.0 or higher is required from version 5.1.0 and later
  • PostgreSQL 9 or later
  • MySQL 5.5, 5.6, 5.7 and 8.0.
  • MariaDB 10.1, 10.2, 10.3, 10.4 and 10.5.

Obtaining the code

There are 2 ways that you can obtain Nadybot:

  • Release Archives (recommended for inexperienced users)
  • Cloning the Repository (recommended for developers).

Release Archives

You can download the latest stable version from link below. If you want the most stable version, choose the latest release. If you want to test some of the newest features, choose an rc, alpha or beta release.

https://github.com/Nadybot/Nadybot/releases

You only need to get the nadybot-bundle-*.zip from the archives, it contains all required libraries.

Cloning The Repository

Alternatively, you can clone the Nadybot git repository. The advantage of doing this is that as new changes are committed you can simply do git pull to pull those changes into your copy. Note that you have the choice between the stable and the unstable brand, so it's up to you if you want features faster or are more after stability. If you are planning on developing on Nadybot, we recommend that you use this method and always work on the unstable branch.

https://github.com/Nadybot/Nadybot.git

Before you are able to run the bot, you need to install the required composer packages:

composer install --no-dev
composer dumpautoload --no-dev

If you don't have composer installed, read up how to get it on https://getcomposer.org/download.

If your org has more than 1000 members

If your org or raid bot has more than 1000 members, you will need to run AOChatProxy in order to support this many buddies. Please set this up first, before you continue with the rest of the bot.

Running Nadybot on Linux

We support running the bot either directly, or in a container via Docker or Podman.

Regular setup without containers

Nadybot requires PHP version 7.4 or higher to run, because we make use of a lot of features that were added in 7.4. If you don't have PHP 7.4 installed, running on Docker might just be your thing.

To start the bot, run the chatbot.sh file. If it is your first time running the bot, it will take you through the configuration wizard to configure the bot. You will need to have a character name that you you want to run the bot as, along with the username and password for the account that has that character.

If you want to run this bot as an org bot, you will also need the exact org name of the org and the character that the bot runs as, will need to already be in the org.

On Linux, you can create a systemd unit file for the bot and have it start on system boot:

[Unit]
Description=My Cool Bot
After=network.target

[Service]
Type=simple
User=the user you want to run this as
ExecStart=/usr/bin/env php \
    /path/to/main.php \
    /path/to/config/config.php
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Note: While it's possible to run the bot as root user, do not do it. Never ever. There is absolutely no need to and you risk exposing your system to bad things, especially when using the webfrontend.

With Docker

Docker is a containerization environment available for Linux. It allows bundling the software with all its dependencies, so you are guaranteed to run a supported version of PHP with all required modules.

It exists on Windows as well, but relies on a Linux VM. Only use it on Linux, otherwise, you'll see huge performance issues.

You can use my pre-made Docker images that I provide at https://quay.io/repository/nadyita/nadybot. Address them as quay.io/nadyita/nadybot

You can then run the bot in test-mode like this:

docker run \
    --rm \
    -it \
    -e CONFIG_LOGIN=myaccount \
    -e CONFIG_PASSWORD=mypassword \
    -e CONFIG_BOTNAME=Mybot \
    -e CONFIG_SUPERADMIN=Myplayer \
    -e CONFIG_DB_TYPE=sqlite \
    -e CONFIG_DB_NAME=testdb \
    -e CONFIG_DB_HOST=/tmp \
    quay.io/nadyita/nadybot:stable

The database in this approach will be fresh on every start (because it's created in /tmp which will be created anew on every container start) and you will expose your bot's password in the process list. Only use this for testing!

A systemd service for this type of configuration, using MariaDB in another docker container as database could look like this:

[Unit]
Description=My Cool Bot
Requires=docker.service
Requires=mariadb.service
After=docker.service

[Service]
Type=simple
ExecStartPre=-/usr/bin/docker stop "%n"
ExecStartPre=-/usr/bin/docker rm -f "%n"
ExecStart=/usr/bin/docker run \
    --rm \
    --name "%n" \
    --env-file /etc/sysconfig/mycoolbot \
    --link mariadb.service:mariadb \
    quay.io/nadyita/nadybot
ExecStop=-/usr/bin/docker stop "%n"
ExecReload=/usr/bin/docker stop "%n"
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

and the corresponding configuration file in /etc/sysconfig/mycoolbot:

CONFIG_LOGIN=myaccountname
CONFIG_PASSWORD=mypassword
CONFIG_ORG=Myorg
CONFIG_SUPERADMIN=Mychar
CONFIG_BOTNAME=Mycoolbot
CONFIG_DIMENSION=5
CONFIG_DB_TYPE=mysql
CONFIG_DB_HOST=mariadb
CONFIG_DB_NAME=my_db_name
CONFIG_DB_USER=my_db_username
CONFIG_DB_PASS=my_db_pass_for_dbuser
#CONFIG_AMQP_SERVER=127.0.0.1
#CONFIG_AMQP_USER=guest
#CONFIG_AMQP_PASSWORD=guest

This prevents passwords from showing up anywhere in the process list, but make sure you set the permissions of this file to 0600, so no one except root can see your password.

This is the recommended way to run the bot, because it allows switching between different versions with ease and guarantees that you meet all requirements.

Alternative systemd unit if you want to use a SQLite database which will be stored in /opt/aodb on the host system:

[Unit]
Description=My Cool Bot
Requires=docker.service
Requires=mariadb.service
After=docker.service

[Service]
Type=simple
ExecStartPre=-/usr/bin/docker stop "%n"
ExecStartPre=-/usr/bin/docker rm -f "%n"
ExecStart=/usr/bin/docker run \
    --rm \
    --name "%n" \
    -v /opt/aodb:/db \
    --env-file /etc/sysconfig/mycoolbot \
    quay.io/nadyita/nadybot
ExecStop=-/usr/bin/docker stop "%n"
ExecReload=/usr/bin/docker stop "%n"
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

and then change the database location in the config file to /db:

CONFIG_LOGIN=myaccountname
CONFIG_PASSWORD=mypassword
CONFIG_ORG=Myorg
CONFIG_SUPERADMIN=Mychar
CONFIG_BOTNAME=Mycoolbot
CONFIG_DIMENSION=5
CONFIG_DB_TYPE=sqlite
CONFIG_DB_HOST=/db
CONFIG_DB_NAME=nadybot

Using the nadybot-big image

Because it can be a bit painful to run AOChatProxy alongside Nadybot in 2 different containers, I created a separate image at quay.io/nadyita/nadybot-big. Again, it comes as :stable and :unstable and it automatically switches on the proxy if you configure it to.

The following general configuration options exist for the image, which correspond to the AOChatProxy settings with the same name:

PROXY_SPAM_BOT_SUPPORT=1/0
PROXY_SEND_TELLS_OVER_MAIN=1/0
PROXY_RELAY_WORKER_TELLS=1/0

PROXY_SPAM_BOT_SUPPORT: toggles support for distributing messages sent via spam over workers. This is used for mass messages as well as raid stuff, etc.

PROXY_SEND_TELLS_OVER_MAIN: will define whether distributing these messages will also use the main client

CONFIG_RELAY_WORKER_TELLS: if set to 1, tells to the workers will be relayed to the bot and commands will be executed. Use this, so people can reply to your workers and don't have to change it to the main char.

Keep in mind, that you still need to enable using the proxy by passing CONFIG_USE_PROXY=1 to the bot!

The proxy needs to define at least 1 worker, on order to activate itself. Workers are defined like this:

PROXY_USERNAME_1=Login
PROXY_PASSWORD_1=PaSSw0rd
PROXY_CHARNAME_1=Botchar1
PROXY_CHARNAME_2=Botchar2
PROXY_CHARNAME_3=Botchar3
PROXY_CHARNAME_4=Botchar4
PROXY_USERNAME_5=Login5
PROXY_PASSWORD_5=PaSSw0rd5
PROXY_CHARNAME_5=Botchar5
PROXY_CHARNAME_6=Botchar6

As you can see, you only need to specify username and login if they differ from the last defined one, hopefully making configuration easy enough, even with lots of workers.

Developing with Containers

Developing the bot using Containers (Docker, Podman, etc.) is very easy. You basically run the container and mount your local checkout over /nadybot.

You don't need PHP or composer installed for this setup since the docker image will already contain everything you need to get started.

Docker

docker run \
    --rm \
    -it \
    -v "$(pwd)":/nadybot \
    -e CONFIG_LOGIN=myaccount \
    -e CONFIG_PASSWORD=mypassword \
    -e CONFIG_BOTNAME=Mybot \
    -e CONFIG_SUPERADMIN=Myplayer \
    -e CONFIG_DB_TYPE=sqlite \
    -e CONFIG_DB_NAME=testdb \
    -e CONFIG_DB_HOST=/tmp \
    quay.io/nadyita/nadybot:unstable

Rootless Podman

podman run \
    --security-opt label=disable \
    --userns keep-id \
    --user "$(id -ur):$(id -gr)" \
    -v "$(pwd)":/nadybot \
    --rm \
    -it \
    -e CONFIG_LOGIN=myaccount \
    -e CONFIG_PASSWORD=mypassword \
    -e CONFIG_BOTNAME=Mybot \
    -e CONFIG_SUPERADMIN=Myplayer \
    -e CONFIG_DB_TYPE=sqlite \
    -e CONFIG_DB_NAME=testdb \
    -e CONFIG_DB_HOST=/tmp \
    quay.io/nadyita/nadybot:unstable

Running on Windows

Main development for Nadybot takes place on Linux, but we recently got some Windows VMs and were able to verify that Nadybot works on Windows. Be careful though, it's not as well-tested as on Linux.

Since Nadybot does not ship PHP due to licensing reasons, we created a PowerShell script to take care of the installation for you. More about that at the bottom of the page.

Keep in mind that if you are under Windows, some things might not work. Sometimes this is due to PHP's limits on Windows, but sometimes, we can work around that. So please contact us if you're having issues or are missing an essential feature and we might be able to fix them.

Installing PHP

If you do not have PHP 7.4 or later installed, we advise you to either download it manually or run the PowerShell script that does it for you. All you need to do in that case is open the Nadybot folder, right click on the install-php.ps1 and choose "Run with PowerShell". Wait and then confirm the blinking Visual C++ install manually.

Nadybot Windows PHP Installer

Starting the bot

Nadybot ships a chatbot.bat file that you can double click to start the bot once (as seen at the end of the GIF) and a chatbot-loop.bat that does essentially the same, but will restart the bot infinitely.