info.py 3.5 KB

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