reddit.py 913 B

12345678910111213141516171819202122232425262728
  1. from pyrogram import filters
  2. from wbb import app, ARQ
  3. from wbb.utils.errors import capture_err
  4. from wbb.utils.fetch import fetch
  5. __MODULE__ = "Reddit"
  6. __HELP__ = "/reddit [query] - results something from reddit"
  7. @app.on_message(filters.command("reddit") & ~filters.edited)
  8. @capture_err
  9. async def reddit(_, message):
  10. if len(message.command) != 2:
  11. await message.reply_text("/reddit needs an argument")
  12. return
  13. subreddit = message.text.split(None, 1)[1]
  14. try:
  15. res = await fetch(f"{ARQ}reddit?query={subreddit}")
  16. sreddit = res["subreddit"]
  17. title = res["title"]
  18. image = res["url"]
  19. link = res["postLink"]
  20. caption = f"""**Title:** `{title}`
  21. **Subreddit:** {sreddit}
  22. **PostLink:** {link}"""
  23. await message.reply_photo(photo=image, caption=caption)
  24. except Exception as e:
  25. print(str(e))
  26. await message.reply_text(str(e))