Skip to content

Commit

Permalink
fix money duplication glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
alec-jensen committed Sep 15, 2024
1 parent 80e20eb commit 898d6b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions kidney-bot/cogs/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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}')
Expand Down
2 changes: 1 addition & 1 deletion kidney-bot/utils/kidney_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = []
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 898d6b4

Please sign in to comment.