1
0
Fork 0
mirror of synced 2024-05-03 12:12:31 +12:00

Ensure database exists before loading it

This commit is contained in:
phxntxm 2019-01-29 17:37:13 -06:00
parent d950c458ef
commit e239194636
2 changed files with 6 additions and 4 deletions

3
bot.py
View file

@ -106,8 +106,7 @@ if __name__ == '__main__':
# Setup our bot vars, db and cache
bot.db = utils.DB()
bot.cache = utils.Cache(bot.db)
# Start our startup tasks
bot.loop.create_task(bot.db.setup())
# Start our startup task (cache sets up the database, so just this)
bot.loop.create_task(bot.cache.setup())
for e in utils.extensions:
bot.load_extension(e)

View file

@ -17,6 +17,9 @@ class Cache:
self.restrictions = defaultdict(dict)
async def setup(self):
# Make sure db is setup first
await self.db.setup()
await self.load_prefixes()
await self.load_custom_permissions()
await self.load_restrictions()
@ -34,8 +37,8 @@ WHERE
"""
rows = await self.db.fetch(query)
for row in rows:
self.ignored[row['guild']]['members'] = row['ignored_members']
self.ignored[row['guild']]['channels'] = row['ignored_channels']
self.ignored[row['id']]['members'] = row['ignored_members']
self.ignored[row['id']]['channels'] = row['ignored_channels']
async def load_prefixes(self):
query = """