Spaces:
Building
Building
import discord | |
from discord import app_commands | |
from discord.ui import Button, View | |
from cash import user_cash | |
class PaymentButtons(View): | |
def __init__(self, requester: discord.User, amount: int): | |
super().__init__(timeout=None) | |
self.requester = requester | |
self.amount = amount | |
async def pay_button(self, interaction: discord.Interaction, button: Button): | |
payer_id = interaction.user.id | |
if user_cash.get(payer_id, 0) >= self.amount: | |
user_cash[payer_id] -= self.amount | |
user_cash[self.requester.id] = user_cash.get(self.requester.id, 0) + self.amount | |
await interaction.response.send_message(f"You paid ${self.amount:.2f} to {self.requester.name}.") | |
await self.requester.send(f"{interaction.user.name} has paid your request of ${self.amount:.2f}.") | |
else: | |
await interaction.response.send_message("You don't have enough money mf.", ephemeral=True) | |
async def decline_button(self, interaction: discord.Interaction, button: Button): | |
await interaction.response.send_message(f"You declined the payment request from {self.requester.name}.") | |
await self.requester.send(f"{interaction.user.name} has declined your request of ${self.amount:.2f}.") | |
async def cashapp(interaction: discord.Interaction, action: str, user: discord.User, amount: int): | |
if action.lower() not in ["request", "pay"]: | |
await interaction.response.send_message("invalid. use 'request' or 'pay'.", ephemeral=True) | |
return | |
if amount <= 0: | |
await interaction.response.send_message("POOR MF IT NEEDS TO BE OVER $0.", ephemeral=True) | |
return | |
if action.lower() == "request": | |
view = PaymentButtons(interaction.user, amount) | |
await user.send( | |
f"{interaction.user.name} is requesting ${amount:.2f} from you.", | |
view=view | |
) | |
await interaction.response.send_message(f"Your request for ${amount:.2f} has been sent to {user.name}.") | |
elif action.lower() == "pay": | |
payer_id = interaction.user.id | |
if user_cash.get(payer_id, 0) >= amount: | |
user_cash[payer_id] -= amount | |
user_cash[user.id] = user_cash.get(user.id, 0) + amount | |
await interaction.response.send_message(f"You paid ${amount:.2f} to {user.name}.") | |
await user.send(f"{interaction.user.name} has paid you ${amount:.2f}.") | |
else: | |
await interaction.response.send_message("you are too poor to make this payment.", ephemeral=True) | |