Add trump + tate
This commit is contained in:
parent
26575883ac
commit
7f2e5e1d36
1 changed files with 106 additions and 42 deletions
|
@ -183,10 +183,13 @@ class QuoteQuota(commands.Cog):
|
|||
file=file
|
||||
)
|
||||
|
||||
@commands.slash_command(name="truths")
|
||||
async def truths_counter(self, ctx: discord.ApplicationContext):
|
||||
"""Counts the number of times the word 'truth' has been said in the quotes channel."""
|
||||
async def _process_trump_truths(self, messages: list[discord.Message]) -> dict[str, int]:
|
||||
"""
|
||||
Processes the given messages to count the number of posts by Donald Trump.
|
||||
|
||||
:param messages: The messages to process
|
||||
:returns: The stats
|
||||
"""
|
||||
def is_truth(msg: discord.Message) -> bool:
|
||||
if msg.author.id == 1101439218334576742:
|
||||
if msg.created_at.timestamp() <= 1713202855.80234:
|
||||
|
@ -198,6 +201,104 @@ class QuoteQuota(commands.Cog):
|
|||
return True
|
||||
return False
|
||||
|
||||
now = discord.utils.utcnow().replace(minute=0, second=0, microsecond=0)
|
||||
counts = {
|
||||
"hour": 0,
|
||||
"day": 0,
|
||||
"week": 0,
|
||||
"all_time": 0
|
||||
}
|
||||
for message in messages:
|
||||
if is_truth(message):
|
||||
counts["all_time"] += 1
|
||||
if message.created_at > now - timedelta(hours=1):
|
||||
counts["hour"] += 1
|
||||
if message.created_at > now - timedelta(days=1):
|
||||
counts["day"] += 1
|
||||
if message.created_at > now - timedelta(days=7):
|
||||
counts["week"] += 1
|
||||
return counts
|
||||
|
||||
async def _process_tate_truths(self, messages: list[discord.Message]) -> dict[str, int]:
|
||||
"""
|
||||
Processes the given messages to count the number of posts by Andrew Tate.
|
||||
|
||||
:param messages: The messages to process
|
||||
:returns: The stats
|
||||
"""
|
||||
def is_truth(msg: discord.Message) -> bool:
|
||||
if msg.author.id == 1229496078726860921:
|
||||
# All the tate truths are already tagged.
|
||||
for __t_e in msg.embeds:
|
||||
if __t_e.type == "rich" and __t_e.colour.value == 0x5448EE:
|
||||
return True
|
||||
return False
|
||||
|
||||
now = discord.utils.utcnow().replace(minute=0, second=0, microsecond=0)
|
||||
counts = {
|
||||
"hour": 0,
|
||||
"day": 0,
|
||||
"week": 0,
|
||||
"all_time": 0,
|
||||
"per_minute": 0.0,
|
||||
"per_hour": 0.0,
|
||||
"per_day": 0.0,
|
||||
}
|
||||
for message in messages:
|
||||
if is_truth(message):
|
||||
counts["all_time"] += 1
|
||||
if message.created_at > now - timedelta(hours=1):
|
||||
counts["hour"] += 1
|
||||
if message.created_at > now - timedelta(days=1):
|
||||
counts["day"] += 1
|
||||
if message.created_at > now - timedelta(days=7):
|
||||
counts["week"] += 1
|
||||
|
||||
counts["per_minute"] = counts["hour"] / 60
|
||||
counts["per_hour"] = counts["day"] / 24
|
||||
counts["per_day"] = counts["week"] / 7
|
||||
return counts
|
||||
|
||||
async def _process_all_messages(self, channel: discord.TextChannel) -> discord.Embed:
|
||||
"""
|
||||
Processes all the messages in the given channel.
|
||||
|
||||
:param channel: The channel to process
|
||||
:returns: The stats
|
||||
"""
|
||||
embed = discord.Embed(
|
||||
title="Truth Counts",
|
||||
color=discord.Color.blurple(),
|
||||
timestamp=discord.utils.utcnow()
|
||||
)
|
||||
messages: list[discord.Message] = await channel.history(after=discord.Object(1228516325681532928)).flatten()
|
||||
trump_stats = await self._process_trump_truths(messages)
|
||||
tate_stats = await self._process_tate_truths(messages)
|
||||
|
||||
embed.add_field(
|
||||
name="Donald Trump",
|
||||
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"**Last Hour:** {trump_stats['hour']:,} ({trump_stats['per_minute']:.1f}/min)"
|
||||
),
|
||||
inline=False
|
||||
)
|
||||
embed.add_field(
|
||||
name="Andrew Tate",
|
||||
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"**Last Hour:** {tate_stats['hour']:,} ({tate_stats['per_minute']:.1f}/min)"
|
||||
)
|
||||
)
|
||||
return embed
|
||||
|
||||
@commands.slash_command(name="truths")
|
||||
async def truths_counter(self, ctx: discord.ApplicationContext):
|
||||
"""Counts the number of times the word 'truth' has been said in the quotes channel."""
|
||||
channel = discord.utils.get(ctx.guild.text_channels, name="spam")
|
||||
if not channel:
|
||||
return await ctx.respond(":x: Cannot find spam channel.")
|
||||
|
@ -207,49 +308,12 @@ class QuoteQuota(commands.Cog):
|
|||
|
||||
embed = discord.Embed(
|
||||
title="Counting truths, please wait.",
|
||||
description="Counting truths for this hour",
|
||||
description="This may take a minute depending on how insane Trump and Tate are feeling.",
|
||||
color=discord.Color.blurple(),
|
||||
timestamp=now
|
||||
)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
count_hour = 0
|
||||
count_day = 0
|
||||
count_week = 0
|
||||
count_all_time = 0
|
||||
|
||||
async for message in channel.history(limit=None, after=now - timedelta(hours=1), before=now):
|
||||
if is_truth(message):
|
||||
count_hour += 1
|
||||
|
||||
per_minute = count_hour / 60
|
||||
embed.add_field(name="This hour", value=f"{count_hour:,} ({per_minute:,.1f}/min)", inline=False)
|
||||
embed.description = "counting truths for the last 24 hours"
|
||||
await ctx.edit(embed=embed)
|
||||
|
||||
async for message in channel.history(limit=None, after=now - timedelta(days=1), before=now):
|
||||
if is_truth(message):
|
||||
count_day += 1
|
||||
per_hour = count_day / 24
|
||||
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"
|
||||
await ctx.edit(embed=embed)
|
||||
|
||||
async for message in channel.history(limit=None, after=now - timedelta(days=7), before=now):
|
||||
if is_truth(message):
|
||||
count_week += 1
|
||||
per_day = count_week / 7
|
||||
embed.add_field(name="Last 7 days", value=f"{count_week:,} ({per_day:,.1f}/day)", inline=False)
|
||||
embed.description = "counting truths for all time"
|
||||
await ctx.edit(embed=embed)
|
||||
|
||||
async for message in channel.history(limit=None, after=discord.Object(1228516325681532928)): # bot's first msg
|
||||
if is_truth(message):
|
||||
count_all_time += 1
|
||||
|
||||
embed.add_field(name="All time", value=f"{count_all_time:,}", inline=False)
|
||||
embed.description = None
|
||||
embed.title = "Truth count"
|
||||
embed = await self._process_all_messages(channel)
|
||||
await ctx.edit(embed=embed)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue