info.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import os
  2. from pyrogram import filters
  3. from pyrogram.types import Message
  4. from wbb import SUDOERS, app
  5. from wbb.core.decorators.errors import capture_err
  6. from wbb.utils.dbfunctions import is_gbanned_user, user_global_karma
  7. __MODULE__ = "Info"
  8. __HELP__ = """
  9. /info [USERNAME|ID] - Get info about a user.
  10. /chat_info [USERNAME|ID] - Get info about a chat.
  11. """
  12. async def get_user_info(user):
  13. user = await app.get_users(user)
  14. if not user.first_name:
  15. return ["Deleted account", None]
  16. user_id = user.id
  17. username = user.username
  18. first_name = user.first_name
  19. mention = user.mention("Link")
  20. status = user.status
  21. dc_id = user.dc_id
  22. photo_id = user.photo.big_file_id if user.photo else None
  23. is_gbanned = await is_gbanned_user(user_id)
  24. is_sudo = user_id in SUDOERS
  25. karma = await user_global_karma(user_id)
  26. caption = f"""
  27. **ID:** `{user_id}`
  28. **DC:** {dc_id}
  29. **Name:** {first_name}
  30. **Username:** {("@" + username) if username else None}
  31. **Permalink:** {mention}
  32. **Status:** {status}
  33. **Sudo:** {is_sudo}
  34. **Karma:** {karma}
  35. **Gbanned:** {is_gbanned}
  36. """
  37. return [caption, photo_id]
  38. async def get_chat_info(chat):
  39. chat = await app.get_chat(chat)
  40. chat_id = chat.id
  41. username = chat.username
  42. title = chat.title
  43. type = chat.type
  44. is_scam = chat.is_scam
  45. description = chat.description
  46. members = chat.members_count
  47. is_restricted = chat.is_restricted
  48. link = f"[Link](t.me/{username})" if username else None
  49. dc_id = chat.dc_id
  50. photo_id = chat.photo.big_file_id if chat.photo else None
  51. caption = f"""
  52. **ID:** `{chat_id}`
  53. **DC:** {dc_id}
  54. **Type:** {type}
  55. **Name:** {title}
  56. **Username:** {("@" + username) if username else None}
  57. **Permalink:** {link}
  58. **Members:** {members}
  59. **Scam:** {is_scam}
  60. **Restricted:** {is_restricted}
  61. **Description:** {description}
  62. """
  63. return [caption, photo_id]
  64. @app.on_message(filters.command("info"))
  65. @capture_err
  66. async def info_func(_, message: Message):
  67. try:
  68. if message.reply_to_message:
  69. user = message.reply_to_message.from_user.id
  70. elif not message.reply_to_message and len(message.command) == 1:
  71. user = message.from_user.id
  72. elif not message.reply_to_message and len(message.command) != 1:
  73. user = message.text.split(None, 1)[1]
  74. m = await message.reply_text("Processing")
  75. info_caption, photo_id = await get_user_info(user)
  76. if not photo_id:
  77. return await m.edit(info_caption, disable_web_page_preview=True)
  78. photo = await app.download_media(photo_id)
  79. await message.reply_photo(photo, caption=info_caption, quote=False)
  80. await m.delete()
  81. os.remove(photo)
  82. except Exception as e:
  83. await message.reply_text(str(e))
  84. print(e)
  85. @app.on_message(filters.command("chat_info"))
  86. @capture_err
  87. async def chat_info_func(_, message: Message):
  88. try:
  89. if len(message.command) > 2:
  90. return await message.reply_text("**Usage:**/chat_info [USERNAME|ID]")
  91. elif len(message.command) == 1:
  92. chat = message.chat.id
  93. elif len(message.command) == 2:
  94. chat = message.text.split(None, 1)[1]
  95. m = await message.reply_text("Processing")
  96. info_caption, photo_id = await get_chat_info(chat)
  97. if not photo_id:
  98. return await m.edit(info_caption, disable_web_page_preview=True)
  99. photo = await app.download_media(photo_id)
  100. await message.reply_photo(photo, caption=info_caption, quote=False)
  101. await m.delete()
  102. os.remove(photo)
  103. except Exception as e:
  104. await message.reply_text(e)
  105. print(e)