WIP: Added stubs for Guilds and fixed formatting

This commit is contained in:
Profitroll 2025-02-18 21:20:14 +01:00
parent 3ffea8b46b
commit 8e2003b7df
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
3 changed files with 19 additions and 10 deletions

View File

@ -14,9 +14,9 @@ class WalletInsufficientFunds(Exception):
"""Wallet's balance is not sufficient to perform the operation""" """Wallet's balance is not sufficient to perform the operation"""
def __init__( def __init__(
self, self,
wallet: "Wallet", wallet: "Wallet",
amount: float, amount: float,
) -> None: ) -> None:
self.wallet = wallet self.wallet = wallet
self.amount = amount self.amount = amount

View File

@ -1,3 +1,12 @@
from dataclasses import dataclass
from bson import ObjectId
@dataclass
class PycordGuild: class PycordGuild:
_id: ObjectId
id: int
def __init__(self) -> None: def __init__(self) -> None:
raise NotImplementedError() raise NotImplementedError()

View File

@ -26,7 +26,7 @@ class Wallet:
# TODO Write a docstring # TODO Write a docstring
@classmethod @classmethod
async def from_id( async def from_id(
cls, owner_id: int, guild_id: int, allow_creation: bool = True cls, owner_id: int, guild_id: int, allow_creation: bool = True
) -> "Wallet": ) -> "Wallet":
db_entry = await col_wallets.find_one( db_entry = await col_wallets.find_one(
{"owner_id": owner_id, "guild_id": guild_id} {"owner_id": owner_id, "guild_id": guild_id}
@ -70,7 +70,7 @@ class Wallet:
@staticmethod @staticmethod
def get_defaults( def get_defaults(
owner_id: Optional[int] = None, guild_id: Optional[int] = None owner_id: Optional[int] = None, guild_id: Optional[int] = None
) -> Dict[str, Any]: ) -> Dict[str, Any]:
return { return {
"owner_id": owner_id, "owner_id": owner_id,
@ -101,13 +101,13 @@ class Wallet:
# TODO Write a docstring # TODO Write a docstring
async def withdraw( async def withdraw(
self, self,
amount: float, amount: float,
allow_overdraft: bool = False, allow_overdraft: bool = False,
overdraft_limit: Optional[float] = None, overdraft_limit: Optional[float] = None,
) -> None: ) -> None:
if amount > self.balance and ( if amount > self.balance and (
not allow_overdraft or (allow_overdraft and amount > overdraft_limit) not allow_overdraft or (allow_overdraft and amount > overdraft_limit)
): ):
raise WalletInsufficientFunds(self, amount) raise WalletInsufficientFunds(self, amount)