rice.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from pyrogram import filters
  2. from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
  3. from pyrogram.types import InputMediaPhoto, InputMediaVideo
  4. from wbb import app
  5. from wbb.core.decorators.errors import capture_err
  6. RICE_GROUP = "DE_WM"
  7. RICE_CHANNEL = "RiceGallery"
  8. @app.on_message(filters.chat(RICE_GROUP)
  9. & (filters.photo | filters.video | filters.document)
  10. & filters.regex(r"^\[RICE\] ")
  11. & ~filters.forwarded
  12. & ~filters.edited)
  13. @capture_err
  14. async def rice(_, message: Message):
  15. """Forward media and media_group messages which has caption starts
  16. with [RICE] with space and description in RICE_GROUP to RICE_CHANNEL
  17. edited or forwarded messages won't be forwarded
  18. """
  19. await message.reply_text(
  20. "**Waiting for admin to approve...**",
  21. reply_markup=InlineKeyboardMarkup(
  22. [
  23. [
  24. InlineKeyboardButton(
  25. "Approve (Forward)",
  26. callback_data="forward"
  27. ),
  28. InlineKeyboardButton(
  29. "Ignore",
  30. callback_data="ignore"
  31. )
  32. ]
  33. ]
  34. ),
  35. quote=True,
  36. parse_mode="markdown"
  37. )
  38. @app.on_callback_query(filters.regex("forward"))
  39. async def callback_query_forward_rice(_, callback_query):
  40. app.set_parse_mode("markdown")
  41. u_approver = callback_query.from_user
  42. c_group = callback_query.message.chat
  43. approver_status = (await c_group.get_member(u_approver.id)).status
  44. if not (approver_status in ("creator", "administrator")):
  45. await callback_query.answer("Only admin can approve this!")
  46. return
  47. await callback_query.answer("Successfully approved")
  48. m_op = callback_query.message.reply_to_message
  49. u_op = m_op.from_user
  50. arg_caption = f"{m_op.caption}\nOP: [{u_op.first_name}]({m_op.link})"
  51. if m_op.media_group_id:
  52. message_id = m_op.message_id
  53. media_group = await app.get_media_group(RICE_GROUP, message_id)
  54. arg_media = []
  55. for m in media_group:
  56. if m.photo and m.caption:
  57. arg_media.append(InputMediaPhoto(m.photo.file_id,
  58. caption=arg_caption))
  59. elif m.photo:
  60. arg_media.append(InputMediaPhoto(m.photo.file_id))
  61. elif m.video and m.caption:
  62. arg_media.append(InputMediaVideo(m.video.file_id,
  63. caption=arg_caption))
  64. elif m.video:
  65. arg_media.append(InputMediaVideo(m.video.file_id))
  66. m_cp = await app.send_media_group(RICE_CHANNEL, arg_media)
  67. link = m_cp[0].link
  68. else:
  69. m_cp = await m_op.copy(RICE_CHANNEL, caption=arg_caption)
  70. link = m_cp.link
  71. await callback_query.message.delete()
  72. reply_text = (f"**OP**: {u_op.mention()}\n"
  73. f"**Approver**: {u_approver.mention()}\n"
  74. f"**Forwarded**: [Rice Gallery]({link})")
  75. await m_op.reply_text(reply_text, disable_web_page_preview=True)
  76. @app.on_callback_query(filters.regex("ignore"))
  77. async def callback_query_ignore_rice(_, callback_query):
  78. c_group = callback_query.message.chat
  79. u_disprover = callback_query.from_user
  80. disprover_status = (await c_group.get_member(u_disprover.id)).status
  81. m_op = callback_query.message.reply_to_message
  82. u_op = m_op.from_user
  83. if u_disprover.id == u_op.id:
  84. await callback_query.answer("Ok, this rice won't be forwarded")
  85. elif disprover_status in ("creator", "administrator"):
  86. await m_op.reply_text(f"{u_disprover.mention} ignored this rice")
  87. else:
  88. await callback_query.answer("Only admin or OP could ignore it")
  89. return
  90. await callback_query.message.delete()