Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Update config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TurnrDev authored Oct 16, 2023
1 parent fa052a2 commit 6602e84
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions trainerdex/discord_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,7 @@ def _get_collection(self, collection: str) -> Collection:
return self.database[collection]

async def get_global(self, *, create: bool = True) -> GlobalConfig:
data: MutableMapping = await self._get_collection("global").find_one(
{"_id": StaticDocuments.GLOBAL_CONFIG.value}
)

if data is None and create:
document: GlobalConfig = GlobalConfig(_id=StaticDocuments.GLOBAL_CONFIG.value)
self._get_collection("global").insert_one(asdict(document))
data: MutableMapping = await self._get_collection("global").find_one(
{"_id": StaticDocuments.GLOBAL_CONFIG.value}
)
elif data is None and not create:
raise ValueError("No entry found.")
return GlobalConfig.from_mapping(data)
return GlobalConfig()

async def get_module_metadata(self, module: Module | type[Module], create: bool = True) -> ModuleMeta:
from trainerdex.discord_bot.modules.base import Module
Expand Down Expand Up @@ -153,8 +141,7 @@ async def get_member(
return MemberConfig.from_mapping(data)

async def set_global(self, document: GlobalConfig):
data: MutableMapping = asdict(document)
await self._get_collection("global").update_one({"_id": document._id}, {"$set": data}, upsert=True)
pass

async def set_module_metadata(self, document: ModuleMeta):
data: MutableMapping = asdict(document)
Expand Down

0 comments on commit 6602e84

Please sign in to comment.