feat(bot): ✨ Add banned users stat to p.stats.

This commit is contained in:
Nyeki.py
2024-10-27 17:34:01 -03:00
parent 99941874e7
commit 0e2486cb4a
+18 -2
View File
@@ -2,14 +2,13 @@ from typing import Awaitable
from datetime import datetime, timezone, timedelta
import sys
import asyncio
import discord
from discord import errors
from discord.ext import commands
from tortoise import transactions, expressions
from tortoise import transactions, expressions, functions
from procs import flush_messages
@@ -339,6 +338,19 @@ class Mods(base.Cog):
- `<wait>`: The amount of seconds to wait between iterations. Defaults to 5.
"""
async def count_banned_users() -> int:
return (
await models.Ban.filter(
expressions.Q(
expires_at=None,
expires_at__gt=datetime.now(timezone.utc),
join_type="OR",
)
)
.annotate(unique_users_count=functions.Count("user_id", distinct=True))
.values("unique_users_count")
)[0]["unique_users_count"]
stats = [
(
"On-call Channels",
@@ -372,6 +384,10 @@ class Mods(base.Cog):
)
).count(),
),
(
"Banned Users",
count_banned_users,
),
("Reports", lambda: models.Report.all().count()),
(
"On-review Reports",