couple.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """
  2. MIT License
  3. Copyright (c) 2024 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. import random
  21. from datetime import datetime
  22. import pytz
  23. from pyrogram import enums, filters
  24. from wbb import app
  25. from wbb.core.decorators.errors import capture_err
  26. from wbb.utils.dbfunctions import get_couple, save_couple
  27. __MODULE__ = "Shippering"
  28. __HELP__ = "/detect_gay - To Choose Couple Of The Day"
  29. # Date and time
  30. def dt():
  31. # Set the timezone to Indian Standard Time
  32. ist_timezone = pytz.timezone("Asia/Kolkata")
  33. # Get the current time in IST
  34. ist_now = datetime.now(ist_timezone)
  35. dt_string = ist_now.strftime("%d/%m/%Y %H:%M")
  36. dt_list = dt_string.split(" ")
  37. return dt_list
  38. def dt_tom():
  39. a = (
  40. str(int(dt()[0].split("/")[0]) + 1)
  41. + "/"
  42. + dt()[0].split("/")[1]
  43. + "/"
  44. + dt()[0].split("/")[2]
  45. )
  46. return a
  47. def today():
  48. return str(dt()[0])
  49. def tomorrow():
  50. return str(dt_tom())
  51. @app.on_message(filters.command("detect_gay"))
  52. @capture_err
  53. async def couple(_, message):
  54. if message.chat.type == enums.ChatType.PRIVATE:
  55. return await message.reply_text("This command only works in groups.")
  56. m = await message.reply("Detecting gay among us...")
  57. try:
  58. chat_id = message.chat.id
  59. is_selected = await get_couple(chat_id, today())
  60. if not is_selected:
  61. list_of_users = []
  62. async for i in app.get_chat_members(message.chat.id):
  63. if not i.user.is_bot and not i.user.is_deleted:
  64. user = await app.get_users(i.user.id)
  65. list_of_users.append(user.id)
  66. if len(list_of_users) < 2:
  67. return await m.edit("Not enough users")
  68. c1_id = random.choice(list_of_users)
  69. c2_id = random.choice(list_of_users)
  70. while c1_id == c2_id:
  71. c1_id = random.choice(list_of_users)
  72. c1_mention = (await app.get_users(c1_id)).mention
  73. c2_mention = (await app.get_users(c2_id)).mention
  74. couple_selection_message = f"""**Couple of the day:**
  75. {c1_mention} + {c2_mention} = ❤️
  76. __New couple of the day may be chosen at 12AM {tomorrow()}__"""
  77. await m.edit(couple_selection_message)
  78. couple = {"c1_id": c1_id, "c2_id": c2_id}
  79. await save_couple(chat_id, today(), couple)
  80. elif is_selected:
  81. c1_id = int(is_selected["c1_id"])
  82. c2_id = int(is_selected["c2_id"])
  83. c1_name = (await app.get_users(c1_id)).first_name
  84. c2_name = (await app.get_users(c2_id)).first_name
  85. couple_selection_message = f"""Couple of the day:
  86. [{c1_name}](tg://openmessage?user_id={c1_id}) + [{c2_name}](tg://openmessage?user_id={c2_id}) = ❤️
  87. __New couple of the day may be chosen at 12AM {tomorrow()}__"""
  88. await m.edit(couple_selection_message)
  89. except Exception as e:
  90. print(e)
  91. await message.reply_text(e)