quotly.py 3.2 KB

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