rice.py 5.0 KB

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