couple.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from wbb import app
  2. from wbb.utils.errors import capture_err
  3. from wbb.utils.dbfunctions import get_couple, save_couple
  4. from pyrogram import filters
  5. import random
  6. from datetime import datetime
  7. __MODULE__ = "Shippering"
  8. __HELP__ = "/detect_gay - To Choose Couple Of The Day"
  9. # Date and time
  10. def dt():
  11. now = datetime.now()
  12. dt_string = now.strftime("%d/%m/%Y %H:%M")
  13. dt_list = dt_string.split(' ')
  14. return dt_list
  15. def dt_tom():
  16. a = str(int(dt()[0].split('/')[0]) + 1)+"/" + \
  17. dt()[0].split('/')[1]+"/" + dt()[0].split('/')[2]
  18. return a
  19. today = str(dt()[0])
  20. tomorrow = str(dt_tom())
  21. @app.on_message(filters.command("detect_gay") & ~filters.edited)
  22. @capture_err
  23. async def couple(_, message):
  24. if message.chat.type == "private":
  25. await message.reply_text("This command only works in groups.")
  26. return
  27. try:
  28. chat_id = message.chat.id
  29. is_selected = await get_couple(chat_id, today)
  30. if not is_selected:
  31. list_of_users = []
  32. async for i in app.iter_chat_members(message.chat.id):
  33. if not i.user.is_bot:
  34. list_of_users.append(i.user.id)
  35. if len(list_of_users) < 2:
  36. await message.reply_text("Not enough users")
  37. return
  38. c1_id = random.choice(list_of_users)
  39. c2_id = random.choice(list_of_users)
  40. while c1_id == c2_id:
  41. c1_id = random.choice(list_of_users)
  42. c1_mention = (await app.get_users(c1_id)).mention
  43. c2_mention = (await app.get_users(c2_id)).mention
  44. couple_selection_message = f"""**Couple of the day:**
  45. {c1_mention} + {c2_mention} = ❤️
  46. __New couple of the day may be chosen at 12AM {tomorrow}__"""
  47. await app.send_message(
  48. message.chat.id,
  49. text=couple_selection_message
  50. )
  51. couple = {
  52. "c1_id": c1_id,
  53. "c2_id": c2_id
  54. }
  55. await save_couple(chat_id, today, couple)
  56. elif is_selected:
  57. c1_id = int(is_selected['c1_id'])
  58. c2_id = int(is_selected['c2_id'])
  59. c1_name = (await app.get_users(c1_id)).first_name
  60. c2_name = (await app.get_users(c2_id)).first_name
  61. couple_selection_message = f"""Couple of the day:
  62. {c1_name} + {c2_name} = ❤️
  63. __New couple of the day may be chosen at 12AM {tomorrow}__"""
  64. await app.send_message(
  65. message.chat.id,
  66. text=couple_selection_message
  67. )
  68. except Exception as e:
  69. print(e)
  70. await message.reply_text(e)