reddit.py 786 B

123456789101112131415161718192021222324
  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. res = await fetch(f"{ARQ}reddit?query={subreddit}")
  15. sreddit = res["subreddit"]
  16. title = res["title"]
  17. image = res["url"]
  18. link = res["postLink"]
  19. caption = f"""**Title:** `{title}`
  20. **Subreddit:** {sreddit}
  21. **PostLink:** {link}"""
  22. await message.reply_photo(photo=image, caption=caption)