crypto.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from pyrogram import filters
  2. from wbb import app
  3. from wbb.core.decorators.errors import capture_err
  4. from wbb.core.keyboard import ikb
  5. from wbb.core.sections import section
  6. from wbb.utils.http import get
  7. __MODULE__ = "Crypto"
  8. __HELP__ = """
  9. /crypto [currency]
  10. Get Real Time value from currency given.
  11. """
  12. @app.on_message(filters.command("crypto"))
  13. @capture_err
  14. async def crypto(_, message):
  15. if len(message.command) < 2:
  16. return await message.reply("/crypto [currency]")
  17. currency = message.text.split(None, 1)[1].lower()
  18. btn = ikb(
  19. {"Available Currencies": "https://plotcryptoprice.herokuapp.com"},
  20. )
  21. m = await message.reply("`Processing...`")
  22. try:
  23. r = await get(
  24. "https://x.wazirx.com/wazirx-falcon/api/v2.0/crypto_rates",
  25. timeout=5,
  26. )
  27. except Exception:
  28. return await m.edit("[ERROR]: Something went wrong.")
  29. if currency not in r:
  30. return await m.edit(
  31. "[ERROR]: INVALID CURRENCY",
  32. reply_markup=btn,
  33. )
  34. body = {i.upper(): j for i, j in r.get(currency).items()}
  35. text = section(
  36. "Current Crypto Rates For " + currency.upper(),
  37. body,
  38. )
  39. await m.edit(text, reply_markup=btn)