info.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 os
  21. from pyrogram import filters
  22. from pyrogram.types import Message
  23. from wbb import SUDOERS, app
  24. from wbb.core.sections import section
  25. from wbb.utils.dbfunctions import is_gbanned_user, user_global_karma
  26. __MODULE__ = "Info"
  27. __HELP__ = """
  28. /info [USERNAME|ID] - Get info about a user.
  29. /chat_info [USERNAME|ID] - Get info about a chat.
  30. """
  31. async def get_user_info(user, already=False):
  32. if not already:
  33. user = await app.get_users(user)
  34. if not user.first_name:
  35. return ["Deleted account", None]
  36. user_id = user.id
  37. username = user.username
  38. first_name = user.first_name
  39. mention = user.mention("Link")
  40. dc_id = user.dc_id
  41. photo_id = user.photo.big_file_id if user.photo else None
  42. is_gbanned = await is_gbanned_user(user_id)
  43. is_sudo = user_id in SUDOERS
  44. is_premium = user.is_premium
  45. karma = await user_global_karma(user_id)
  46. body = {
  47. "ID": user_id,
  48. "DC": dc_id,
  49. "Name": [first_name],
  50. "Username": [("@" + username) if username else "Null"],
  51. "Mention": [mention],
  52. "Sudo": is_sudo,
  53. "Premium": is_premium,
  54. "Karma": karma,
  55. "Gbanned": is_gbanned,
  56. }
  57. caption = section("User info", body)
  58. return [caption, photo_id]
  59. async def get_chat_info(chat, already=False):
  60. if not already:
  61. chat = await app.get_chat(chat)
  62. chat_id = chat.id
  63. username = chat.username
  64. title = chat.title
  65. type_ = str(chat.type).split(".")[1]
  66. is_scam = chat.is_scam
  67. description = chat.description
  68. members = chat.members_count
  69. is_restricted = chat.is_restricted
  70. link = f"[Link](t.me/{username})" if username else "Null"
  71. dc_id = chat.dc_id
  72. photo_id = chat.photo.big_file_id if chat.photo else None
  73. body = {
  74. "ID": chat_id,
  75. "DC": dc_id,
  76. "Type": type_,
  77. "Name": [title],
  78. "Username": [("@" + username) if username else "Null"],
  79. "Mention": [link],
  80. "Members": members,
  81. "Scam": is_scam,
  82. "Restricted": is_restricted,
  83. "Description": [description],
  84. }
  85. caption = section("Chat info", body)
  86. return [caption, photo_id]
  87. @app.on_message(filters.command("info"))
  88. async def info_func(_, message: Message):
  89. if message.reply_to_message:
  90. user = message.reply_to_message.from_user.id
  91. elif not message.reply_to_message and len(message.command) == 1:
  92. user = message.from_user.id
  93. elif not message.reply_to_message and len(message.command) != 1:
  94. user = message.text.split(None, 1)[1]
  95. m = await message.reply_text("Processing")
  96. try:
  97. info_caption, photo_id = await get_user_info(user)
  98. except Exception as e:
  99. return await m.edit(f"{str(e)}, Perhaps you meant to use /chat_info ?")
  100. if not photo_id:
  101. return await m.edit(info_caption, disable_web_page_preview=True)
  102. photo = await app.download_media(photo_id)
  103. await message.reply_photo(photo, caption=info_caption, quote=False)
  104. await m.delete()
  105. os.remove(photo)
  106. @app.on_message(filters.command("chat_info"))
  107. async def chat_info_func(_, message: Message):
  108. splited = message.text.split()
  109. if len(splited) == 1:
  110. chat = message.chat.id
  111. if chat == message.from_user.id:
  112. return await message.reply_text(
  113. "**Usage:**/chat_info [USERNAME|ID]"
  114. )
  115. else:
  116. chat = splited[1]
  117. try:
  118. m = await message.reply_text("Processing")
  119. info_caption, photo_id = await get_chat_info(chat)
  120. if not photo_id:
  121. return await m.edit(info_caption, disable_web_page_preview=True)
  122. photo = await app.download_media(photo_id)
  123. await message.reply_photo(photo, caption=info_caption, quote=False)
  124. await m.delete()
  125. os.remove(photo)
  126. except Exception as e:
  127. await m.edit(e)