From 898d6b4048474d02db220ee540c5d6e3d8cef6fd Mon Sep 17 00:00:00 2001 From: Alec Jensen Date: Sun, 15 Sep 2024 10:09:37 -0500 Subject: [PATCH] fix money duplication glitch --- kidney-bot/cogs/economy.py | 6 ++++++ kidney-bot/utils/kidney_bot.py | 2 +- pyproject.toml | 7 +++++++ requirements.txt | 1 - 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml diff --git a/kidney-bot/cogs/economy.py b/kidney-bot/cogs/economy.py index 62a591f..b2cb6f0 100644 --- a/kidney-bot/cogs/economy.py +++ b/kidney-bot/cogs/economy.py @@ -235,6 +235,8 @@ async def add_currency(self, amount: int, location: str): if location not in ['wallet', 'bank']: raise ValueError( f"Parameter \"location\" must be 'wallet' or 'bank' got: {location}") + + logging.info(f'Adding {amount} beans to {self.user.display_name}\'s {location}') await self.bot.add_currency(self.user, amount, location) @@ -480,6 +482,10 @@ async def pay(self, interaction: discord.Interaction, target: discord.User, amou if int(await profile.wallet()) < amount: await interaction.followup.send('You don\'t have enough beans!', ephemeral=True) return + elif interaction.user.id == target.id: + await interaction.followup.send('You can\'t pay yourself!', ephemeral=True) + return + await profile.add_currency(-amount, 'wallet') await target_profile.add_currency(amount, 'wallet') await interaction.followup.send(f'You paid {amount} beans to {target.mention}') diff --git a/kidney-bot/utils/kidney_bot.py b/kidney-bot/utils/kidney_bot.py index 2f8bf63..786b4cc 100644 --- a/kidney-bot/utils/kidney_bot.py +++ b/kidney-bot/utils/kidney_bot.py @@ -43,7 +43,7 @@ async def setup_hook(self): """Add currency to a user's wallet or bank.""" async def add_currency(self, user: types.AnyUser, value: int, location: str) -> None: - doc: Schemas.Currency = await self.database.currency.find_one({"userID": str(user.id)}, Schemas.Currency) + doc: Optional[Schemas.Currency] = await self.database.currency.find_one({"userID": str(user.id)}, Schemas.Currency) if doc is not None: if location == 'wallet': await self.database.currency.update_one({'userID': str(user.id)}, diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..81f0278 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "kidney-bot" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.12" +dependencies = [] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c73d090..1cb2ce8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ aiohttp~=3.9.5 aiosignal~=1.3.1 -attrs~=23.2.0 beautifulsoup4~=4.12.2 cachetools~=5.3.2 cattrs~=23.2.3