more info when available
This commit is contained in:
@@ -37,21 +37,29 @@ class Counter:
|
|||||||
total_usage: int,
|
total_usage: int,
|
||||||
counted: str = "time",
|
counted: str = "time",
|
||||||
transform: Optional[Callable[[int], str]] = None,
|
transform: Optional[Callable[[int], str]] = None,
|
||||||
|
ranking: bool = True,
|
||||||
|
top: bool = True,
|
||||||
) -> str:
|
) -> str:
|
||||||
# place
|
# place
|
||||||
output = ""
|
output = ""
|
||||||
|
if ranking:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
output += ":first_place:"
|
output += ":first_place: "
|
||||||
elif i == 1:
|
elif i == 1:
|
||||||
output += ":second_place:"
|
output += ":second_place: "
|
||||||
elif i == 2:
|
elif i == 2:
|
||||||
output += ":third_place:"
|
output += ":third_place: "
|
||||||
else:
|
else:
|
||||||
output += f"**#{i + 1}**"
|
output += f"**#{i + 1}** "
|
||||||
|
else:
|
||||||
|
output += f"- "
|
||||||
sum = val_sum(self.usages)
|
sum = val_sum(self.usages)
|
||||||
output += f" {name} - {plural(sum, counted)} ({percent(sum/total_usage)}, last {from_now(self.last_used)})"
|
if sum > 0:
|
||||||
|
output += f"{name} - {plural(sum, counted)} ({percent(sum/total_usage)}, last {from_now(self.last_used)})"
|
||||||
|
else:
|
||||||
|
output += f"{name} - unused"
|
||||||
top_item = top_key(self.usages)
|
top_item = top_key(self.usages)
|
||||||
if top_item != 0 and transform is not None:
|
if top and top_item != 0 and transform is not None:
|
||||||
if self.usages[top_item] == sum:
|
if self.usages[top_item] == sum:
|
||||||
output += f" (all{transform(top_item)})"
|
output += f" (all{transform(top_item)})"
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class ChannelsScanner(Scanner):
|
|||||||
total_usage=usage_count,
|
total_usage=usage_count,
|
||||||
counted="message",
|
counted="message",
|
||||||
transform=lambda id: f" by {mention(id)}",
|
transform=lambda id: f" by {mention(id)}",
|
||||||
|
top=len(self.members) != 1,
|
||||||
)
|
)
|
||||||
for name in names
|
for name in names
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ class MentionedScanner(Scanner):
|
|||||||
names.index(name),
|
names.index(name),
|
||||||
name,
|
name,
|
||||||
total_usage=usage_count,
|
total_usage=usage_count,
|
||||||
|
transform=lambda id: f" for {mention(id)}",
|
||||||
|
top=len(self.members) != 1,
|
||||||
)
|
)
|
||||||
for name in names
|
for name in names
|
||||||
]
|
]
|
||||||
@@ -85,6 +87,6 @@ class MentionedScanner(Scanner):
|
|||||||
mention(member_id)
|
mention(member_id)
|
||||||
) + message.content.count(alt_mention(member_id))
|
) + message.content.count(alt_mention(member_id))
|
||||||
mentions[mention(message.author)].update_use(
|
mentions[mention(message.author)].update_use(
|
||||||
count, message.created_at
|
count, message.created_at, member_id
|
||||||
)
|
)
|
||||||
return impacted
|
return impacted
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ class MentionsScanner(Scanner):
|
|||||||
names.index(name),
|
names.index(name),
|
||||||
name,
|
name,
|
||||||
total_usage=usage_count,
|
total_usage=usage_count,
|
||||||
|
transform=lambda id: f" by {mention(id)}",
|
||||||
|
top=len(self.members) != 1,
|
||||||
)
|
)
|
||||||
for name in names
|
for name in names
|
||||||
]
|
]
|
||||||
@@ -103,24 +105,28 @@ class MentionsScanner(Scanner):
|
|||||||
count = message.content.count(name) + message.content.count(
|
count = message.content.count(name) + message.content.count(
|
||||||
alt_mention(member_id)
|
alt_mention(member_id)
|
||||||
)
|
)
|
||||||
mentions[name].update_use(count, message.created_at)
|
mentions[name].update_use(count, message.created_at, message.author)
|
||||||
if all_mentions:
|
if all_mentions:
|
||||||
for role_id in message.role_mentions:
|
for role_id in message.role_mentions:
|
||||||
name = role_mention(role_id)
|
name = role_mention(role_id)
|
||||||
mentions[name].update_use(
|
mentions[name].update_use(
|
||||||
message.content.count(name), message.created_at
|
message.content.count(name), message.created_at, message.author
|
||||||
)
|
)
|
||||||
for channel_id in message.channel_mentions:
|
for channel_id in message.channel_mentions:
|
||||||
name = channel_mention(channel_id)
|
name = channel_mention(channel_id)
|
||||||
mentions[name].update_use(
|
mentions[name].update_use(
|
||||||
message.content.count(name), message.created_at
|
message.content.count(name), message.created_at, message.author
|
||||||
)
|
)
|
||||||
if "@everyone" in message.content:
|
if "@everyone" in message.content:
|
||||||
mentions["@\u200beveryone"].update_use(
|
mentions["@\u200beveryone"].update_use(
|
||||||
message.content.count("@everyone"), message.created_at
|
message.content.count("@everyone"),
|
||||||
|
message.created_at,
|
||||||
|
message.author,
|
||||||
)
|
)
|
||||||
if "@here" in message.content:
|
if "@here" in message.content:
|
||||||
mentions["@\u200bhere"].update_use(
|
mentions["@\u200bhere"].update_use(
|
||||||
message.content.count("@here"), message.created_at
|
message.content.count("@here"),
|
||||||
|
message.created_at,
|
||||||
|
message.author,
|
||||||
)
|
)
|
||||||
return impacted
|
return impacted
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class MessagesScanner(Scanner):
|
|||||||
total_usage=usage_count,
|
total_usage=usage_count,
|
||||||
counted="message",
|
counted="message",
|
||||||
transform=lambda id: f" in {channel_mention(id)}",
|
transform=lambda id: f" in {channel_mention(id)}",
|
||||||
|
top=self.channels != 1,
|
||||||
)
|
)
|
||||||
for name in names
|
for name in names
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class ReactionsScanner(Scanner):
|
|||||||
total_usage=usage_count,
|
total_usage=usage_count,
|
||||||
counted="reaction",
|
counted="reaction",
|
||||||
transform=lambda id: f" in {channel_mention(id)}",
|
transform=lambda id: f" in {channel_mention(id)}",
|
||||||
|
top=self.channels != 1,
|
||||||
)
|
)
|
||||||
for name in names
|
for name in names
|
||||||
]
|
]
|
||||||
|
|||||||
+10
-3
@@ -27,6 +27,8 @@ from logs import (
|
|||||||
|
|
||||||
|
|
||||||
class Scanner(ABC):
|
class Scanner(ABC):
|
||||||
|
VALID_ARGS = ["me", "here", "fast", "fresh", "mobile", "mention"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@@ -34,12 +36,16 @@ class Scanner(ABC):
|
|||||||
valid_args: List[str] = [],
|
valid_args: List[str] = [],
|
||||||
help: str,
|
help: str,
|
||||||
intro_context: str,
|
intro_context: str,
|
||||||
|
all_args: bool = False,
|
||||||
):
|
):
|
||||||
self.has_digit_args = has_digit_args
|
self.has_digit_args = has_digit_args
|
||||||
self.valid_args = valid_args
|
self.valid_args = valid_args
|
||||||
|
self.all_args = all_args
|
||||||
self.help = help
|
self.help = help
|
||||||
self.intro_context = intro_context
|
self.intro_context = intro_context
|
||||||
|
|
||||||
|
self.other_args = []
|
||||||
|
|
||||||
self.members = []
|
self.members = []
|
||||||
self.raw_members = []
|
self.raw_members = []
|
||||||
self.full = False
|
self.full = False
|
||||||
@@ -86,15 +92,16 @@ class Scanner(ABC):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
if (
|
if (
|
||||||
arg
|
arg not in self.valid_args + Scanner.VALID_ARGS
|
||||||
not in self.valid_args
|
|
||||||
+ ["me", "here", "fast", "fresh", "mobile", "mention"]
|
|
||||||
and (not arg.isdigit() or not self.has_digit_args)
|
and (not arg.isdigit() or not self.has_digit_args)
|
||||||
and arg not in str_channel_mentions
|
and arg not in str_channel_mentions
|
||||||
and arg not in str_mentions
|
and arg not in str_mentions
|
||||||
and arg not in other_mentions
|
and arg not in other_mentions
|
||||||
and not skip_check
|
and not skip_check
|
||||||
):
|
):
|
||||||
|
if self.all_args:
|
||||||
|
self.other_args += [arg]
|
||||||
|
else:
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
f"Unrecognized argument: `{arg}`", reference=message
|
f"Unrecognized argument: `{arg}`", reference=message
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ import re
|
|||||||
from logs import ChannelLogs, MessageLog
|
from logs import ChannelLogs, MessageLog
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
from data_types import Counter
|
from data_types import Counter
|
||||||
from utils import (
|
from utils import generate_help, plural, precise, mention
|
||||||
generate_help,
|
|
||||||
plural,
|
|
||||||
precise,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WordsScanner(Scanner):
|
class WordsScanner(Scanner):
|
||||||
@@ -68,13 +64,14 @@ class WordsScanner(Scanner):
|
|||||||
words.sort(key=lambda word: self.words[word].score(), reverse=True)
|
words.sort(key=lambda word: self.words[word].score(), reverse=True)
|
||||||
words = words[: self.top]
|
words = words[: self.top]
|
||||||
usage_count = Counter.total(self.words)
|
usage_count = Counter.total(self.words)
|
||||||
print(len(self.words))
|
|
||||||
res = [intro.format(self.letters)]
|
res = [intro.format(self.letters)]
|
||||||
res += [
|
res += [
|
||||||
self.words[word].to_string(
|
self.words[word].to_string(
|
||||||
words.index(word),
|
words.index(word),
|
||||||
f"`{word}`",
|
f"`{word}`",
|
||||||
total_usage=usage_count,
|
total_usage=usage_count,
|
||||||
|
transform=lambda id: f" by {mention(id)}",
|
||||||
|
top=len(self.members) != 1,
|
||||||
)
|
)
|
||||||
for word in words
|
for word in words
|
||||||
]
|
]
|
||||||
@@ -121,5 +118,5 @@ class WordsScanner(Scanner):
|
|||||||
words[word] = words[word + case]
|
words[word] = words[word + case]
|
||||||
del words[word + case]
|
del words[word + case]
|
||||||
break
|
break
|
||||||
words[word].update_use(1, message.created_at)
|
words[word].update_use(1, message.created_at, message.author)
|
||||||
return impacted
|
return impacted
|
||||||
|
|||||||
Reference in New Issue
Block a user