rice.py 3.7 KB

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