global_stats.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. """
  2. MIT License
  3. Copyright (c) 2023 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 pyrogram.enums import ChatType
  23. from pyrogram.errors import FloodWait
  24. from wbb import BOT_ID, BOT_NAME, SUDOERS, USERBOT_NAME, app, app2
  25. from wbb.core.decorators.errors import capture_err
  26. from wbb.modules import ALL_MODULES
  27. from wbb.utils.dbfunctions import (
  28. get_blacklist_filters_count,
  29. get_filters_count,
  30. get_gbans_count,
  31. get_karmas_count,
  32. get_notes_count,
  33. get_rss_feeds_count,
  34. get_served_chats,
  35. get_served_users,
  36. get_warns_count,
  37. remove_served_chat,
  38. )
  39. from wbb.utils.http import get
  40. from wbb.utils.inlinefuncs import keywords_list
  41. @app.on_message(filters.command("clean_db") & SUDOERS)
  42. @capture_err
  43. async def clean_db(_, message):
  44. served_chats = [int(i["chat_id"]) for i in (await get_served_chats())]
  45. m = await message.reply(
  46. f"__**Cleaning database, Might take around {len(served_chats) * 2} seconds.**__",
  47. )
  48. for served_chat in served_chats:
  49. try:
  50. await app.get_chat_members(served_chat, BOT_ID)
  51. await asyncio.sleep(2)
  52. except FloodWait as e:
  53. await asyncio.sleep(int(e.x))
  54. except Exception:
  55. await remove_served_chat(served_chat)
  56. served_chats.remove(served_chat)
  57. await m.edit("**Database Cleaned.**")
  58. @app.on_message(filters.command("gstats") & SUDOERS)
  59. @capture_err
  60. async def global_stats(_, message):
  61. m = await app.send_message(
  62. message.chat.id,
  63. text="__**Analysing Stats...**__",
  64. disable_web_page_preview=True,
  65. )
  66. # For bot served chat and users count
  67. served_chats = len(await get_served_chats())
  68. served_users = len(await get_served_users())
  69. # Gbans count
  70. gbans = await get_gbans_count()
  71. _notes = await get_notes_count()
  72. notes_count = _notes["notes_count"]
  73. notes_chats_count = _notes["chats_count"]
  74. # Filters count across chats
  75. _filters = await get_filters_count()
  76. filters_count = _filters["filters_count"]
  77. filters_chats_count = _filters["chats_count"]
  78. # Blacklisted filters count across chats
  79. _filters = await get_blacklist_filters_count()
  80. blacklist_filters_count = _filters["filters_count"]
  81. blacklist_filters_chats_count = _filters["chats_count"]
  82. # Warns count across chats
  83. _warns = await get_warns_count()
  84. warns_count = _warns["warns_count"]
  85. warns_chats_count = _warns["chats_count"]
  86. # Karmas count across chats
  87. _karmas = await get_karmas_count()
  88. karmas_count = _karmas["karmas_count"]
  89. karmas_chats_count = _karmas["chats_count"]
  90. # Contributors/Developers count and commits on github
  91. url = "https://api.github.com/repos/thehamkercat/williambutcherbot/contributors"
  92. rurl = "https://github.com/thehamkercat/williambutcherbot"
  93. developers = await get(url)
  94. commits = 0
  95. for developer in developers:
  96. commits += developer["contributions"]
  97. developers = len(developers)
  98. # Rss feeds
  99. rss_count = await get_rss_feeds_count()
  100. # Modules info
  101. modules_count = len(ALL_MODULES)
  102. # Userbot info
  103. groups_ub = channels_ub = bots_ub = privates_ub = total_ub = 0
  104. async for i in app2.get_dialogs():
  105. t = i.chat.type
  106. total_ub += 1
  107. if t in [ChatType.SUPERGROUP, ChatType.GROUP]:
  108. groups_ub += 1
  109. elif t == ChatType.CHANNEL:
  110. channels_ub += 1
  111. elif t == ChatType.BOT:
  112. bots_ub += 1
  113. elif t == ChatType.PRIVATE:
  114. privates_ub += 1
  115. msg = f"""
  116. **Global Stats of {BOT_NAME}**:
  117. **{modules_count}** Modules Loaded.
  118. **{len(keywords_list)}** Inline Modules Loaded.
  119. **{rss_count}** Active RSS Feeds.
  120. **{gbans}** Globally banned users.
  121. **{filters_count}** Filters, Across **{filters_chats_count}** chats.
  122. **{blacklist_filters_count}** Blacklist Filters, Across **{blacklist_filters_chats_count}** chats.
  123. **{notes_count}** Notes, Across **{notes_chats_count}** chats.
  124. **{warns_count}** Warns, Across **{warns_chats_count}** chats.
  125. **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
  126. **{served_users}** Users, Across **{served_chats}** chats.
  127. **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**.
  128. **Global Stats of {USERBOT_NAME}**:
  129. **{total_ub} Dialogs.**
  130. **{groups_ub} Groups Joined.**
  131. **{channels_ub} Channels Joined.**
  132. **{bots_ub} Bots.**
  133. **{privates_ub} Users.**
  134. """
  135. await m.edit(msg, disable_web_page_preview=True)