rice.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from pyrogram import filters
  2. from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
  3. from wbb import app
  4. RICE_GROUP = "DE_WM"
  5. RICE_CHANNEL = "RiceGallery"
  6. @app.on_message(filters.chat(RICE_GROUP)
  7. & filters.media
  8. & filters.regex(r"^\[RICE\] ")
  9. & ~filters.forwarded
  10. & ~filters.edited)
  11. async def rice(_, message: Message):
  12. """Forward media and media_group messages which has caption starts
  13. with [RICE] with space and description in RICE_GROUP to RICE_CHANNEL
  14. edited or forwarded messages won't be forwarded
  15. """
  16. await message.reply_text(
  17. "**Waiting for admin to approve**",
  18. reply_markup=InlineKeyboardMarkup(
  19. [
  20. [
  21. InlineKeyboardButton(
  22. "Approve (Forward)",
  23. callback_data="forward"
  24. ),
  25. InlineKeyboardButton(
  26. "Ignore",
  27. callback_data="ignore"
  28. )
  29. ]
  30. ]
  31. ),
  32. quote=True
  33. )
  34. @app.on_callback_query(filters.regex("forward"))
  35. async def callback_query_forward_rice(_, callback_query):
  36. approver = callback_query.from_user
  37. group_chat = callback_query.message.chat
  38. approver_status = (await group_chat.get_member(approver.id)).status
  39. if not (approver_status in ("creator", "administrator")):
  40. await callback_query.answer("Only admin can approve this!")
  41. return
  42. await callback_query.answer("Successfully approved")
  43. m_rice = callback_query.message.reply_to_message
  44. if m_rice.media_group_id:
  45. message_id = m_rice.message_id
  46. media_group = await app.get_media_group(RICE_GROUP, message_id)
  47. reply = await app.forward_messages(
  48. RICE_CHANNEL, RICE_GROUP,
  49. [m.message_id for m in media_group])
  50. link = reply[0].link
  51. else:
  52. reply = await m_rice.forward(RICE_CHANNEL)
  53. link = reply.link
  54. await callback_query.message.delete()
  55. print(reply)
  56. reply_text = (f"<b>OP</b>: {m_rice.from_user.mention()}\n"
  57. f"<b>Approver</b>: {approver.mention()}\n"
  58. f"<b>Forwarded</b>: "
  59. f"<a href=\"{link}\">Rice Gallery</a>")
  60. await m_rice.reply_text(reply_text, parse_mode="html",
  61. disable_web_page_preview=True)
  62. @app.on_callback_query(filters.regex("ignore"))
  63. async def callback_query_ignore_rice(_, callback_query):
  64. m_rice = callback_query.message.reply_to_message
  65. group_chat = callback_query.message.chat
  66. from_user = callback_query.from_user
  67. from_user_status = (await group_chat.get_member(from_user.id)).status
  68. rice_op = callback_query.message.reply_to_message.from_user
  69. if from_user.id == rice_op.id:
  70. await callback_query.answer("Ok, this rice won't be forwarded")
  71. elif from_user_status in ("creator", "administrator"):
  72. await m_rice.reply_text(f"{from_user.mention} ignored this rice")
  73. else:
  74. await callback_query.answer("Only admin or OP could ignore it")
  75. return
  76. await callback_query.message.delete()