Advertisement
Guest User

Untitled

a guest
Feb 11th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. @bot.command(
  2.     type=interactions.ApplicationCommandType.CHAT_INPUT,
  3.     name="buy",
  4.     scope=934127207872331787,
  5.     description="buy a stock",
  6.     options=[interactions.Option(
  7.         type=interactions.OptionType.STRING,
  8.         name="symbol",
  9.         description="symbol of stock",
  10.         autocomplete=True,
  11.         required =True
  12.     )]
  13. )
  14. async def buy(ctx, symbol):
  15.     pr = h.price(symbol)
  16.     try:
  17.         data = check(int(ctx.author.user.id))
  18.     except:
  19.         await ctx.send("This stock doesnt exist")
  20.         return
  21.     am = int(str(data["wallet"]/float(pr)).split(".")[0])
  22.     if am < 1:
  23.         sr = "you do not have enough money to buy this stock"
  24.         n = True
  25.     else:
  26.         sr = f"you can buy a max of {am} {symbol} stock(s)"
  27.         n = False
  28.     if n:
  29.         await ctx.send(sr, ephemeral=True)
  30.         return
  31.     await ctx.send(f"This stock costs ${pr} each \n {sr} \n (0 for none)")
  32.     async def checks(msg):
  33.         if int(msg.author.id) == int(ctx.author.user.id):
  34.             return True
  35.         await ctx.send("I wasn't asking you", ephemeral=True)
  36.         return False
  37.  
  38.     try:
  39.         msg: Message = await wait_for.wait_for(
  40.             bot, "on_message_create", check=checks, timeout=15
  41.         )
  42.         try:
  43.             t = int(str(msg.content))
  44.         except:
  45.             await ctx.send(f"Must be a number and contain no decimals, not {msg.content} \ntry again")
  46.             return
  47.         if 1 > t:
  48.             await ctx.send("Buy canceled")
  49.             return
  50.         else:
  51.             n = await ctx.send(f"Do you wish to buy {t} {symbol} with a total cost of {t*float(pr)}?", components=yn)
  52.         button_ctx: ComponentContext = await bot.wait_for_component(
  53.             components=[yny, ynn], check=check, timeout=15
  54.         )
  55.         print(n._json)
  56.         await n.delete()
  57.         if button_ctx.custom_id == 'yes':
  58.             await ctx.send("Buying and stuff")
  59.             return
  60.         else:
  61.             return await ctx.send("Cancled", ephemeral=True)
  62.     except asyncio.TimeoutError:
  63.         return await ctx.send("You said nothing :(")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement