-
-
Notifications
You must be signed in to change notification settings - Fork 964
New command structure #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What I've been thinking about in terms of Commands, is how a user can totally define his/her own ones, removing the existing ones the library brings along. Let me illustrate with an example: Ok, I create a new directory with those commands in them and add it as a commands directory, fine. Also, I want to provide an How would I do this with the current library without touching any library code? |
I think that we should implement a method that let you enable/disable certain commands during the setup. Then when you include a new dir of commands you can overwrite a present one if they have the same name |
It would be really cool to be able to implement something like the hooks that WordPress uses. Given the example here, there would be a hook to set the command directories. This way a user could easily "hook into" the Telegram class and set / unset any custom command directories. The same method could be applied to enable / disable a list of commands. About simply overriding existing commands, that's how it works at the moment already! 😃 All command related methods need some tweaking to simplify it all and make sure that they all have the same data to work with. At the moment |
After thinking about this in more depth and looking at how the commands are currently handled, here are my current view on how I would change it. I'm obviously looking at implementing the most flexible solution, making it easy to override commands and add / remove command directories with ease. New file structure (for the core library):
All commands extend a specific class, namely:
All these commands can be overridden by the user, by adding custom command directories and defining them as the same command names. If an Admin and User command have the same name, it depends if the user is an admin or not. If yes, the Admin command is used, if not, the normal User one is used. When fetching the command list, it also depends if we're an admin or not. This is used by the
Does this make sense so far? I'm sure more things will come up as I go along and explore. Any feedback and suggestions are very welcome, thanks 😃 |
I took a look at the code! Great work! /start command should be considered a users commad or a sys one? |
I haven't looked at making it fit the current tests yet, as some tests will probably need to change a bit anyway. Also, I'll be writing new tests for the new structure 😃
If somebody wants to add their own message, they can just override the class 😊 |
I fix some autoload problems, now here it works properly for InlineQueryCommand: We should decide if the abstract command have to stay in the same directory with other commands or not. Some tips for autoloading:
|
I don't fully understand what you mean by this. The whole reason to separate the different command types is to enforce certain access and functionality, giving the user a simple way to add custom commands. If I understand you correctly, users should be able to make their own abstract At the moment, with the way it works right now, this is not possible as we only allow 1 layer, so custom user commands must extend our existing abstract classes directly. How do you suggest we implement this (users making their own abstract classes)? Regarding the namespaces and the abstract class files in the command directories, I'm not sure if it makes sense to prefix all abstract classes with What we could do though, is restructure the files a bit: So we would have these abstract classes: On top of that, we should really consider having a What are you thoughts? (P.S. Sorry for the long message, hope it all kind of makes sense) |
In my bot i created an extension of the command class and all the command Inherit from my custom class. This was useful because you can share function ecc. I would remove Abstract from of the class too. Sounds good to put a commander or command bus class to menage everything about commands! |
So you extend the abstract 👍 Ok, will remove the "Abstract" from all of them and move them up a folder. |
I think that with this new model i will have to create MyCommadBasic extension of Systemcommand (for example) and create my own commad extension of MyCommadBasic. |
You're right, let's continue with the alpha and then take another view. |
A few bigger changes have been made to the inner workings of the commands, here's a list to explain the main ones so far. As always, feel free to comment, ask question, discuss, etc. 😃 Command return value 🔍
Remember last executed command response 🔍The response of the last command that was executed when processing the updates from Telegram (via Custom command overriding 🔍When adding custom commands, they override any existing commands with the same name. If multiple custom command folders get added, if they contain the same command, the last one "wins". Let me try to explain this overriding process a bit more using the
On top of this, Admin commands take preference over User commands. So if we have a |
@MBoretto @akalongman Also, before refactoring the |
I checked the code and everything works fine, i also try custom commands in separate folder! Merged |
The discussion on refactoring the Closing here... |
As @noplanman suggest in a comment commands structure can move to this configuration:
Copied form @noplanman commet:
In my mind (as far as I've understood the different commands so far), there should be 3 different kinds of commands:
Executed by the library / internal system
Executed by the Admins
Executed by the Users (& Admins obviously)
This way, we could separate these different commands more easily, as they have their own specific way of being executed. I see at the moment that many commands do pretty much the same thing, but each one uses lots of identical code, which really should be optimised.
Yes I saw that @ public vs. private. I think public should be the ones all Users can execute and private the ones only Admins can.
I haven't looked deeper into this, but maybe adding an extra layer could help out a lot:
(my opinion)
In this way we can remove the public var ad show them according to the division
Lets start the discussion!
The text was updated successfully, but these errors were encountered: