info.py 4.6 KB

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