global_stats.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_chat
  11. )
  12. from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
  13. from pyrogram import filters
  14. @app.on_message(filters.new_chat_members & filters.left_chat_member, group=global_stats_group)
  15. @capture_err
  16. async def chat_watcher(_, message):
  17. chat_id = message.chat.id
  18. served_chat = await is_served_chat(chat_id)
  19. if served_chat: 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 app.send_message(message.chat.id, 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(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. # NOTE need to fix these
  40. msg = f"""**Global Stats of {BOT_NAME}**:
  41. 0 gbanned users.
  42. 0 blacklist triggers, across 0 chats.
  43. 0 filters, across 0 chats.
  44. 0 notes, across 0 chats.
  45. 0 welcome messages are set.
  46. {total_users} users, across {len(served_chats)} chats.
  47. 0 warns, across 0 chats."""
  48. await m.edit(msg)