From 71fbcad502fe42e742ea3153ce312df982f1d2ef Mon Sep 17 00:00:00 2001 From: Nadie Date: Wed, 12 Apr 2023 16:35:30 -0400 Subject: [PATCH 1/3] Custom database name Check to see if mongo_url has a database given if not use the default 'modmail_bot' --- core/clients.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/clients.py b/core/clients.py index f504b7051d..f29606b57e 100644 --- a/core/clients.py +++ b/core/clients.py @@ -10,6 +10,7 @@ from aiohttp import ClientResponseError, ClientResponse from motor.motor_asyncio import AsyncIOMotorClient from pymongo.errors import ConfigurationError +from pymongo.uri_parser import parse_uri from core.models import InvalidConfigError, getLogger @@ -445,7 +446,8 @@ def __init__(self, bot): raise RuntimeError try: - db = AsyncIOMotorClient(mongo_uri).modmail_bot + database = parse_uri(mongo_uri).get('database') if parse_uri(mongo_uri).get('database') else 'modmail_bot' + db = AsyncIOMotorClient(mongo_uri)[database] except ConfigurationError as e: logger.critical( "Your MongoDB CONNECTION_URI might be copied wrong, try re-copying from the source again. " @@ -497,7 +499,8 @@ async def validate_database_connection(self, *, ssl_retry=True): 'run "Certificate.command" on MacOS, ' 'and check certifi is up to date "pip3 install --upgrade certifi".' ) - self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True).modmail_bot + database = parse_uri(mongo_uri).get('database') if parse_uri(mongo_uri).get('database') else 'modmail_bot' + self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True)[database] return await self.validate_database_connection(ssl_retry=False) if "ServerSelectionTimeoutError" in message: logger.critical( From 284376d3b3077ec928925ad6f824746884b878bd Mon Sep 17 00:00:00 2001 From: August Date: Fri, 14 Apr 2023 13:42:35 -0400 Subject: [PATCH 2/3] Update core/clients.py Co-authored-by: Raiden Signed-off-by: August --- core/clients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/clients.py b/core/clients.py index f29606b57e..6036bac06a 100644 --- a/core/clients.py +++ b/core/clients.py @@ -446,7 +446,7 @@ def __init__(self, bot): raise RuntimeError try: - database = parse_uri(mongo_uri).get('database') if parse_uri(mongo_uri).get('database') else 'modmail_bot' + database = parse_uri(mongo_uri).get('database') or 'modmail_bot' db = AsyncIOMotorClient(mongo_uri)[database] except ConfigurationError as e: logger.critical( From c88b203c18195db0436583292eefc4d7ca7e9f31 Mon Sep 17 00:00:00 2001 From: August Date: Fri, 14 Apr 2023 13:42:43 -0400 Subject: [PATCH 3/3] Update core/clients.py Co-authored-by: Raiden Signed-off-by: August --- core/clients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/clients.py b/core/clients.py index 6036bac06a..9c6a0f3256 100644 --- a/core/clients.py +++ b/core/clients.py @@ -499,7 +499,7 @@ async def validate_database_connection(self, *, ssl_retry=True): 'run "Certificate.command" on MacOS, ' 'and check certifi is up to date "pip3 install --upgrade certifi".' ) - database = parse_uri(mongo_uri).get('database') if parse_uri(mongo_uri).get('database') else 'modmail_bot' + database = parse_uri(mongo_uri).get('database') or 'modmail_bot' self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True)[database] return await self.validate_database_connection(ssl_retry=False) if "ServerSelectionTimeoutError" in message: