1
1
Fork
You've already forked minecraft-server-telegram-bot
1
A Telegram bot to start/stop Minecraft servers via systemd services.
  • Rust 88.7%
  • Fluent 11.3%
2024年03月05日 21:04:47 +01:00
.idea Rename: remove "-rust" in name. 2022年02月25日 15:44:28 +01:00
locales Fix status message. 2022年12月11日 23:48:01 +01:00
src Update regex to support other server software than Paper. 2024年03月05日 21:04:47 +01:00
systemd-service Introduce regex to sudoers file. Add new user for bot. 2023年03月24日 19:30:37 +01:00
.gitignore Add example bot-config.json 2022年04月05日 00:09:26 +02:00
bot-config.json Update README and bot-config to include information about localisation. 2022年04月10日 17:13:40 +02:00
Cargo.lock Update dependencies. 2024年03月05日 21:03:47 +01:00
Cargo.toml Update dependencies. 2024年03月05日 21:03:47 +01:00
LICENSE Add licence. 2022年04月09日 18:44:52 +02:00
minecraft-server-telegram-bot.iml Rename: remove "-rust" in name. 2022年02月25日 15:44:28 +01:00
README.md Introduce regex to sudoers file. Add new user for bot. 2023年03月24日 19:30:37 +01:00

Minecraft Server Telegram Bot

This software can be used to start and stop Minecraft servers via systemd and get the current status of servers, all using a Telegram bot. It can also mirror the chat messages in Minecraft to a Telegram chat and vice versa.

To be able to use the software, one has to have a setup similar to the one in explained here. Most importantly, the start and stop commands have to have the same structure as mentioned in the explanation. If this is not the case, you will have to edit the command syntax in the source code of this software.

Configuration

The setup is written as a follow-up to the explanation given in this repository. Especially the steps 1 and 3 of the section ‘Setting up the systemd-service’ are necessary.

Compile the project

The software is written in Rust. Since I do not provide any prebuilt binaries yet, you have to compile the software yourself. Hence, the Rust toolchain has to be installed on your device.

Use cargo build --release to compile the software. The compiled binary can be found at target/release/minecraft-server-telegram-bot.

Setting up the bot

  1. Obtain a token from the BotFather. In the following, it is referred to as <token>.
  2. Create a new user for the bot:
# sudo useradd -r -g minecraft -d "/var/minecraft/telegram-bot" -s "/bin/zsh" minecraft-telegram
  1. Create a new folder called /var/minecraft/telegram-bot.
  2. Copy the compiled binary as well as the bot-config.json to that folder and set the rights properly:
# chown -R root:root /var/minecraft/telegram-bot
# chmod 755 /var/minecraft/telegram-bot/minecraft-server-telegram-bot
# semanage fcontext -a -f bin_t '/var/minecraft/telegram-bot/minecraft-server-telegram-bot'
# restorecon -v /var/minecraft/telegram-bot/minecraft-server-telegram-bot
  1. Open the bot-config.json and edit the configuration as follows:
    1. Enter the obtained token.
    2. Enter the RCON password used for your servers.
    3. Edit the locale, if needed. The default is en-UK. All possible locales are listed in the locales directory. Feel free to add new locales! Please have a look at the Contributions section.
    4. Use the chat_server_map to set which chats may control which servers. Enter the chat id on the left, the server name on the right. It must be an n:1 relation, so one chat may control up to one server, but one server may be controlled by many chats. To see how a chat id for a particular chat can be obtained, see here.
  2. Create a new sudoers file using visudo, e.g. using
# visudo -f /etc/sudoers.d/80-minecraft

Then, put

# Allow user minecraft to start and stop systemd service for the minecraft server
minecraft-telegram ALL = NOPASSWD: /usr/bin/systemctl ^(start|is-active|stop) minecraft-server@([a-zA-Z_0-9\.\-]+).service,ドル /usr/bin/journalctl ^-f -u minecraft-server@([a-zA-Z_0-9\.\-]+).service,ドル /usr/bin/journalctl ^-f -n 0 -u minecraft-server@([a-zA-Z_0-9\.\-]+).service$

into this file.

In this sudoers file, regular expressions are used. This is only possible from sudo version 1.9.10 onwards. If your distribution has not received a sudo version ≥ 1.9.10 yet, you can use the legacy method.

Now you can run the server by using

$ sudo -u minecraft-telegram /var/minecraft/telegram-bot/minecraft-server-telegram-bot

You can also install a systemd-service for the bot by copying systemd-service/minecraft-telegram-bot.service to /etc/systemd/system and executing

# systemctl daemon-reload

Legacy sudoers file

# Allow user minecraft-telegram to start and stop systemd service for the minecraft server
minecraft ALL = NOPASSWD: /usr/bin/systemctl start minecraft-server@<name>.service, /usr/bin/systemctl is-active minecraft-server@<name>.service, /usr/bin/systemctl stop minecraft-server@<name>.service, /usr/bin/journalctl -f -u minecraft-server@<name>.service, /usr/bin/journalctl -f -n 0 -u minecraft-server@<name>.service

In this file, <name> should be replaced by the name of your server, the same that you put into the bot-config.json. You will have to add such a line for every server which you want to control using the Telegram bot.

Known issues

  • The project currently lacks proper documentation.

Contribution

I am happy about any contribution you want to make to this project! If you want to do any major contribution, please open an issue before submitting a pull request, so we can coordinate it (so no work is done twice).

Licencing

The software is licenced under the terms of the GNU General Public License, Version 3 or later.

Copyright (C) 2022-2023 Joshua Noeske

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.