Modular bot framework for telegram (MBFT for short) allows you to quickly create stable, modular and highly customizable bots
Go to file
dymik739 ec22c72afb core: harden the handling of received messages 2023-10-29 20:56:55 +02:00
modules pingtools: fix leaderboard sorting 2023-10-09 23:48:08 +03:00
.gitignore auto-schedule-pro-v2: add clear option to remove custom setting value and clean up old code remnants 2023-09-12 09:52:38 +03:00
LICENSE add GPLv3 license 2023-05-03 14:04:56 +03:00
README.md Updated README.md 2022-11-06 13:08:15 +02:00
main.py core: harden the handling of received messages 2023-10-29 20:56:55 +02:00
module-testing.py core: fix response dropping when formatting is returned as an empty string 2023-09-21 19:29:53 +03:00

README.md

Modular Bot Framework for Telegram (MBFT)

Modular bot framework for telegram (MBFT for short) allows you to quickly create stable, modular and highly customizable bots. The concept comes from the original project created for Twitch chat that has shown its high stability (it has worked for over 10 months without a single crash). Now it is being rewritten for Telegram to serve many different purposes.

Installing and running the bot

The installation can be easily done by cloning this repository and providing the Telegram bot token using the config/token file. In commands, it is done like this:

# cloning the repo
git clone http://109.86.70.81:3000/dymik739/modular-bot-framework-for-telegram
cd modular-bot-framework-for-telegram/

# creating "config" folder and providing a token
mkdir config/
printf "YOUR_AUTH_TOKEN" > config/token

# running the bot
python3 main.py
# or, using the screen utility:
screen -S mbft python3 main.py

Writing modules (for modVM v1)

To start making your module, you need to create a folder in the modules/ directory and give it a unique name (just like with any other folder). After that, you need to create two files: for code and for metadata.

Firstly, you want to make a file called "meta.json" - it will let the module loader know where you placed your code as well as some other useful metadata. Let's look at a sample meta.json file:

{
    "index_file": index.py, # locates your source code; index.py by default
    "start_on_boot": true, # tells mod loader to start your module automatically; false by default
    "version": 1, # this points to the specific version of modVM your code needs to run; 1 by default
    "alias": "testapp" # adds an alias to your module which can be later specified in control commands
    "predefine": "predefine.py" # locates your predefine code (it is being run only once on module load
}

After that you can start writing your code in the index.py file; every code is different, but there are some generic rules to understand and follow:

  • your code receives message that can be accessed at self.MESSAGE
  • message text can be found at self.MESSAGE.text
  • to send a responce, you need to write a string with responce text to self.RESPONCE
  • you can use modules already available to you (json, codecs); please, try to avoid importing unneccesary modules
  • if you need to access files amd folders in your module dicertory, you can easily do so by using self.path + "filename"; self.path always contains your current folder name
  • please, avoid using time.sleep() in any scenario; modules are syncronous, so usage of this method will stall the entire bot
  • in order to define persistent variables you can set them in your predefine file

If you want to submit your code, please check if it works by testing the output (see "testing" section below); if you want to submit the code for someone to do more work on it, you should set "start_on_boot" to "false" in meta.json file (the same should be done for testing/unstable modules)

Testing modules locally

In order to test the modules/bot offline you can run the module-testing.py file - it behaves just like the bot, but allows you to enter any message, doesn't require Internet connection and bot token. This is a good way to test your modules before publishing them.

It can be used like this:

python3 module-testing.py