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.3.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.3.tar.gz.
File metadata
- Download URL: telebot_plugins-0.1.3.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 |
d2a6585709e83350c56c40886e5dc912104a9ffa3c59a083fce4970baf564afc
|
|
| MD5 |
2e73df1a98dcce203a8f3081afce04df
|
|
| BLAKE2b-256 |
e89957077176e73a314b0d67c0b82bd85cb98bbc60906007928b6670478f3762
|
File details
Details for the file telebot_plugins-0.1.3-py3-none-any.whl.
File metadata
- Download URL: telebot_plugins-0.1.3-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 |
0c7100baf726bab5d4a863ba7bc6f0be6eb35a4e5a7e7965521697e4f7f2e197
|
|
| MD5 |
1a0aadf0d61a1bb9bb67514254e345c3
|
|
| BLAKE2b-256 |
b6f3f498dabe649f16fd914be870c48558046ce97f77ffbd5639cc44a11e860d
|