Make truths_counter command more accurate

This commit is contained in:
Nexus 2024-04-15 18:32:17 +01:00
parent 2130c993b0
commit 5829faba46
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -186,8 +186,19 @@ class QuoteQuota(commands.Cog):
@commands.slash_command(name="truths") @commands.slash_command(name="truths")
async def truths_counter(self, ctx: discord.ApplicationContext): async def truths_counter(self, ctx: discord.ApplicationContext):
"""Counts the number of times the word 'truth' has been said in the quotes channel.""" """Counts the number of times the word 'truth' has been said in the quotes channel."""
def is_truth(msg: discord.Message) -> bool:
if msg.author.id == 1101439218334576742:
if msg.created_at.timestamp() <= 1713202258.991351:
# Pre 6:30pm 15th April, embeds were not tagged for detection.
return any((_te.type == "rich" for _te in msg.embeds))
for __t_e in msg.embeds:
if __t_e.type == "rich" and __t_e.colour.value == 0x5448EE:
return True
return False
channel = discord.utils.get(ctx.guild.text_channels, name="spam") channel = discord.utils.get(ctx.guild.text_channels, name="spam")
BOT_ID = 1101439218334576742
if not channel: if not channel:
return await ctx.respond(":x: Cannot find spam channel.") return await ctx.respond(":x: Cannot find spam channel.")
@ -208,9 +219,7 @@ class QuoteQuota(commands.Cog):
count_all_time = 0 count_all_time = 0
async for message in channel.history(limit=None, after=now - timedelta(hours=1), before=now): async for message in channel.history(limit=None, after=now - timedelta(hours=1), before=now):
if message.author.id == BOT_ID: if is_truth(message):
if not any([x.type == "rich" for x in message.embeds]):
continue
count_hour += 1 count_hour += 1
per_minute = count_hour / 60 per_minute = count_hour / 60
@ -218,20 +227,16 @@ class QuoteQuota(commands.Cog):
embed.description = "counting truths for the last 24 hours" embed.description = "counting truths for the last 24 hours"
await ctx.edit(embed=embed) await ctx.edit(embed=embed)
async for message in channel.history(limit=None, after=now - timedelta(hours=1), before=now): async for message in channel.history(limit=None, after=now - timedelta(days=1), before=now):
if message.author.id == BOT_ID: if is_truth(message):
if not any([x.type == "rich" for x in message.embeds]): count_day += 1
continue
count_hour += 1
per_hour = count_day / 24 per_hour = count_day / 24
embed.add_field(name="Last 24 hours", value=f"{count_day:,} ({per_hour:,.1f}/hour)", inline=False) embed.add_field(name="Last 24 hours", value=f"{count_day:,} ({per_hour:,.1f}/hour)", inline=False)
embed.description = "counting truths for the last 7 days" embed.description = "counting truths for the last 7 days"
await ctx.edit(embed=embed) await ctx.edit(embed=embed)
async for message in channel.history(limit=None, after=now - timedelta(days=7), before=now): async for message in channel.history(limit=None, after=now - timedelta(days=7), before=now):
if message.author.id == BOT_ID: if is_truth(message):
if not any([x.type == "rich" for x in message.embeds]):
continue
count_week += 1 count_week += 1
per_day = count_week / 7 per_day = count_week / 7
embed.add_field(name="Last 7 days", value=f"{count_week:,} ({per_day:,.1f}/day)", inline=False) embed.add_field(name="Last 7 days", value=f"{count_week:,} ({per_day:,.1f}/day)", inline=False)