Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit c0ecb86

Browse files
authored
Merge pull request #258 from PyBotDevs/add-shop-tax
Add shop tax calculation and invoice display in `/buy` command
2 parents d5eea11 + 3257173 commit c0ecb86

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cogs/economy.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,20 @@ async def buy(self, ctx: ApplicationContext, name: str, quantity: int=1):
357357
if (currency['wallet'][str(ctx.author.id)] < amt): return await ctx.respond('You don\'t have enough balance to buy this.')
358358
if (shopitem[name]['available'] == False): return await ctx.respond('You can\'t buy this item **dood**')
359359
if (quantity <= 0): return await ctx.respond('The specified quantity cannot be less than `1`!')
360-
currency['wallet'][str(ctx.author.id)] -= int(amt)
360+
tax = 3
361+
taxable_amount = (amt / 100) * tax
362+
rounded_taxable_amount = math.floor(taxable_amount)
363+
total_amount = amt + rounded_taxable_amount
364+
currency['wallet'][str(ctx.author.id)] -= int(total_amount)
361365
items[str(ctx.author.id)][str(name)] += quantity
362366
save()
363-
await ctx.respond(embed=discord.Embed(title=f'You just bought {quantity} {shopitem[name]["stylized name"]}!', description='Thank you for your purchase.', color=discord.Color.green()))
367+
localembed = discord.Embed(
368+
title=f'You just bought {quantity} {shopitem[name]["stylized name"]}!',
369+
description=f"**Your Purchase Invoice**\n\nItem: {quantity} {name.lower()}\n---------------\nBase Amount: {amt} coins\nTax: 3%\nTaxable Amount: {taxable_amount} coins\nTaxable Amount (rounded): {rounded_taxable_amount} coins\n**Charged Amount:** {total_amount} coins",
370+
color=discord.Color.green()
371+
)
372+
localembed.set_footer(text="Thank you for your purchase.")
373+
await ctx.respond(embed=localembed)
364374
except KeyError: await ctx.respond('That item doesn\'t exist.')
365375

366376
@commands.slash_command(

0 commit comments

Comments
 (0)