File size: 2,935 Bytes
ab5e10b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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

    @discord.ui.button(label="Pay", style=discord.ButtonStyle.green)
    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)

    @discord.ui.button(label="Decline", style=discord.ButtonStyle.red)
    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}.")

@app_commands.command(name="cashapp", description="Request or pay money to others")
@app_commands.describe(
    action="Choose 'request' or 'pay'",
    user="The user to request from or pay to",
    amount="The amount of money to request or pay"
)
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)