Add "today" truth counter

This commit is contained in:
Nexus 2024-04-16 11:40:13 +01:00
parent cbd3b47aed
commit aa017fca6c
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -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)"
),
)