quotly.py 3.0 KB

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