Change processing engine
This commit is contained in:
parent
7f2e5e1d36
commit
2fb9fc77a2
1 changed files with 35 additions and 42 deletions
|
@ -6,7 +6,7 @@ import io
|
|||
import matplotlib.pyplot as plt
|
||||
from datetime import timedelta, datetime
|
||||
from discord.ext import commands
|
||||
from typing import Iterable, Annotated
|
||||
from typing import Callable, Iterable, Annotated
|
||||
|
||||
from conf import CONFIG
|
||||
|
||||
|
@ -183,6 +183,38 @@ class QuoteQuota(commands.Cog):
|
|||
file=file
|
||||
)
|
||||
|
||||
def _metacounter(
|
||||
self,
|
||||
messages: list[discord.Message],
|
||||
filter_func: Callable[[discord.Message], bool],
|
||||
*,
|
||||
now: datetime = None
|
||||
) -> dict[str, float | int]:
|
||||
now = now or 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 filter_func(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_trump_truths(self, messages: list[discord.Message]) -> dict[str, int]:
|
||||
"""
|
||||
Processes the given messages to count the number of posts by Donald Trump.
|
||||
|
@ -201,23 +233,7 @@ 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
|
||||
return self._metacounter(messages, is_truth)
|
||||
|
||||
async def _process_tate_truths(self, messages: list[discord.Message]) -> dict[str, int]:
|
||||
"""
|
||||
|
@ -234,30 +250,7 @@ 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,
|
||||
"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
|
||||
return self._metacounter(messages, is_truth)
|
||||
|
||||
async def _process_all_messages(self, channel: discord.TextChannel) -> discord.Embed:
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue