Skip to content

Um boilerplate para bots com suporte a modularização e plugins inteligentes, inspirado nos smart plugins do Pyrogram.

License

Notifications You must be signed in to change notification settings

cleitonleonel/SmartBot

Repository files navigation

SmartBot

SmartBot logo

Um boilerplate para bots com suporte a modularização e plugins inteligentes.

Supported Python Versions


Modular SmartBot é um boilerplate para bots com suporte a modularização e plugins inteligentes, inspirado nos smart plugins do Pyrogram. Ele oferece uma estrutura base para criar bots altamente configuráveis e expansíveis.

🚀 Instalação

Requisitos

  • Python 3.9 ou superior
  • Poetry (opcional, mas recomendado)

Instalando com Poetry

  1. Clone este repositório:

    git clone https://github.com/cleitonleonel/SmartBot.git
    cd SmartBot
  2. Instale as dependências com Poetry:

    poetry install
  3. Ative o ambiente virtual gerenciado pelo Poetry:

    poetry shell

Instalando com pip

  1. Clone este repositório:

    git clone https://github.com/cleitonleonel/SmartBot.git
    cd SmartBot
  2. Instale as dependências com pip:

    pip install -r requirements.txt

🛠️ Como Usar

Configuração Inicial

  1. Renomeie o arquivo de exemplo config_dev.toml para config.toml:

    mv config_dev.toml config.toml
  2. Edite o arquivo config.toml com as informações necessárias, como o token do bot e outras configurações.

Executando o Bot

Com o ambiente configurado, execute o bot com:

python main.py

Estrutura Modular

Os módulos do bot estão localizados no diretório handlers. Cada módulo é carregado automaticamente e segue a estrutura de plugins inteligentes. Você pode criar novos módulos adicionando arquivos Python no diretório handlers.

Exemplo de um plugin básico:

import logging
from telethon import events
from app.utils.base_handler import ClientHandler

logging.basicConfig(level=logging.INFO)

client = ClientHandler()


@client.on(events.NewMessage(pattern='/start'))
async def handle_start(event):
    """
    Handles the `/start` command by sending a greeting message.

    :param event: The event triggered by the `/start` command.
    """
    sender = await event.get_sender()
    sender_id = sender.id
    logging.info(f"Start Handler Triggered by User ID: {sender_id}")
    logging.debug(f"Event Client Instance: {event.client}")

    await event.client.send_message(
        sender_id,
        message=f'Mensagem enviada pelo client: {event.client}',
        buttons=None
    )
    await event.respond(
        message='Resposta enviada por evento.',
        buttons=None
    )
    await event.reply(
        f"Olá, {sender.first_name}! Este é o start handler."
    )

🧩 Smart Plugins

  • Carregue todos os manipuladores de cada módulo, nomeadamente handlers0.py, handlers1.py e handlers2.py em ordem alfabética (arquivos) e ordem de definição (manipuladores dentro de arquivos):
plugins = dict(root="handlers")
  • Carregue apenas manipuladores definidos dentro de handlers.py e handlers0.py, nesta ordem:
from app.bot import Client
plugins = dict(
    root="handlers",
    include=[
        "subfolder2.handlers2",
        "handlers0"
    ]
)
Client("my_account", plugins=plugins).start_service()
  • Carregue tudo, exceto os manipuladores dentro de handlers2.py:
from app.bot import Client
plugins = dict(
    root="handlers",
    exclude=["subfolder2.handlers2"]
)
Client("my_account", plugins=plugins).start_service()
  • Carregue apenas fn3, fn1 e fn2 (nesta ordem) de handlers1.py:
from app.bot import Client
plugins = dict(
    root="handlers",
    include=["subfolder1.handlers1 fn3 fn1 fn2"]
)

Client("my_account", plugins=plugins).start_service()

Adicione o plugin ao diretório handlers e ele será carregado automaticamente.

🧑‍💻 Contribuindo

Contribuições são bem-vindas! Sinta-se à vontade para abrir issues ou pull requests para melhorar este projeto.

📄 Licença

Este projeto está licenciado sob a MIT License.

About

Um boilerplate para bots com suporte a modularização e plugins inteligentes, inspirado nos smart plugins do Pyrogram.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages