rice.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """
  2. MIT License
  3. Copyright (c) 2021 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from pyrogram import filters
  21. from pyrogram.types import (InlineKeyboardButton, InlineKeyboardMarkup,
  22. InputMediaPhoto, InputMediaVideo, Message)
  23. from wbb import app
  24. from wbb.core.decorators.errors import capture_err
  25. RICE_GROUP = "DE_WM"
  26. RICE_CHANNEL = "RiceGallery"
  27. @app.on_message(
  28. filters.chat(RICE_GROUP)
  29. & (filters.photo | filters.video | filters.document)
  30. & filters.regex(r"^\[RICE\] ")
  31. & ~filters.forwarded
  32. & ~filters.edited
  33. )
  34. @capture_err
  35. async def rice(_, message: Message):
  36. """Forward media and media_group messages which has caption starts
  37. with [RICE] with space and description in RICE_GROUP to RICE_CHANNEL
  38. edited or forwarded messages won't be forwarded
  39. """
  40. await message.reply_text(
  41. "**Waiting for admin to approve...**",
  42. reply_markup=InlineKeyboardMarkup(
  43. [
  44. [
  45. InlineKeyboardButton(
  46. "Approve (Forward)", callback_data="forward"
  47. ),
  48. InlineKeyboardButton("Ignore", callback_data="ignore"),
  49. ]
  50. ]
  51. ),
  52. quote=True,
  53. parse_mode="markdown",
  54. )
  55. @app.on_callback_query(filters.regex("forward"))
  56. async def callback_query_forward_rice(_, callback_query):
  57. app.set_parse_mode("markdown")
  58. u_approver = callback_query.from_user
  59. c_group = callback_query.message.chat
  60. approver_status = (await c_group.get_member(u_approver.id)).status
  61. if not (approver_status in ("creator", "administrator")):
  62. await callback_query.answer("Only admin can approve this!")
  63. return
  64. await callback_query.answer("Successfully approved")
  65. m_op = callback_query.message.reply_to_message
  66. u_op = m_op.from_user
  67. arg_caption = f"{m_op.caption}\nOP: [{u_op.first_name}]({m_op.link})"
  68. if m_op.media_group_id:
  69. message_id = m_op.message_id
  70. media_group = await app.get_media_group(RICE_GROUP, message_id)
  71. arg_media = []
  72. for m in media_group:
  73. if m.photo and m.caption:
  74. arg_media.append(
  75. InputMediaPhoto(m.photo.file_id, caption=arg_caption)
  76. )
  77. elif m.photo:
  78. arg_media.append(InputMediaPhoto(m.photo.file_id))
  79. elif m.video and m.caption:
  80. arg_media.append(
  81. InputMediaVideo(m.video.file_id, caption=arg_caption)
  82. )
  83. elif m.video:
  84. arg_media.append(InputMediaVideo(m.video.file_id))
  85. m_cp = await app.send_media_group(RICE_CHANNEL, arg_media)
  86. link = m_cp[0].link
  87. else:
  88. m_cp = await m_op.copy(RICE_CHANNEL, caption=arg_caption)
  89. link = m_cp.link
  90. await callback_query.message.delete()
  91. reply_text = (
  92. f"**OP**: {u_op.mention()}\n"
  93. f"**Approver**: {u_approver.mention()}\n"
  94. f"**Forwarded**: [Rice Gallery]({link})"
  95. )
  96. await m_op.reply_text(reply_text, disable_web_page_preview=True)
  97. @app.on_callback_query(filters.regex("ignore"))
  98. async def callback_query_ignore_rice(_, callback_query):
  99. c_group = callback_query.message.chat
  100. u_disprover = callback_query.from_user
  101. disprover_status = (await c_group.get_member(u_disprover.id)).status
  102. m_op = callback_query.message.reply_to_message
  103. u_op = m_op.from_user
  104. if u_disprover.id == u_op.id:
  105. await callback_query.answer("Ok, this rice won't be forwarded")
  106. elif disprover_status in ("creator", "administrator"):
  107. await m_op.reply_text(f"{u_disprover.mention} ignored this rice")
  108. else:
  109. await callback_query.answer("Only admin or OP could ignore it")
  110. return
  111. await callback_query.message.delete()