|
1 | | -Plugins |
2 | | -======= |
| 1 | +Smart Plugins |
| 2 | +============= |
3 | 3 |
|
4 | | -Pyrogram embeds an **automatic** and lightweight plugin system that is meant to further simplify the organization of |
5 | | -large projects and to provide a way for creating pluggable components that can be **easily shared** across different |
| 4 | +Pyrogram embeds a **smart** (automatic) and lightweight plugin system that is meant to further simplify the organization |
| 5 | +of large projects and to provide a way for creating pluggable components that can be **easily shared** across different |
6 | 6 | Pyrogram applications with **minimal boilerplate code**. |
7 | 7 |
|
8 | 8 | Introduction |
9 | 9 | ------------ |
10 | 10 |
|
11 | | -Prior to the plugin system, pluggable handlers were already possible. For instance, if you wanted to modularize your |
12 | | -applications, you had to do something like this... |
| 11 | +Prior to the Smart Plugin system, pluggable handlers were already possible. For example, if you wanted to modularize |
| 12 | +your applications, you had to do something like this... |
13 | 13 |
|
14 | 14 | .. note:: This is an example application that replies in private chats with two messages: one containing the same |
15 | 15 | text message you sent and the other containing the reversed text message (e.g.: "pyrogram" -> "pyrogram" and |
@@ -61,13 +61,15 @@ manually ``import``, manually :meth:`add_handler <pyrogram.Client.add_handler>` |
61 | 61 | :obj:`MessageHandler <pyrogram.MessageHandler>` object because **you can't use those cool decorators** for your |
62 | 62 | functions. So... What if you could? |
63 | 63 |
|
64 | | -Creating Plugins |
65 | | ----------------- |
| 64 | +Using Smart Plugins |
| 65 | +------------------- |
66 | 66 |
|
67 | | -Setting up your Pyrogram project to accommodate plugins is as easy as creating a folder and putting your files full of |
68 | | -handlers inside. |
| 67 | +Setting up your Pyrogram project to accommodate Smart Plugins is as easy as creating a folder and putting your files |
| 68 | +full of handlers inside. |
69 | 69 |
|
70 | | - .. note:: This is the same example application `as shown above <#introduction>`_, written using the plugin system. |
| 70 | + .. note:: |
| 71 | + |
| 72 | + This is the same example application `as shown above <#introduction>`_, written using the Smart Plugin system. |
71 | 73 |
|
72 | 74 | .. code-block:: text |
73 | 75 | :emphasize-lines: 2, 3 |
@@ -104,14 +106,13 @@ handlers inside. |
104 | 106 | Client("my_account").run() |
105 | 107 |
|
106 | 108 | The first important thing to note is the ``plugins`` folder, whose name is default and can be changed easily by setting |
107 | | -the ``plugins_dir`` parameter when creating a :obj:`Client <pyrogram.Client>`; you can put *any python file* in the |
108 | | -plugins folder and each file can contain *any decorated function (handlers)*. Your Pyrogram Client instance (in the |
109 | | -``main.py`` file) will **automatically** scan the folder upon creation to search for valid handlers and register them |
110 | | -for you. |
111 | | - |
112 | | -Then you'll notice you can now use decorators, with only one limitation: within a single plugin file you must use |
113 | | -different names for each decorated function. That's right, you can apply the usual decorators to your callback functions |
114 | | -in a static way, i.e. **without having the Client instance around**: simply use ``@Client`` (Client class) instead of |
115 | | -the usual ``@app`` (Client instance) namespace and things will work just the same. |
| 109 | +the ``plugins_dir`` parameter when creating a :obj:`Client <pyrogram.Client>`; you can put *any python file* in there |
| 110 | +and each file can contain *any decorated function* (handlers) with only one limitation: within a single plugin file you |
| 111 | +must use different names for each decorated function. Your Pyrogram Client instance (in the ``main.py`` file) will |
| 112 | +**automatically** scan the folder upon creation to search for valid handlers and register them for you. |
| 113 | + |
| 114 | +Then you'll notice you can now use decorators. That's right, you can apply the usual decorators to your callback |
| 115 | +functions in a static way, i.e. **without having the Client instance around**: simply use ``@Client`` (Client class) |
| 116 | +instead of the usual ``@app`` (Client instance) namespace and things will work just the same. |
116 | 117 |
|
117 | 118 | The ``main.py`` script is now at its bare minimum and cleanest state. |
0 commit comments