info.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. import os
  21. from pyrogram import filters
  22. from pyrogram.types import Message
  23. from wbb import SUDOERS, app
  24. from wbb.core.decorators.errors import capture_err
  25. from wbb.modules.trust import get_spam_probability
  26. from wbb.utils.dbfunctions import is_gbanned_user, user_global_karma
  27. __MODULE__ = "Info"
  28. __HELP__ = """
  29. /info [USERNAME|ID] - Get info about a user.
  30. /chat_info [USERNAME|ID] - Get info about a chat.
  31. """
  32. async def get_user_info(user):
  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. karma = await user_global_karma(user_id)
  45. spam_probab, n_messages = await get_spam_probability(user_id)
  46. isSpammer = (
  47. True
  48. if spam_probab > 70
  49. else False
  50. if spam_probab != 0
  51. else "Uncertain"
  52. )
  53. spam_probab = (
  54. str(round(spam_probab)) + " %"
  55. if spam_probab != 0
  56. else "Uncertain"
  57. )
  58. caption = f"""
  59. **ID:** `{user_id}`
  60. **DC:** {dc_id}
  61. **Name:** {first_name}
  62. **Username:** {("@" + username) if username else None}
  63. **Mention:** {mention}
  64. **Sudo:** {is_sudo}
  65. **Karma:** {karma}
  66. **Gbanned:** {is_gbanned}
  67. **ARQ Spam Detection:**
  68. **Spammer:** {isSpammer}
  69. **Spam Probability:** {spam_probab}
  70. __Stats Of Last {n_messages} Messages.__
  71. """
  72. return [caption, photo_id]
  73. async def get_chat_info(chat):
  74. chat = await app.get_chat(chat)
  75. chat_id = chat.id
  76. username = chat.username
  77. title = chat.title
  78. type = chat.type
  79. is_scam = chat.is_scam
  80. description = chat.description
  81. members = chat.members_count
  82. is_restricted = chat.is_restricted
  83. link = f"[Link](t.me/{username})" if username else None
  84. dc_id = chat.dc_id
  85. photo_id = chat.photo.big_file_id if chat.photo else None
  86. caption = f"""
  87. **ID:** `{chat_id}`
  88. **DC:** {dc_id}
  89. **Type:** {type}
  90. **Name:** {title}
  91. **Username:** {("@" + username) if username else None}
  92. **Mention:** {link}
  93. **Members:** {members}
  94. **Scam:** {is_scam}
  95. **Restricted:** {is_restricted}
  96. **Description:** {description}
  97. """
  98. return [caption, photo_id]
  99. @app.on_message(filters.command("info"))
  100. @capture_err
  101. async def info_func(_, message: Message):
  102. if message.reply_to_message:
  103. user = message.reply_to_message.from_user.id
  104. elif not message.reply_to_message and len(message.command) == 1:
  105. user = message.from_user.id
  106. elif not message.reply_to_message and len(message.command) != 1:
  107. user = message.text.split(None, 1)[1]
  108. m = await message.reply_text("Processing")
  109. try:
  110. info_caption, photo_id = await get_user_info(user)
  111. except Exception as e:
  112. return await m.edit(str(e))
  113. if not photo_id:
  114. return await m.edit(
  115. info_caption, disable_web_page_preview=True
  116. )
  117. photo = await app.download_media(photo_id)
  118. await message.reply_photo(
  119. photo, caption=info_caption, quote=False
  120. )
  121. await m.delete()
  122. os.remove(photo)
  123. @app.on_message(filters.command("chat_info"))
  124. @capture_err
  125. async def chat_info_func(_, message: Message):
  126. try:
  127. if len(message.command) > 2:
  128. return await message.reply_text(
  129. "**Usage:**/chat_info [USERNAME|ID]"
  130. )
  131. elif len(message.command) == 1:
  132. chat = message.chat.id
  133. elif len(message.command) == 2:
  134. chat = message.text.split(None, 1)[1]
  135. m = await message.reply_text("Processing")
  136. info_caption, photo_id = await get_chat_info(chat)
  137. if not photo_id:
  138. return await m.edit(
  139. info_caption, disable_web_page_preview=True
  140. )
  141. photo = await app.download_media(photo_id)
  142. await message.reply_photo(
  143. photo, caption=info_caption, quote=False
  144. )
  145. await m.delete()
  146. os.remove(photo)
  147. except Exception as e:
  148. await message.reply_text(e)
  149. print(e)
  150. await m.delete()