coollsd commited on
Commit
ab5e10b
·
verified ·
1 Parent(s): 73597c3

Create cashapp.py

Browse files
Files changed (1) hide show
  1. cashapp.py +59 -0
cashapp.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ from discord import app_commands
3
+ from discord.ui import Button, View
4
+ from cash import user_cash
5
+
6
+ class PaymentButtons(View):
7
+ def __init__(self, requester: discord.User, amount: int):
8
+ super().__init__(timeout=None)
9
+ self.requester = requester
10
+ self.amount = amount
11
+
12
+ @discord.ui.button(label="Pay", style=discord.ButtonStyle.green)
13
+ async def pay_button(self, interaction: discord.Interaction, button: Button):
14
+ payer_id = interaction.user.id
15
+ if user_cash.get(payer_id, 0) >= self.amount:
16
+ user_cash[payer_id] -= self.amount
17
+ user_cash[self.requester.id] = user_cash.get(self.requester.id, 0) + self.amount
18
+ await interaction.response.send_message(f"You paid ${self.amount:.2f} to {self.requester.name}.")
19
+ await self.requester.send(f"{interaction.user.name} has paid your request of ${self.amount:.2f}.")
20
+ else:
21
+ await interaction.response.send_message("You don't have enough money mf.", ephemeral=True)
22
+
23
+ @discord.ui.button(label="Decline", style=discord.ButtonStyle.red)
24
+ async def decline_button(self, interaction: discord.Interaction, button: Button):
25
+ await interaction.response.send_message(f"You declined the payment request from {self.requester.name}.")
26
+ await self.requester.send(f"{interaction.user.name} has declined your request of ${self.amount:.2f}.")
27
+
28
+ @app_commands.command(name="cashapp", description="Request or pay money to others")
29
+ @app_commands.describe(
30
+ action="Choose 'request' or 'pay'",
31
+ user="The user to request from or pay to",
32
+ amount="The amount of money to request or pay"
33
+ )
34
+ async def cashapp(interaction: discord.Interaction, action: str, user: discord.User, amount: int):
35
+ if action.lower() not in ["request", "pay"]:
36
+ await interaction.response.send_message("invalid. use 'request' or 'pay'.", ephemeral=True)
37
+ return
38
+
39
+ if amount <= 0:
40
+ await interaction.response.send_message("POOR MF IT NEEDS TO BE OVER $0.", ephemeral=True)
41
+ return
42
+
43
+ if action.lower() == "request":
44
+ view = PaymentButtons(interaction.user, amount)
45
+ await user.send(
46
+ f"{interaction.user.name} is requesting ${amount:.2f} from you.",
47
+ view=view
48
+ )
49
+ await interaction.response.send_message(f"Your request for ${amount:.2f} has been sent to {user.name}.")
50
+
51
+ elif action.lower() == "pay":
52
+ payer_id = interaction.user.id
53
+ if user_cash.get(payer_id, 0) >= amount:
54
+ user_cash[payer_id] -= amount
55
+ user_cash[user.id] = user_cash.get(user.id, 0) + amount
56
+ await interaction.response.send_message(f"You paid ${amount:.2f} to {user.name}.")
57
+ await user.send(f"{interaction.user.name} has paid you ${amount:.2f}.")
58
+ else:
59
+ await interaction.response.send_message("you are too poor to make this payment.", ephemeral=True)