|
|
@@ -10,6 +10,13 @@ def hint_quit(): # Hint how to edit the settings and quit
|
|
|
logging.info("")
|
|
|
quit()
|
|
|
|
|
|
+def sql_db_does_not_exis():
|
|
|
+ logging.error("Database does not exist. Doublecheck if it has been created, and the user has access.")
|
|
|
+ quit()
|
|
|
+
|
|
|
+def sql_authentication_error():
|
|
|
+ logging.error("Database autentication failed. Doublecheck username & password, and if the user has been created.")
|
|
|
+ quit()
|
|
|
|
|
|
def missing_config(): # Copy or create settings file if missing
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
@@ -105,13 +112,22 @@ async def main():
|
|
|
)
|
|
|
except AttributeError:
|
|
|
missing_config()
|
|
|
+ except asyncpg.exceptions.InvalidPasswordError:
|
|
|
+ sql_authentication_error()
|
|
|
+ except asyncpg.exceptions.InvalidCatalogNameError:
|
|
|
+ sql_db_does_not_exis()
|
|
|
|
|
|
# Create database pool
|
|
|
await create_db_pool()
|
|
|
|
|
|
# Create database tables if they do not exist
|
|
|
- from query.initialise_database import init_db
|
|
|
- await init_db(bot.pg)
|
|
|
+ from query.initialise_database import init_db, check_db
|
|
|
+ try:
|
|
|
+ await check_db(bot.pg)
|
|
|
+ except asyncpg.exceptions.UndefinedTableError:
|
|
|
+ logging.info("Guild table does not exists, assuming empty database. Populating database...")
|
|
|
+ await init_db(bot.pg)
|
|
|
+
|
|
|
await bot.start(settings.DISCORD_TOKEN)
|
|
|
|
|
|
|
|
|
@@ -122,4 +138,7 @@ except AttributeError:
|
|
|
missing_config()
|
|
|
except discord.errors.LoginFailure:
|
|
|
logging.error("Invalid discord token.")
|
|
|
- correct_setting("DISCORD_TOKEN")
|
|
|
+ correct_setting("DISCORD_TOKEN")
|
|
|
+except KeyboardInterrupt:
|
|
|
+ logging.info("Received keyboard interrupt, exiting...")
|
|
|
+ quit()
|