Comments (4)
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.
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.
Hmmm, what if we clone the blueprints system from flask? 🤔
from aiotg.
My approach is:
Have the main Bot instance in main.py
, where here we have 2 things happen.
- act as the modules listing, or main menu
- 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)
- Old GET/POST API
- Issue with session HOT 21
- Closing Session HOT 1
- Option to send chat action automatically. HOT 1
- Bump new release HOT 1
- AttributeError: module 'aiohttp' has no attribute 'post' HOT 1
- Missing data in CallbackQuery HOT 1
- Additional callback_query data in CallbackQuery __init__ HOT 6
- Argument "disable_notification" not working for send_photo method HOT 2
- Add conversation support HOT 1
- group_chat_created not in list of supported messages
- README fix HOT 1
- KeyError when processing the callback handler of an inline message HOT 2
- Dead link to telegram chat in readme HOT 1
- Handle text and commands at the same time HOT 2
- Add support for new_chat_members
- aiosocksy is deprecated and archived HOT 1
- Webhook mode doesn't work on aiohttp >= 3.8
- Log error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiotg.