From: CMDR furrycat Date: Wed, 26 Oct 2016 06:56:32 +0000 (+0100) Subject: Test for plugin on_ready() before trying to run. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=bb44f6c294e94b8e28a7c71d58925393dc474ebc;p=furrycat%2Fcatbot.git Test for plugin on_ready() before trying to run. --- diff --git a/app.py b/app.py index eea831e..d38292c 100644 --- a/app.py +++ b/app.py @@ -2006,8 +2006,7 @@ def on_ready(): log.debug('Maybe unassigning {}'.format(member.name)) yield from set_unassigned(member) if not threads_ready.value: - for plugin in plugins.all(): - asyncio.async(plugin.on_ready()) + plugins.on_ready() asyncio.async(do_announcements()) asyncio.async(maybe_sleep()) threads_ready.value = True diff --git a/db.py b/db.py index e091b4c..5f10c36 100644 --- a/db.py +++ b/db.py @@ -1,4 +1,3 @@ -import asyncio import discord import logging import sqlite3 @@ -173,8 +172,3 @@ class DBConnection(object): def delete_announcement(self, client, id): return self.delete_from_table(client, 'announcements', id) - - @asyncio.coroutine - def on_ready(self): - # Override me. - return diff --git a/plugins/__init__.py b/plugins/__init__.py index 17c0175..75e611a 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -40,3 +40,8 @@ class Plugins(object): def all(self): for name, data in self.loaded.items(): yield data['plugin'] + + def on_ready(self): + for name, data in self.loaded.items(): + if hasattr(data['module'], 'on_ready'): + asyncio.async(data['module'].on_ready())