A simple plugin system for pyTelegramBotAPI (telebot)
Project description
TeleBot Plugins
A simple plugin system for pyTelegramBotAPI (telebot) that allows you to organize your bot's functionality into separate plugin files without having to redefine the bot instance in each file.
Features
- Load plugins from a specified directory
- Support for both synchronous and asynchronous telebot
- Handle relative paths properly
- Automatically register the bot instance globally
- Support for webhook and polling modes
Installation
pip install telebot-plugins
Usage
Basic Example
from telebot import TeleBot
from telebot_plugins import TelebotWithPlugins
# Create a bot instance
API_TOKEN = "YOUR_BOT_TOKEN"
bot = TeleBot(API_TOKEN)
# Initialize TelebotWithPlugins
plugins = TelebotWithPlugins(
bot=bot,
plugins="plugins", # plugins folder name
exclude=["disabled_plugin.py"] # files to exclude (optional)
)
if __name__ == '__main__':
# Start the bot
bot.polling()
Example Plugin File (plugins/example.py)
from telebot import bot # The bot is automatically available
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "Hello! This is a plugin example.")
Async Bot Example
from telebot.async_telebot import AsyncTeleBot
from telebot_plugins import TelebotWithPlugins
import asyncio
# Create an async bot instance
API_TOKEN = "YOUR_BOT_TOKEN"
bot = AsyncTeleBot(API_TOKEN)
# Initialize TelebotWithPlugins
plugins = TelebotWithPlugins(
bot=bot,
plugins="plugins"
)
if __name__ == '__main__':
# Start the async bot
asyncio.run(bot.polling())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
telebot_plugins-0.1.2.tar.gz
(3.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telebot_plugins-0.1.2.tar.gz.
File metadata
- Download URL: telebot_plugins-0.1.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6de1983ce2b014eb32a61d3b91ed854a4554c4540ad6942abcb43c4f45fa138d
|
|
| MD5 |
d7dd23b6fee3906309c16b275fdd26c9
|
|
| BLAKE2b-256 |
ff9feab04129cbaa8c5be3f77773f714be01d27748284c1800ce25a0529378ef
|
File details
Details for the file telebot_plugins-0.1.2-py3-none-any.whl.
File metadata
- Download URL: telebot_plugins-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f418179ca960b41aa1468bc2af1541e94b67619d6a7f4548015879491b9ec7e0
|
|
| MD5 |
ed41cf2beff17d8eeeb53b71ce61920c
|
|
| BLAKE2b-256 |
c2f049c976b4e6e74b85d631159e36ca07c56e277f99b4170ba937a4011244e7
|