Code Monkey home page Code Monkey logo

Comments (4)

derfenix avatar derfenix commented on August 15, 2024 2

I think it is not a good idea. Your library is a flat and clean async binding for Telegram's API and should stay so. Plugins is the application's responsibility area, not library's.
That's just my opinion 😄

from aiotg.

szastupov avatar szastupov commented on August 15, 2024 1

To be honest I was thinking about something simpler. There is Errbot and I don't want to compete with them.

So my first goal is to let users create reusable commands, something like this (just a draft, not a final API):

from aiotg import plugin

@plugin.command(r"/echo (.+)")
def echo(bot, chat, match):
    return chat.reply(match.group(1))

Then users can can import specific module and it will register itself. We can add optional autoloading from a folder as well. Note that I would like to keep namespace global and not impose any naming convention.

Enabling disabling modules from bot is another goal, but I'd rather implement it as bot API and then create a text interface as a "plugin manager" plugin.

from aiotg.

szastupov avatar szastupov commented on August 15, 2024 1

Hmmm, what if we clone the blueprints system from flask? 🤔

from aiotg.

bliz937 avatar bliz937 commented on August 15, 2024

My approach is:

Have the main Bot instance in main.py, where here we have 2 things happen.

  1. act as the modules listing, or main menu
  2. Get and send off updates to relevant modules.

main.py loads the modules from a specified directory, and each module having its own Bot instance.
When loading the modules, set the API key, name, etc in the module's Bot instance.
Each module has its own entry command, and this gets copied to a command array. Once all the modules are loaded, prepend the command array to each module Bot instance - the _commands variable.

Extract and modify the following methods from bot.py and put them in main.py:
loop and _process_updates.

Extract loop so that we call this function in main.py and not the Bot instance in main.py.
Extract and modify _process_updates to set the _offset and pass the update to the relevant module.

Then from a user point of view, message the bot.
First the Bot in main.py will process the message, since the user hasn't entered a module, and display a list of installed modules. Once a user goes into a module, each subsequent request from that user gets passed into the _process_updates of the module's Bot instance.

This is a rough approach of my implementation.

from aiotg.

Related Issues (20)

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.