global_stats.py 3.1 KB

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