Skip to content

Commit

Permalink
Now sorting plugins according to their order ( default 0 )
Browse files Browse the repository at this point in the history
  • Loading branch information
Mydayyy committed Sep 17, 2017
1 parent 45e610e commit c2d8f76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Bot/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, ip, port=10011, user=None, password=None, virtual_server_id=N
self._queryTracker = Bot.QueryManager.QueryTracker()

self._slaves = {} # cid: slave_instance
self._pluginList = []
self._plugin_list = []
self._command_prefix = config.get_value("command_prefix")

self._lastLine = ""
Expand Down Expand Up @@ -119,7 +119,11 @@ def _setup_plugins(self):
available_classes = inspect.getmembers(imported_plugins, inspect.isclass)
for classes in available_classes:
if classes[0].endswith("Plugin"):
self._pluginList.append(getattr(imported_plugins, classes[0])(self))
self._plugin_list.append(getattr(imported_plugins, classes[0])(self))

self._plugin_list = sorted(self._plugin_list, key=lambda plugin: plugin.order)

pass

def _init_networking(self, ip, port):
"""!
Expand Down Expand Up @@ -277,7 +281,7 @@ def _call_method_on_all_plugins(self, method_name, *args):
@return None
"""

for plugin in self._pluginList:
for plugin in self._plugin_list:
getattr(plugin, method_name)(*args)

def _call_callbacks(self, event, event_type):
Expand Down
1 change: 1 addition & 0 deletions Bot/Plugins/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class PluginBase:
def __init__(self, bot_instance):
self.bot_instance = bot_instance
self.CommandResults = CommandResults
self.order = 0

def on_initial_data(self, client_list, channel_list):
pass
Expand Down
3 changes: 3 additions & 0 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ TEMPLATE_RELATIONS = NO
DOT_GRAPH_MAX_NODES = 100
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = YES

SORT_MEMBER_DOCS = YES
GENERATE_TREEVIEW = NO
2 changes: 2 additions & 0 deletions doc/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Every plugin should be its own file in Bot/Plugins. The bot will load all classes which end with "Plugin". The file should import `PluginBase` from `Bot.Plugins.Base` and the class should inherit the imported `PluginBase`. Further, the class needs to provide a `__init__` method which takes one argument, the `bot_instance` and calls the parents `__init__` method with that argument. Also, all your classes which are supposed to get loaded by the teamspeakbot need to end in `Plugin`. E.g `HelpPlugin` or `AutoKickPlugin`.

You can influence the order in which your plugin will receive callbacks by overwriting self.order in inside your plugins init method. Plugins will be sorted according to the order, meaning that with a lower order your plugin will get called before plugins with a higher order. This is useful if you need to manipulate the event object. The default order set in the PluginBase is 0.

Most minimal plugin setup:

```Python
Expand Down

0 comments on commit c2d8f76

Please sign in to comment.