couple.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. """
  2. MIT License
  3. Copyright (c) 2021 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. from wbb import app
  21. from wbb.core.decorators.errors import capture_err
  22. from wbb.utils.dbfunctions import get_couple, save_couple
  23. from pyrogram import filters
  24. import random
  25. from datetime import datetime
  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 = str(int(dt()[0].split('/')[0]) + 1)+"/" + \
  36. dt()[0].split('/')[1]+"/" + dt()[0].split('/')[2]
  37. return a
  38. today = str(dt()[0])
  39. tomorrow = str(dt_tom())
  40. @app.on_message(filters.command("detect_gay") & ~filters.edited)
  41. @capture_err
  42. async def couple(_, message):
  43. if message.chat.type == "private":
  44. await message.reply_text("This command only works in groups.")
  45. return
  46. try:
  47. chat_id = message.chat.id
  48. is_selected = await get_couple(chat_id, today)
  49. if not is_selected:
  50. list_of_users = []
  51. async for i in app.iter_chat_members(message.chat.id):
  52. if not i.user.is_bot:
  53. list_of_users.append(i.user.id)
  54. if len(list_of_users) < 2:
  55. await message.reply_text("Not enough users")
  56. return
  57. c1_id = random.choice(list_of_users)
  58. c2_id = random.choice(list_of_users)
  59. while c1_id == c2_id:
  60. c1_id = random.choice(list_of_users)
  61. c1_mention = (await app.get_users(c1_id)).mention
  62. c2_mention = (await app.get_users(c2_id)).mention
  63. couple_selection_message = f"""**Couple of the day:**
  64. {c1_mention} + {c2_mention} = ❤️
  65. __New couple of the day may be chosen at 12AM {tomorrow}__"""
  66. await app.send_message(
  67. message.chat.id,
  68. text=couple_selection_message
  69. )
  70. couple = {
  71. "c1_id": c1_id,
  72. "c2_id": c2_id
  73. }
  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 app.send_message(
  84. message.chat.id,
  85. text=couple_selection_message
  86. )
  87. except Exception as e:
  88. print(e)
  89. await message.reply_text(e)