global_stats.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. """
  2. MIT License
  3. Copyright (c) 2021 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from wbb import app, SUDOERS, BOT_ID, BOT_NAME
  21. from wbb.core.decorators.errors import capture_err
  22. from wbb.utils.fetch import fetch
  23. from wbb.modules import ALL_MODULES
  24. from wbb.utils.inlinefuncs import keywords_list
  25. from wbb.utils.dbfunctions import (
  26. get_served_chats,
  27. remove_served_chat,
  28. get_notes_count,
  29. get_filters_count,
  30. get_warns_count,
  31. get_karmas_count,
  32. get_gbans_count,
  33. get_blacklist_filters_count
  34. )
  35. from pyrogram import filters
  36. import asyncio
  37. """ CHAT WATCHER IS IN filters.py"""
  38. @app.on_message(
  39. filters.command("gstats") & filters.user(SUDOERS)
  40. & ~filters.edited
  41. )
  42. @capture_err
  43. async def global_stats(_, message):
  44. m = await app.send_message(
  45. message.chat.id,
  46. text="__**Analysing Stats**__",
  47. disable_web_page_preview=True
  48. )
  49. # For bot served chat and users count
  50. served_chats = []
  51. total_users = 0
  52. chats = await get_served_chats()
  53. for chat in chats:
  54. served_chats.append(int(chat["chat_id"]))
  55. await m.edit(
  56. f"__**Generating Statistics Report, Should Take {len(served_chats)*6}+ Seconds.**__",
  57. disable_web_page_preview=True
  58. )
  59. for served_chat in served_chats:
  60. try:
  61. await app.get_chat_members(served_chat, BOT_ID)
  62. await asyncio.sleep(2)
  63. except Exception:
  64. await remove_served_chat(served_chat)
  65. served_chats.remove(served_chat)
  66. pass
  67. for i in served_chats:
  68. try:
  69. mc = (await app.get_chat(i)).members_count
  70. total_users += int(mc)
  71. except Exception:
  72. await remove_served_chat(served_chat)
  73. pass
  74. await asyncio.sleep(2)
  75. # Gbans count
  76. gbans = await get_gbans_count()
  77. _notes = await get_notes_count()
  78. notes_count = _notes["notes_count"]
  79. notes_chats_count = _notes["chats_count"]
  80. # Filters count across chats
  81. _filters = await get_filters_count()
  82. filters_count = _filters["filters_count"]
  83. filters_chats_count = _filters["chats_count"]
  84. # Blacklisted filters count across chats
  85. _filters = await get_blacklist_filters_count()
  86. blacklist_filters_count = _filters["filters_count"]
  87. blacklist_filters_chats_count = _filters["chats_count"]
  88. # Warns count across chats
  89. _warns = await get_warns_count()
  90. warns_count = _warns["warns_count"]
  91. warns_chats_count = _warns["chats_count"]
  92. # Karmas count across chats
  93. _karmas = await get_karmas_count()
  94. karmas_count = _karmas["karmas_count"]
  95. karmas_chats_count = _karmas["chats_count"]
  96. # Contributors/Developers count and commits on github
  97. url = "https://api.github.com/repos/thehamkercat/williambutcherbot/contributors"
  98. rurl = "https://github.com/thehamkercat/williambutcherbot"
  99. developers = await fetch(url)
  100. commits = 0
  101. for developer in developers:
  102. commits += developer['contributions']
  103. developers = len(developers)
  104. # Modules info
  105. modules_count = len(ALL_MODULES)
  106. msg = f"""
  107. **Global Stats of {BOT_NAME}**:
  108. **{modules_count}** Modules Loaded
  109. **{len(keywords_list)}** Inline Modules Loaded.
  110. **{gbans}** Globally banned users.
  111. **{filters_count}** Filters, Across **{filters_chats_count}** chats.
  112. **{blacklist_filters_count}** Blacklist Filters, Across **{blacklist_filters_chats_count}** chats.
  113. **{notes_count}** Notes, Across **{notes_chats_count}** chats.
  114. **{warns_count}** Warns, Across **{warns_chats_count}** chats.
  115. **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
  116. **{total_users}** Users, Across **{len(served_chats)}** chats.
  117. **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**.
  118. """
  119. await m.edit(msg, disable_web_page_preview=True)