Add truths_counter command
This commit is contained in:
parent
51454440d4
commit
2130c993b0
1 changed files with 67 additions and 1 deletions
|
@ -4,7 +4,7 @@ import re
|
||||||
import discord
|
import discord
|
||||||
import io
|
import io
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from datetime import timedelta
|
from datetime import timedelta, datetime
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from typing import Iterable, Annotated
|
from typing import Iterable, Annotated
|
||||||
|
|
||||||
|
@ -183,6 +183,72 @@ class QuoteQuota(commands.Cog):
|
||||||
file=file
|
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."""
|
||||||
|
channel = discord.utils.get(ctx.guild.text_channels, name="spam")
|
||||||
|
BOT_ID = 1101439218334576742
|
||||||
|
if not channel:
|
||||||
|
return await ctx.respond(":x: Cannot find spam channel.")
|
||||||
|
|
||||||
|
await ctx.defer()
|
||||||
|
now = discord.utils.utcnow().replace(minute=0, second=0, microsecond=0)
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Counting truths, please wait.",
|
||||||
|
description="Counting truths for this hour",
|
||||||
|
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 message.author.id == BOT_ID:
|
||||||
|
if not any([x.type == "rich" for x in message.embeds]):
|
||||||
|
continue
|
||||||
|
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(hours=1), before=now):
|
||||||
|
if message.author.id == BOT_ID:
|
||||||
|
if not any([x.type == "rich" for x in message.embeds]):
|
||||||
|
continue
|
||||||
|
count_hour += 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 message.author.id == BOT_ID:
|
||||||
|
if not any([x.type == "rich" for x in message.embeds]):
|
||||||
|
continue
|
||||||
|
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 message.author.id == BOT_ID:
|
||||||
|
if not any([x.type == "rich" for x in message.embeds]):
|
||||||
|
continue
|
||||||
|
count_all_time += 1
|
||||||
|
|
||||||
|
embed.add_field(name="All time", value=f"{count_all_time:,}", inline=False)
|
||||||
|
embed.description = None
|
||||||
|
embed.title = "Truth count"
|
||||||
|
await ctx.edit(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(QuoteQuota(bot))
|
bot.add_cog(QuoteQuota(bot))
|
||||||
|
|
Loading…
Reference in a new issue