rice.py 4.8 KB

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