From 1c792f01940d04c4a9cb90fd2d80d6b2951cfa9f Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 10 Oct 2019 13:58:45 +0100 Subject: [PATCH] move PoolHook registrations to start.py --- src/IRCBot.py | 11 +++++------ start.py | 5 ++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/IRCBot.py b/src/IRCBot.py index 8760f610..b1060dbf 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -36,7 +36,7 @@ class ListLambdaPollHook(PollHook.PollHook): class Bot(object): def __init__(self, directory, args, cache, config, database, events, - exports, log, modules, timers, lock_file): + exports, log, modules, timers): self.directory = directory self.args = args self.cache = cache @@ -68,11 +68,7 @@ class Bot(object): self._read_thread = None self._write_thread = None - self._poll_timeouts = [] # typing.List[PollHook] - self._poll_timeouts.append(self._timers) - self._poll_timeouts.append(self.cache) - self._poll_timeouts.append(lock_file) - + self._poll_timeouts = [] # typing.List[PollHook.PollHook] self._poll_timeouts.append(ListLambdaPollHook( lambda: self.servers.values(), lambda server: server.until_read_timeout())) @@ -84,6 +80,9 @@ class Bot(object): self._poll_timeouts.append(ListLambdaPollHook( lambda: self.servers.values(), self._throttle_timeout)) + def add_poll_hook(self, hook: PollHook.PollHook): + self._poll_timeouts.append(hook) + def _throttle_timeout(self, server: IRCServer.Server): if server.socket.waiting_throttled_send(): return server.socket.send_throttle_timeout() diff --git a/start.py b/start.py index 9c000521..270c021d 100755 --- a/start.py +++ b/start.py @@ -106,7 +106,10 @@ modules = ModuleManager.ModuleManager(events, exports, timers, config, log, module_directories) bot = IRCBot.Bot(directory, args, cache, config, database, events, - exports, log, modules, timers, lock_file) + exports, log, modules, timers) +bot.add_poll_hook(cache) +bot.add_poll_hook(lock_file) +bot.add_poll_hook(timers) if args.module: definition = modules.find_module(args.module)