From aa017fca6c29f14ccd3226ef463a0095e7509b0a Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 16 Apr 2024 11:40:13 +0100 Subject: [PATCH] Add "today" truth counter --- src/cogs/quote_quota.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cogs/quote_quota.py b/src/cogs/quote_quota.py index dd56333..56da82f 100644 --- a/src/cogs/quote_quota.py +++ b/src/cogs/quote_quota.py @@ -174,10 +174,14 @@ class QuoteQuota(commands.Cog): def _metacounter( self, messages: list[discord.Message], filter_func: Callable[[discord.Message], bool], *, now: datetime = None ) -> dict[str, float | int]: + def _is_today(date: datetime) -> bool: + return date.date() == now.date() + now = now or discord.utils.utcnow().replace(minute=0, second=0, microsecond=0) counts = { "hour": 0, "day": 0, + "today": 0, "week": 0, "all_time": 0, "per_minute": 0.0, @@ -189,6 +193,8 @@ class QuoteQuota(commands.Cog): age = now - message.created_at self.log.debug("%r was a truth (%.2f seconds ago).", message.id, age.total_seconds()) counts["all_time"] += 1 + if _is_today(message.created_at): + counts["today"] += 1 if message.created_at > now - timedelta(hours=1): counts["hour"] += 1 if message.created_at > now - timedelta(days=1): @@ -264,7 +270,8 @@ class QuoteQuota(commands.Cog): value=( f"**All time:** {trump_stats['all_time']:,}\n" f"**Last Week:** {trump_stats['week']:,} ({trump_stats['per_day']:.1f}/day)\n" - f"**Last Day:** {trump_stats['day']:,} ({trump_stats['per_hour']:.1f}/hour)\n" + f"**Today:** {trump_stats['today']:,}\n" + f"**Last 24 Hours:** {trump_stats['day']:,} ({trump_stats['per_hour']:.1f}/hour)\n" f"**Last Hour:** {trump_stats['hour']:,} ({trump_stats['per_minute']:.1f}/min)" ), ) @@ -273,7 +280,8 @@ class QuoteQuota(commands.Cog): value=( f"**All time:** {tate_stats['all_time']:,}\n" f"**Last Week:** {tate_stats['week']:,} ({tate_stats['per_day']:.1f}/day)\n" - f"**Last Day:** {tate_stats['day']:,} ({tate_stats['per_hour']:.1f}/hour)\n" + f"**Today:** {tate_stats['today']:,}\n" + f"**Last 24 Hours:** {tate_stats['day']:,} ({tate_stats['per_hour']:.1f}/hour)\n" f"**Last Hour:** {tate_stats['hour']:,} ({tate_stats['per_minute']:.1f}/min)" ), )