Code Monkey home page Code Monkey logo

minecraft-tg's Introduction

minecraft-tg

Bash/python script which links chats in Telegram messenger with in-game chat on Spigot Minecraft server and allows sending commands to Spigot remotely. Optionally you can also create a channel to which the bot will send a message every time someone logs in/out and change chat title to the number of players online.

Every chat message on the Minecraft server is sent to the selected Telegram chat and every message from that chat is sent to the Minecraft server. Another selected chat gets the entire server log sent to it live.

If selected user (admin) starts his message on Telegram with slash, it's sent to the server as a command. Effects of that command can be seen in the chat which gets server log.

Script in action: https://imgur.com/a/yRjor (screenshots outdated a little)

WARNING!

Thais is a very dumb way to do this, but it works for me almost 24/7 since 2018. This should be a Java plugin, but initially I wrote it in only bash (with jq), and later managed to move most of the code to python. There are multiple problems with this approach - it's difficult to set up, inefficient, there are problems with strings, interaction with the console... Don't take this as an example, it's like a duct tape solution.

Usage

First you must make a Telegram bot for your server. It's very easy, no coding required, everything's in the Telegram app. When you're done, start chat with your bot or make a group (and make your bot admin of that group so it can see the messages). Then you must edit tg.sh and put chat IDs and other configuration variables at the start of the file.

Spigot must be run with GNU screen. Screen session must be named "spigot" for tg.sh to work correctly. See file start.sh for the exact command.

You must copy log4j2.xml to your server's directory and change the command you're using to start the server (in start.sh) to something like "java -Dlog4j.configurationFile=log4j2.xml -jar spigot-1.11.2.jar". For information on what it does look here.

Now you can run tg.sh. When you will send message to the bot, it will appear in Spigot with some small delay (usually 0.5-2s).

If you want tg.sh to run automatically with system startup you can use the spigottg.service file.

Files

  • tg.sh - main file, which starts sending messages between Telegram and Spigot when executed

  • config.py - config file with ID's of chats etc

  • serverfiles/spigot.service - example systemd service unit to run spigot with GNU screen when Linux is starting

  • serverfiles/spigottg.service - example systemd service unit to run tg.sh when Linux is starting

Config variables at the start of tg.sh

  • spigot - spigot directory absolute path with slash at the end (tg.sh will make directory "tg" for its files there)

Config variables in config.py

  • token - Telegram bot's token

  • adminUsername - user who will be able to send commands

  • chatID - ID of chat which will get messages from Minecraft (user or group chat)

  • consoleID - ID of chat which will get the entire server log (user or group chat)

  • channelID - username with @ of channel which will get the log in/out messages

Dependencies

To install on Debian-like distros:

sudo apt-get install screen python3.8
pip install requests

Links

minecraft-tg's People

Contributors

oskarkk avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.