fix: Rename _on_command of BaseModule

This commit is contained in:
PapaTutuWawa 2021-06-13 19:34:05 +02:00
parent 3b2b89061b
commit ee96e79f34
2 changed files with 11 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class MiraBot:
def _initialise_modules(self):
for module in self._config['modules']:
logger.debug("Initialising module %s" % (module))
logger.debug("Initialising module %s" % (module['name']))
mod = importlib.import_module(module['name'])
self._modules[mod.NAME] = mod.get_instance(self, config=module, name=mod.NAME)
@ -117,7 +117,7 @@ class MiraBot:
' module that is restricted to whitelisted users only')
return
self._modules[cmd[0]]._on_command(cmd[1:], message)
self._modules[cmd[0]].__on_command(cmd[1:], message)
# Module Function: Send message
def send_message(self, message):

View File

@ -16,10 +16,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import asyncio
from functools import partial
import logging
from mira.storage import StorageManager
from mira.subscription import SubscriptionManager
logger = logging.getLogger('mira.module')
class ManagerWrapper:
'''
Wrapper class around {Storage, Subscription}Manager in order
@ -52,6 +55,8 @@ class BaseModule:
self._stm = ManagerWrapper(self._name, StorageManager)
self._sum = ManagerWrapper(self._name, SubscriptionManager)
logger.debug('Init of %s done' % (self._name))
def get_option(self, key, default=None):
'''
@ -69,11 +74,13 @@ class BaseModule:
'''
self._base.send_message_wrapper(to, body)
def _on_command(self, cmd, msg):
def __on_command(self, cmd, msg):
def run(func):
loop = asyncio.get_event_loop()
loop.create_task(func(cmd, msg))
logger.debug('Received command: %s' % (str(cmd)))
if not self._subcommand_table:
run(self.on_command)
elif cmd and cmd[0] in self._subcommand_table: