run: pass app instance to EventDispatcher

this should help with future DM channel pub/sub, as we'll
have to query the `dm_channel_state` table.
This commit is contained in:
Luna Mendes 2018-10-11 16:52:15 -03:00
parent b43b220882
commit b7f0bd1bb4
3 changed files with 6 additions and 4 deletions

View File

@ -11,8 +11,9 @@ log = Logger(__name__)
class EventDispatcher: class EventDispatcher:
"""Pub/Sub routines for litecord.""" """Pub/Sub routines for litecord."""
def __init__(self, sm): def __init__(self, app):
self.state_manager = sm self.state_manager = app.state_manager
self.app = app
self.backends = { self.backends = {
'guild': GuildDispatcher(self), 'guild': GuildDispatcher(self),

View File

@ -11,6 +11,7 @@ class Dispatcher:
def __init__(self, main): def __init__(self, main):
self.main_dispatcher = main self.main_dispatcher = main
self.sm = main.state_manager self.sm = main.state_manager
self.app = main.app
async def sub(self, _key, _id): async def sub(self, _key, _id):
raise NotImplementedError raise NotImplementedError

4
run.py
View File

@ -93,9 +93,9 @@ async def app_before_serving():
g.loop = asyncio.get_event_loop() g.loop = asyncio.get_event_loop()
app.state_manager = StateManager() app.state_manager = StateManager()
app.dispatcher = EventDispatcher(app.state_manager)
app.storage = Storage(app.db) app.storage = Storage(app.db)
app.dispatcher = EventDispatcher(app)
app.presence = PresenceManager(app.storage, app.presence = PresenceManager(app.storage,
app.state_manager, app.dispatcher) app.state_manager, app.dispatcher)
app.storage.presence = app.presence app.storage.presence = app.presence