88import traceback
99from pathlib import Path
1010
11- from typing import Tuple , Dict , Any , Type , Set , List , Optional
11+ from typing import Tuple , Dict , Any , Type , Set , List , Optional , Callable
1212
1313from errbot .flow import BotFlow , Flow
1414from errbot .repo_manager import BotRepoManager , check_dependencies
@@ -135,11 +135,22 @@ def __init__(self,
135135 extra_plugin_dir : Optional [str ],
136136 autoinstall_deps : bool ,
137137 core_plugins : Tuple [str , ...],
138+ plugin_instance_callback : Callable [[str , Type [BotPlugin ]], BotPlugin ],
138139 plugins_callback_order : Tuple [Optional [str ], ...]):
140+ """
141+ Creates a Plugin manager
142+ :param storage_plugin: the plugin used to store to config for this manager
143+ :param repo_manager: the repo manager
144+ :param extra_plugin_dir: an extra directory to search for plugins
145+ :param autoinstall_deps: if True, will install also the plugin deps from requirements.txt
146+ :param core_plugins: the list of core plugin that will be started
147+ :param plugin_instance_callback: the callback to instantiate a plugin (to inject the dependency on the bot)
148+ :param plugins_callback_order: the order on which the plugins will be callbacked
149+ """
139150 super ().__init__ ()
140- self .bot = None
141151 self .autoinstall_deps = autoinstall_deps
142152 self ._extra_plugin_dir = extra_plugin_dir
153+ self ._plugin_instance_callback = plugin_instance_callback
143154 self .core_plugins = core_plugins
144155 # Make sure there is a 'None' entry in the callback order, to include
145156 # any plugin not explicitly ordered.
@@ -156,9 +167,6 @@ def __init__(self,
156167 if CONFIGS not in self :
157168 self [CONFIGS ] = {}
158169
159- def attach_bot (self , bot ):
160- self .bot = bot
161-
162170 def get_plugin_obj_by_name (self , name : str ) -> BotPlugin :
163171 return self .plugins .get (name , None )
164172
@@ -233,7 +241,7 @@ def _load_plugins_generic(self,
233241
234242 # instantiate the plugin object.
235243 _ , clazz = plugin_classes [0 ]
236- dest_dict [name ] = clazz ( self .bot , name )
244+ dest_dict [name ] = self ._plugin_instance_callback ( name , clazz )
237245
238246 except Exception :
239247 feedback [path ] = traceback .format_exc ()
0 commit comments