small fixes

This commit is contained in:
klemek
2021-01-11 19:34:22 +01:00
parent d48031e4b5
commit daad1a1563
6 changed files with 28 additions and 24 deletions
+5 -6
View File
@@ -8,7 +8,7 @@ import discord
from logs import ChannelLogs, MessageLog
from data_types import Emote, get_emote_dict
from .scanner import Scanner
from utils import emojis, COMMON_HELP_ARGS
from utils import emojis, COMMON_HELP_ARGS, plural, precise
class EmotesScanner(Scanner):
@@ -50,8 +50,7 @@ class EmotesScanner(Scanner):
len(self.members) == 0 or len(self.members) > 1
)
# Create emotes dict from custom emojis of the guild
# Create emotes dict from custom emojis of the guild
self.emotes = get_emote_dict(message.channel.guild)
self.emotes = get_emote_dict(guild)
return True
def compute_message(self, channel: ChannelLogs, message: MessageLog):
@@ -79,10 +78,10 @@ class EmotesScanner(Scanner):
usage_count += self.emotes[name].usages
reaction_count += self.emotes[name].reactions
res += [
f"Total: {usage_count:,} times ({usage_count / self.msg_count:.4f} / message)"
f"Total: {plural(usage_count,'time')} ({precise(usage_count/self.msg_count)}/msg)"
]
if reaction_count > 0:
res[-1] += f" and {reaction_count:,} reactions"
res[-1] += f" and {plural(reaction_count, 'reaction')}"
return res
@staticmethod
@@ -95,7 +94,7 @@ class EmotesScanner(Scanner):
) -> bool:
impacted = False
# If author is included in the selection (empty list is all)
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
if not message.bot and len(raw_members) == 0 or message.author in raw_members:
impacted = True
# Find all emotes un the current message in the form "<:emoji:123456789>"
# Filter for known emotes
+6 -6
View File
@@ -1,13 +1,12 @@
from typing import List
from collections import defaultdict
import discord
# Custom libs
from .scanner import Scanner
from . import FrequencyScanner, CompositionScanner, PresenceScanner, EmotesScanner
from data_types import Frequency, Composition, Presence, get_emote_dict
from . import FrequencyScanner, CompositionScanner, PresenceScanner
from data_types import Frequency, Composition, Presence
from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS
@@ -31,7 +30,6 @@ class FullScanner(Scanner):
)
async def init(self, message: discord.Message, *args: str) -> bool:
guild = message.channel.guild
self.freq = Frequency()
self.compo = Composition()
self.pres = Presence()
@@ -42,8 +40,10 @@ class FullScanner(Scanner):
FrequencyScanner.analyse_message(message, self.freq, self.raw_members)
CompositionScanner.analyse_message(message, self.compo, self.raw_members)
PresenceScanner.analyse_message(channel, message, self.pres, self.raw_members)
return not message.bot and (
len(self.raw_members) == 0 or message.author in self.raw_members
return (
not message.bot
and len(self.raw_members) == 0
or message.author in self.raw_members
)
def get_results(self, intro: str) -> List[str]:
+1 -1
View File
@@ -57,7 +57,7 @@ class PresenceScanner(Scanner):
) -> bool:
impacted = False
# If author is included in the selection (empty list is all)
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
if not message.bot and len(raw_members) == 0 or message.author in raw_members:
impacted = True
pres.channel_usage[channel.id] += 1
for mention in message.mentions: