File tree 2 files changed +10
-6
lines changed
2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ def __init__(self):
61
61
self .threads = ThreadManager (self )
62
62
self .session = aiohttp .ClientSession (loop = self .loop )
63
63
self .config = ConfigManager (self )
64
- self .config_ready = asyncio .Event ()
65
64
self .selfhosted = bool (self .config .get ('mongo_uri' ))
66
65
if self .selfhosted :
67
66
self .db = AsyncIOMotorClient (self .config .mongo_uri ).modmail_bot
@@ -178,7 +177,6 @@ async def on_connect(self):
178
177
print (Fore .CYAN + 'Connected to gateway.' )
179
178
180
179
await self .config .refresh ()
181
- self .config_ready .set ()
182
180
183
181
activity_type = self .config .get ('activity_type' )
184
182
message = self .config .get ('activity_message' )
@@ -206,7 +204,7 @@ async def on_ready(self):
206
204
else :
207
205
await self .threads .populate_cache ()
208
206
209
- await self .config_ready . wait () # Wait until config cache is popluated with stuff from db
207
+ await self .config . wait_until_ready () # Wait until config cache is popluated with stuff from db
210
208
211
209
closures = self .config .closures .copy ()
212
210
Original file line number Diff line number Diff line change
1
+ import asyncio
1
2
import os
2
3
import json
3
4
import box
4
5
5
-
6
6
class ConfigManager :
7
7
"""Class that manages a cached configuration"""
8
8
@@ -29,8 +29,11 @@ class ConfigManager:
29
29
def __init__ (self , bot ):
30
30
self .bot = bot
31
31
self .cache = box .Box ()
32
- self ._modified = True
32
+ self .ready_event = asyncio . Event ()
33
33
self .populate_cache ()
34
+
35
+ def __repr__ (self ):
36
+ return repr (self .cache )
34
37
35
38
@property
36
39
def api (self ):
@@ -58,7 +61,6 @@ def populate_cache(self):
58
61
59
62
async def update (self , data = None ):
60
63
"""Updates the config with data from the cache"""
61
- self ._modified = False
62
64
if data is not None :
63
65
self .cache .update (data )
64
66
await self .api .update_config (self .cache )
@@ -67,6 +69,10 @@ async def refresh(self):
67
69
"""Refreshes internal cache with data from database"""
68
70
data = await self .api .get_config ()
69
71
self .cache .update (data )
72
+ self .ready_event .set ()
73
+
74
+ async def wait_until_ready (self ):
75
+ await self .ready_event .wait ()
70
76
71
77
def __getattr__ (self , value ):
72
78
return self .cache [value ]
You can’t perform that action at this time.
0 commit comments