global_stats.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. import asyncio
  21. from pyrogram import filters
  22. from wbb import BOT_ID, BOT_NAME, SUDOERS, app
  23. from wbb.core.decorators.errors import capture_err
  24. from wbb.modules import ALL_MODULES
  25. from wbb.utils.dbfunctions import (get_blacklist_filters_count,
  26. get_filters_count, get_gbans_count,
  27. get_karmas_count, get_notes_count,
  28. get_served_chats, get_served_users,
  29. get_warns_count,
  30. remove_served_chat)
  31. from wbb.utils.http import get
  32. from wbb.utils.inlinefuncs import keywords_list
  33. """ CHAT WATCHER IS IN filters.py"""
  34. @app.on_message(
  35. filters.command("gstats")
  36. & filters.user(SUDOERS)
  37. & ~filters.edited
  38. )
  39. @capture_err
  40. async def global_stats(_, message):
  41. m = await app.send_message(
  42. message.chat.id,
  43. text="__**Analysing Stats**__",
  44. disable_web_page_preview=True,
  45. )
  46. # For bot served chat and users count
  47. served_chats = []
  48. chats = await get_served_chats()
  49. for chat in chats:
  50. served_chats.append(int(chat["chat_id"]))
  51. await m.edit(
  52. f"__**Generating Statistics Report, Should Take {len(served_chats)*2}+ Seconds.**__",
  53. disable_web_page_preview=True,
  54. )
  55. for served_chat in served_chats:
  56. try:
  57. await app.get_chat_members(served_chat, BOT_ID)
  58. await asyncio.sleep(2)
  59. except Exception:
  60. await remove_served_chat(served_chat)
  61. served_chats.remove(served_chat)
  62. pass
  63. served_users = await get_served_users()
  64. # Gbans count
  65. gbans = await get_gbans_count()
  66. _notes = await get_notes_count()
  67. notes_count = _notes["notes_count"]
  68. notes_chats_count = _notes["chats_count"]
  69. # Filters count across chats
  70. _filters = await get_filters_count()
  71. filters_count = _filters["filters_count"]
  72. filters_chats_count = _filters["chats_count"]
  73. # Blacklisted filters count across chats
  74. _filters = await get_blacklist_filters_count()
  75. blacklist_filters_count = _filters["filters_count"]
  76. blacklist_filters_chats_count = _filters["chats_count"]
  77. # Warns count across chats
  78. _warns = await get_warns_count()
  79. warns_count = _warns["warns_count"]
  80. warns_chats_count = _warns["chats_count"]
  81. # Karmas count across chats
  82. _karmas = await get_karmas_count()
  83. karmas_count = _karmas["karmas_count"]
  84. karmas_chats_count = _karmas["chats_count"]
  85. # Contributors/Developers count and commits on github
  86. url = "https://api.github.com/repos/thehamkercat/williambutcherbot/contributors"
  87. rurl = "https://github.com/thehamkercat/williambutcherbot"
  88. developers = await get(url)
  89. commits = 0
  90. for developer in developers:
  91. commits += developer["contributions"]
  92. developers = len(developers)
  93. # Modules info
  94. modules_count = len(ALL_MODULES)
  95. msg = f"""
  96. **Global Stats of {BOT_NAME}**:
  97. **{modules_count}** Modules Loaded
  98. **{len(keywords_list)}** Inline Modules Loaded.
  99. **{gbans}** Globally banned users.
  100. **{filters_count}** Filters, Across **{filters_chats_count}** chats.
  101. **{blacklist_filters_count}** Blacklist Filters, Across **{blacklist_filters_chats_count}** chats.
  102. **{notes_count}** Notes, Across **{notes_chats_count}** chats.
  103. **{warns_count}** Warns, Across **{warns_chats_count}** chats.
  104. **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
  105. **{len(served_users)}** Users, Across **{len(served_chats)}** chats.
  106. **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**.
  107. """
  108. await m.edit(msg, disable_web_page_preview=True)