quotly.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from io import BytesIO
  2. from pyrogram import filters
  3. from pyrogram.types import Message
  4. from wbb import app, arq
  5. from wbb.core.decorators.errors import capture_err
  6. __MODULE__ = "Quotly"
  7. __HELP__ = """
  8. /q - To quote a message.
  9. /q [INTEGER] - To quote more than 1 messages.
  10. """
  11. async def quotify(messages: list):
  12. response = await arq.quotly(messages)
  13. if not response.ok:
  14. return [False, response.result]
  15. sticker = response.result
  16. sticker = BytesIO(sticker)
  17. sticker.name = "sticker.webp"
  18. return [True, sticker]
  19. def getArg(message: Message) -> str:
  20. arg = message.text.strip().split(None, 1)[1].strip()
  21. return arg
  22. def isArgInt(message: Message) -> bool:
  23. count = getArg(message)
  24. try:
  25. count = int(count)
  26. return [True, count]
  27. except ValueError:
  28. return [False, 0]
  29. @app.on_message(filters.command("q"))
  30. @capture_err
  31. async def quotly_func(_, message: Message):
  32. if not message.reply_to_message:
  33. await message.reply_text("Reply to a message to quote it.")
  34. return
  35. if not message.reply_to_message.text:
  36. await message.reply_text("Replied message has no text, can't quote it.")
  37. return
  38. m = await message.reply_text("Quoting Messages")
  39. if len(message.command) < 2:
  40. messages = [message.reply_to_message]
  41. elif len(message.command) == 2:
  42. arg = isArgInt(message)
  43. if arg[0]:
  44. if arg[1] < 2 or arg[1] > 10:
  45. await m.edit("Argument must be between 2-10.")
  46. return
  47. count = arg[1]
  48. messages = await app.get_messages(
  49. message.chat.id,
  50. [
  51. i
  52. for i in range(
  53. message.reply_to_message.message_id,
  54. message.reply_to_message.message_id + count,
  55. )
  56. ],
  57. replies=0,
  58. )
  59. else:
  60. if getArg(message) != "r":
  61. await m.edit(
  62. "Incorrect Argument, Pass **'r'** or **'INT'**, **EX:** __/q 2__"
  63. )
  64. return
  65. reply_message = await app.get_messages(
  66. message.chat.id,
  67. message.reply_to_message.message_id,
  68. replies=1,
  69. )
  70. messages = [reply_message]
  71. else:
  72. await m.edit("Incorrect argument, check quotly module in help section.")
  73. return
  74. try:
  75. sticker = await quotify(messages)
  76. if not sticker[0]:
  77. await message.rely_text(sticker[1])
  78. await m.delete()
  79. return
  80. sticker = sticker[1]
  81. await message.reply_sticker(sticker)
  82. await m.delete()
  83. sticker.close()
  84. except Exception:
  85. await message.reply_text(
  86. "Something wrong happened while quoting messages,"
  87. + " This error usually happens when there's a "
  88. + " message containing something other than text."
  89. )
  90. await m.delete()
  91. return