couple.py 2.5 KB

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