global_stats.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from wbb import app
  2. from wbb.utils.filter_groups import global_stats_group
  3. from wbb.utils.errors import capture_err
  4. from wbb.utils.botinfo import BOT_ID, BOT_NAME
  5. from wbb.utils.dbfunctions import (
  6. is_served_chat,
  7. get_served_chats,
  8. add_served_chat,
  9. remove_served_chat,
  10. alpha_to_int
  11. )
  12. from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
  13. @app.on_message(filters.new_chat_members & filters.left_chat_member)
  14. @capture_err
  15. async def chat_watcher(_, message):
  16. chat_id = message.chat.id
  17. served_chat = await is_served_chat(chat_id)
  18. if served_chat:
  19. return
  20. await add_served_chat(chat_id)
  21. @app.on_message(filters.command("/global_stats") & ~filters.edited)
  22. @capture_err
  23. async def global_stats(_, message):
  24. m = await message.reply_text("__**Analysing Stats, Might Take 10-30 Seconds.**__")
  25. served_chats = []
  26. total_users = 0
  27. chats = await get_served_chats
  28. for chat in chats:
  29. served_chats.append(await alpha_to_int(chat))
  30. for served_chat in served_chats:
  31. try:
  32. await app.get_chat_member(served_chat, BOT_ID)
  33. except UserNotParticipant:
  34. await remove_served_chat(served_chat)
  35. served_chats.remove(served_chat)
  36. pass
  37. for i in served_chats:
  38. total_users += int((await app.get_chat(i)).members_count)
  39. msg = f"""**Global Stats of {BOT_NAME}**:
  40. 0 gbanned users.
  41. 0 blacklist triggers, across 0 chats.
  42. 0 filters, across 0 chats.
  43. 0 notes, across 0 chats.
  44. 0 welcome messages are set.
  45. {total_users} users, across {len(served_chats)} chats.
  46. 0 warns, across 0 chats.
  47. 0 """
  48. await m.edit(msg)