quotly.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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(
  37. "Replied message has no text, can't quote it."
  38. )
  39. return
  40. m = await message.reply_text("Quoting Messages")
  41. if len(message.command) < 2:
  42. messages = [message.reply_to_message]
  43. elif len(message.command) == 2:
  44. arg = isArgInt(message)
  45. if arg[0]:
  46. if arg[1] < 2 or arg[1] > 10:
  47. await m.edit("Argument must be between 2-10.")
  48. return
  49. count = arg[1]
  50. messages = await app.get_messages(
  51. message.chat.id,
  52. [
  53. i
  54. for i in range(
  55. message.reply_to_message.message_id,
  56. message.reply_to_message.message_id + count,
  57. )
  58. ],
  59. replies=0,
  60. )
  61. else:
  62. if getArg(message) != "r":
  63. await m.edit(
  64. "Incorrect Argument, Pass **'r'** or **'INT'**, **EX:** __/q 2__"
  65. )
  66. return
  67. reply_message = await app.get_messages(
  68. message.chat.id,
  69. message.reply_to_message.message_id,
  70. replies=1,
  71. )
  72. reply_message = reply_message.reply_to_message
  73. messages = [reply_message, message.reply_to_message]
  74. else:
  75. await m.edit(
  76. "Incorrect argument, check quotly module in help section."
  77. )
  78. return
  79. try:
  80. sticker = await quotify(messages)
  81. if not sticker[0]:
  82. await message.rely_text(sticker[1])
  83. await m.delete()
  84. return
  85. sticker = sticker[1]
  86. await message.reply_sticker(sticker)
  87. await m.delete()
  88. sticker.close()
  89. except Exception:
  90. await message.reply_text(
  91. "Something wrong happened while quoting messages,"
  92. + " This error usually happens when there's a "
  93. + " message containing something other than text."
  94. )
  95. await m.delete()
  96. return