global_stats.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from wbb import app, SUDOERS
  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.fetch import fetch
  6. from wbb.modules import ALL_MODULES
  7. from wbb.utils.dbfunctions import (
  8. is_served_chat,
  9. get_served_chats,
  10. add_served_chat,
  11. remove_served_chat,
  12. get_notes_count,
  13. get_filters_count,
  14. get_warns_count,
  15. get_karmas_count,
  16. get_gbans_count
  17. )
  18. from pyrogram import filters
  19. @app.on_message(filters.text, group=global_stats_group)
  20. @capture_err
  21. async def chat_watcher(_, message):
  22. chat_id = message.chat.id
  23. served_chat = await is_served_chat(chat_id)
  24. if served_chat:
  25. return
  26. await add_served_chat(chat_id)
  27. @app.on_message(
  28. filters.command("global_stats") & filters.user(SUDOERS)
  29. & ~filters.edited
  30. )
  31. @capture_err
  32. async def global_stats(_, message):
  33. m = await app.send_message(
  34. message.chat.id,
  35. text="__**Analysing Stats, Might Take 10-30 Seconds.**__",
  36. disable_web_page_preview=True
  37. )
  38. # For bot served chat and users count
  39. served_chats = []
  40. total_users = 0
  41. chats = await get_served_chats()
  42. for chat in chats:
  43. served_chats.append(int(chat["chat_id"]))
  44. for served_chat in served_chats:
  45. try:
  46. await app.get_chat_members(served_chat, BOT_ID)
  47. except Exception as e:
  48. print(f"{e} - {served_chat} in global_stats.py")
  49. await remove_served_chat(served_chat)
  50. served_chats.remove(served_chat)
  51. pass
  52. for i in served_chats:
  53. mc = (await app.get_chat(i)).members_count
  54. total_users += int(mc)
  55. # Gbans count
  56. gbans = await get_gbans_count()
  57. # Notes count across chats
  58. _notes = await get_notes_count()
  59. notes_count = _notes["notes_count"]
  60. notes_chats_count = _notes["chats_count"]
  61. # Filters count across chats
  62. _filters = await get_filters_count()
  63. filters_count = _filters["filters_count"]
  64. filters_chats_count = _filters["chats_count"]
  65. # Warns count across chats
  66. _warns = await get_warns_count()
  67. warns_count = _warns["warns_count"]
  68. warns_chats_count = _warns["chats_count"]
  69. # Karmas count across chats
  70. _karmas = await get_karmas_count()
  71. karmas_count = _karmas["karmas_count"]
  72. karmas_chats_count = _karmas["chats_count"]
  73. # Contributors/Developers count and commits on github
  74. url = "https://api.github.com/repos/thehamkercat/williambutcherbot/contributors"
  75. rurl = "https://github.com/thehamkercat/williambutcherbot"
  76. developers = await fetch(url)
  77. commits = 0
  78. for developer in developers:
  79. commits += developer['contributions']
  80. developers = len(developers)
  81. # Modules info
  82. modules_count = len(ALL_MODULES)
  83. msg = f"""
  84. **Global Stats of {BOT_NAME}**:
  85. **{modules_count}** Modules Loaded
  86. **{gbans}** Globally banned users.
  87. **{filters_count}** Filters, Across **{filters_chats_count}** chats.
  88. **{notes_count}** Notes, Across **{notes_chats_count}** chats.
  89. **{warns_count}** Warns, Across **{warns_chats_count}** chats.
  90. **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
  91. **{total_users}** Users, Across **{len(served_chats)}** chats.
  92. **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**."""
  93. await m.edit(msg, disable_web_page_preview=True)