couple.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. """
  2. MIT License
  3. Copyright (c) 2023 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. from pyrogram import enums, filters
  23. from wbb import app
  24. from wbb.core.decorators.errors import capture_err
  25. from wbb.utils.dbfunctions import get_couple, save_couple
  26. __MODULE__ = "Shippering"
  27. __HELP__ = "/detect_gay - To Choose Couple Of The Day"
  28. # Date and time
  29. def dt():
  30. now = datetime.now()
  31. dt_string = now.strftime("%d/%m/%Y %H:%M")
  32. dt_list = dt_string.split(" ")
  33. return dt_list
  34. def dt_tom():
  35. a = (
  36. str(int(dt()[0].split("/")[0]) + 1)
  37. + "/"
  38. + dt()[0].split("/")[1]
  39. + "/"
  40. + dt()[0].split("/")[2]
  41. )
  42. return a
  43. def today():
  44. return str(dt()[0])
  45. def tomorrow():
  46. return str(dt_tom())
  47. @app.on_message(filters.command("detect_gay"))
  48. @capture_err
  49. async def couple(_, message):
  50. if message.chat.type == enums.ChatType.PRIVATE:
  51. return await message.reply_text("This command only works in groups.")
  52. m = await message.reply("Detecting gay among us...")
  53. try:
  54. chat_id = message.chat.id
  55. is_selected = await get_couple(chat_id, today())
  56. if not is_selected:
  57. list_of_users = []
  58. async for i in app.get_chat_members(message.chat.id):
  59. if not i.user.is_bot:
  60. list_of_users.append(i.user.id)
  61. if len(list_of_users) < 2:
  62. return await m.edit("Not enough users")
  63. c1_id = random.choice(list_of_users)
  64. c2_id = random.choice(list_of_users)
  65. while c1_id == c2_id:
  66. c1_id = random.choice(list_of_users)
  67. c1_mention = (await app.get_users(c1_id)).mention
  68. c2_mention = (await app.get_users(c2_id)).mention
  69. couple_selection_message = f"""**Couple of the day:**
  70. {c1_mention} + {c2_mention} = ❤️
  71. __New couple of the day may be chosen at 12AM {tomorrow()}__"""
  72. await m.edit(couple_selection_message)
  73. couple = {"c1_id": c1_id, "c2_id": c2_id}
  74. await save_couple(chat_id, today(), couple)
  75. elif is_selected:
  76. c1_id = int(is_selected["c1_id"])
  77. c2_id = int(is_selected["c2_id"])
  78. c1_name = (await app.get_users(c1_id)).first_name
  79. c2_name = (await app.get_users(c2_id)).first_name
  80. couple_selection_message = f"""Couple of the day:
  81. [{c1_name}](tg://openmessage?user_id={c1_id}) + [{c2_name}](tg://openmessage?user_id={c2_id}) = ❤️
  82. __New couple of the day may be chosen at 12AM {tomorrow()}__"""
  83. await m.edit(couple_selection_message)
  84. except Exception as e:
  85. print(e)
  86. await message.reply_text(e)