From 7fb3f7aad2b64a3901dffa5e3cf99b70cb7227da Mon Sep 17 00:00:00 2001 From: Raiden Date: Tue, 9 May 2023 18:32:23 +0800 Subject: [PATCH] Pull modmail-dev/modmail#3279 --- core/clients.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/clients.py b/core/clients.py index f504b7051d..9c6a0f3256 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') or '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') or '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(