info.py 4.7 KB

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