couple.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from wbb import app
  2. from wbb.utils.errors import capture_err
  3. from wbb.utils.dbfunctions import _get_lovers, get_couple, save_couple
  4. from pyrogram import filters
  5. import random
  6. 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"))
  22. async def couple(_, message):
  23. if message.chat.type == "private":
  24. await message.reply_text("This command only works in groups.")
  25. return
  26. try:
  27. chat_id = message.chat.id
  28. is_selected = await get_couple(chat_id, today)
  29. if not is_selected:
  30. list_of_users = []
  31. async for i in app.iter_chat_members(message.chat.id):
  32. if not i.user.is_bot:
  33. list_of_users.append(i.user.id)
  34. c1_id = random.choice(list_of_users)
  35. c2_id = random.choice(list_of_users)
  36. while c1_id == c2_id:
  37. c1_id = random.choice(list_of_users)
  38. c1_mention = (await app.get_users(c1_id)).mention
  39. c2_mention = (await app.get_users(c2_id)).mention
  40. couple_selection_message = f"""**Couple of the day:**
  41. {c1_mention} + {c2_mention} = ❤️
  42. __New couple of the day may be chosen at 12AM {tomorrow}__"""
  43. await app.send_message(
  44. message.chat.id,
  45. text=couple_selection_message
  46. )
  47. couple = {
  48. "c1_id": c1_id,
  49. "c2_id": c2_id
  50. }
  51. await save_couple(chat_id, today, couple)
  52. elif is_selected:
  53. c1_id = int(is_selected['c1_id'])
  54. c2_id = int(is_selected['c2_id'])
  55. c1_name = (await app.get_users(c1_id)).first_name
  56. c2_name = (await app.get_users(c2_id)).first_name
  57. couple_selection_message = f"""Couple of the day:
  58. {c1_name} + {c2_name} = ❤️
  59. __New couple of the day may be chosen at 12AM {tomorrow}__"""
  60. await app.send_message(
  61. message.chat.id,
  62. text=couple_selection_message
  63. )
  64. except Exception as e:
  65. print(e)
  66. await message.reply_text(e)