crypto.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. {
  20. "Available Currencies": "https://plotcryptoprice.herokuapp.com"
  21. },
  22. )
  23. m = await message.reply("`Processing...`")
  24. try:
  25. r = await get(
  26. "https://x.wazirx.com/wazirx-falcon/api/v2.0/crypto_rates",
  27. timeout=5,
  28. )
  29. except Exception:
  30. return await m.edit("[ERROR]: Something went wrong.")
  31. if currency not in r:
  32. return await m.edit(
  33. "[ERROR]: INVALID CURRENCY",
  34. reply_markup=btn,
  35. )
  36. body = {i.upper(): j for i, j in r.get(currency).items()}
  37. text = section(
  38. "Current Crypto Rates For " + currency.upper(),
  39. body,
  40. )
  41. await m.edit(text, reply_markup=btn)