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 from datetime import datetime, timezone, timedelta
import sys
import asyncio import asyncio
import discord import discord
from discord import errors from discord import errors
from discord.ext import commands from discord.ext import commands
from tortoise import transactions, expressions from tortoise import transactions, expressions, functions
from procs import flush_messages 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. - `<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 = [ stats = [
( (
"On-call Channels", "On-call Channels",
@@ -372,6 +384,10 @@ class Mods(base.Cog):
) )
).count(), ).count(),
), ),
(
"Banned Users",
count_banned_users,
),
("Reports", lambda: models.Report.all().count()), ("Reports", lambda: models.Report.all().count()),
( (
"On-review Reports", "On-review Reports",