rice.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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,
  22. InlineKeyboardMarkup, InputMediaPhoto,
  23. InputMediaVideo, Message)
  24. from wbb import app
  25. from wbb.core.decorators.errors import capture_err
  26. # NOTE: THIS MODULE IS SPECIFICALLY FOR @DE_WM GROUP, YOU CAN REMOVE IT IN YOUR FORK IF YOU WANT TO
  27. RICE_GROUP = "DE_WM"
  28. RICE_CHANNEL = "RiceGallery"
  29. @app.on_message(
  30. filters.chat(RICE_GROUP)
  31. & (filters.photo | filters.video | filters.document)
  32. & filters.regex(r"^\[RICE\] ")
  33. & ~filters.forwarded
  34. & ~filters.edited
  35. )
  36. @capture_err
  37. async def rice(_, message: Message):
  38. """Forward media and media_group messages which has caption starts
  39. with [RICE] with space and description in RICE_GROUP to RICE_CHANNEL
  40. edited or forwarded messages won't be forwarded
  41. """
  42. await message.reply_text(
  43. "**Waiting for admin to approve...**",
  44. reply_markup=InlineKeyboardMarkup(
  45. [
  46. [
  47. InlineKeyboardButton(
  48. "Approve (Forward)", callback_data="forward"
  49. ),
  50. InlineKeyboardButton(
  51. "Ignore", callback_data="ignore"
  52. ),
  53. ]
  54. ]
  55. ),
  56. quote=True,
  57. parse_mode="markdown",
  58. )
  59. @app.on_callback_query(filters.regex("forward"))
  60. async def callback_query_forward_rice(_, callback_query):
  61. app.set_parse_mode("markdown")
  62. u_approver = callback_query.from_user
  63. c_group = callback_query.message.chat
  64. approver_status = (await c_group.get_member(u_approver.id)).status
  65. if not (approver_status in ("creator", "administrator")):
  66. await callback_query.answer("Only admin can approve this!")
  67. return
  68. await callback_query.answer("Successfully approved")
  69. m_op = callback_query.message.reply_to_message
  70. u_op = m_op.from_user
  71. arg_caption = (
  72. f"{m_op.caption}\nOP: [{u_op.first_name}]({m_op.link})"
  73. )
  74. if m_op.media_group_id:
  75. message_id = m_op.message_id
  76. media_group = await app.get_media_group(
  77. RICE_GROUP, message_id
  78. )
  79. arg_media = []
  80. for m in media_group:
  81. if m.photo and m.caption:
  82. arg_media.append(
  83. InputMediaPhoto(
  84. m.photo.file_id, caption=arg_caption
  85. )
  86. )
  87. elif m.photo:
  88. arg_media.append(InputMediaPhoto(m.photo.file_id))
  89. elif m.video and m.caption:
  90. arg_media.append(
  91. InputMediaVideo(
  92. m.video.file_id, caption=arg_caption
  93. )
  94. )
  95. elif m.video:
  96. arg_media.append(InputMediaVideo(m.video.file_id))
  97. m_cp = await app.send_media_group(RICE_CHANNEL, arg_media)
  98. link = m_cp[0].link
  99. else:
  100. m_cp = await m_op.copy(RICE_CHANNEL, caption=arg_caption)
  101. link = m_cp.link
  102. await callback_query.message.delete()
  103. reply_text = (
  104. f"**OP**: {u_op.mention()}\n"
  105. f"**Approver**: {u_approver.mention()}\n"
  106. f"**Forwarded**: [Rice Gallery]({link})"
  107. )
  108. await m_op.reply_text(reply_text, disable_web_page_preview=True)
  109. @app.on_callback_query(filters.regex("ignore"))
  110. async def callback_query_ignore_rice(_, callback_query):
  111. c_group = callback_query.message.chat
  112. u_disprover = callback_query.from_user
  113. disprover_status = (
  114. await c_group.get_member(u_disprover.id)
  115. ).status
  116. m_op = callback_query.message.reply_to_message
  117. u_op = m_op.from_user
  118. if u_disprover.id == u_op.id:
  119. await callback_query.answer(
  120. "Ok, this rice won't be forwarded"
  121. )
  122. elif disprover_status in ("creator", "administrator"):
  123. await m_op.reply_text(
  124. f"{u_disprover.mention} ignored this rice"
  125. )
  126. else:
  127. return await callback_query.answer(
  128. "Only admin or OP could ignore it"
  129. )
  130. await callback_query.message.delete()