Matthew Dorner's chess plugin for Mattermost makes it easy to play against your friends and colleagues, but has no built-in machine opponent. This simple service built upon Alex Tzonko's bot and Niklas Fiekas' chess library allows you to add any machine opponent that uses the Universal Chess Interface.
- Create a system user on any machine that is always on, and has network access to your Mattermost service.
This can be the same server that Mattermost is on. E.g.:
DHOME=/srv sudo adduser --system --group --shell /bin/bash chessbot
- On the same machine, download and install a UCI chess engine, like Stockfish, to a location that user can access. E.g.:
Ensure you choose a version that works on your CPU. You may need an older Stockfish engine for your system.
wget https://github.com/official-stockfish/Stockfish/releases/latest/download/stockfish-ubuntu-x86-64-avx2.tar tar -xf stockfish-ubuntu-x86-64-avx2.tar --strip-components=1 stockfish/stockfish-ubuntu-x86-64-avx2 sudo install stockfish-ubuntu-x86-64-avx2 /usr/local/bin/stockfish rm stockfish-ubuntu-x86-64-avx2*
- Switch to your new user:
sudo -u chessbot -i cd
- Clone this repo:
git clone https://github.com/Roy-Orbison/mmpychessbot.git cd mmpychessbot/
- Install the python dependencies:
python3 -m venv venv . venv/bin/activate pip3 install chess mmpy-bot
- Copy the example app config file and open it for editing, e.g.:
Change the URL to your Mattermost server's, and copy the team's slug from a URL in its main interface, e.g. the
cp mmpychessbot.conf{.example,} vim mmpychessbot.conf
your-team
inhttps://mattermost.your-domain.example/your-team/channels/town-square
. - In Mattermost's main interface, open the Integrations panel from the ⋮⋮⋮ menu, and add a bot account. It does not require any elevated privileges. Copy the access token it provides you back into the config file, and then save it and close your editor.
- Test the bot by sourcing the environment variables from the config, and running it (assuming the venv is still active), e.g.:
If it starts running okay, switch to Mattermost, and challenge the bot account to a new game. Ctrl + C to terminate the script. Address any config issues until it works.
set -a && . mmpychessbot.conf && set +a python3 mm_chess_bot.py
- Exit the bot account's shell.
- Copy the example service file to
/usr/local/lib/systemd/system/mmpychessbot.service
, adjusting theUser=
and/or file paths in that copy if you chose values different to the above. - Enable and start the service:
sudo systemctl enable --now mmpychessbot
Start games with the bot as you would any other team member. If you can't see the bot account's icon to access its user menu, thus the Challenge User to Chess link, create a DM channel with it.
You can “nudge” it into responding by @
-mentioning its username in a game channel.