From ae9cc69ed22fc54fec5bf1dc0762836000f30c86 Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 11 Jan 2021 16:35:33 +0100 Subject: [PATCH] Other => Presence --- src/data_types/__init__.py | 2 +- src/data_types/{other.py => presence.py} | 2 +- src/main.py | 10 ++-- src/scanners/__init__.py | 2 +- src/scanners/full_scanner.py | 14 +++--- .../{other_scanner.py => presence_scanner.py} | 47 ++++++++++--------- 6 files changed, 40 insertions(+), 37 deletions(-) rename src/data_types/{other.py => presence.py} (99%) rename src/scanners/{other_scanner.py => presence_scanner.py} (56%) diff --git a/src/data_types/__init__.py b/src/data_types/__init__.py index 1d1172b..aa734be 100644 --- a/src/data_types/__init__.py +++ b/src/data_types/__init__.py @@ -1,4 +1,4 @@ from .emote import Emote, get_emote_dict from .frequency import Frequency from .composition import Composition -from .other import Other +from .presence import Presence diff --git a/src/data_types/other.py b/src/data_types/presence.py similarity index 99% rename from src/data_types/other.py rename to src/data_types/presence.py index c54ed55..1f269cb 100644 --- a/src/data_types/other.py +++ b/src/data_types/presence.py @@ -5,7 +5,7 @@ from collections import defaultdict from utils import mention, channel_mention, plural -class Other: +class Presence: def __init__(self): self.most_used_reaction = "" self.most_used_reaction_count = 0 diff --git a/src/main.py b/src/main.py index db04992..0e5bfec 100644 --- a/src/main.py +++ b/src/main.py @@ -7,7 +7,7 @@ from scanners import ( FullScanner, FrequencyScanner, CompositionScanner, - OtherScanner, + PresenceScanner, ) logging.basicConfig( @@ -26,10 +26,10 @@ bot.log_calls = True bot.client.bot = bot # TODO place in miniscord bot.register_command( - "other", - lambda *args: OtherScanner().compute(*args), - "other: other data analysis", - OtherScanner.help(), + "pres(ence)?", + lambda *args: PresenceScanner().compute(*args), + "pres: presence analysis", + PresenceScanner.help(), ) bot.register_command( "emotes", diff --git a/src/scanners/__init__.py b/src/scanners/__init__.py index 37c6e4c..51b5d69 100644 --- a/src/scanners/__init__.py +++ b/src/scanners/__init__.py @@ -1,5 +1,5 @@ from .emotes_scanner import EmotesScanner from .frequency_scanner import FrequencyScanner from .composition_scanner import CompositionScanner -from .other_scanner import OtherScanner +from .presence_scanner import PresenceScanner from .full_scanner import FullScanner diff --git a/src/scanners/full_scanner.py b/src/scanners/full_scanner.py index 7b5268a..d780d91 100644 --- a/src/scanners/full_scanner.py +++ b/src/scanners/full_scanner.py @@ -6,8 +6,8 @@ import discord # Custom libs from .scanner import Scanner -from . import FrequencyScanner, CompositionScanner, OtherScanner, EmotesScanner -from data_types import Frequency, Composition, Other, Emote, get_emote_dict +from . import FrequencyScanner, CompositionScanner, PresenceScanner, EmotesScanner +from data_types import Frequency, Composition, Presence, Emote, get_emote_dict from logs import ChannelLogs, MessageLog @@ -32,7 +32,7 @@ class FullScanner(Scanner): guild = message.channel.guild self.freq = Frequency() self.comp = Composition() - self.other = Other() + self.pres = Presence() # 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) @@ -41,7 +41,7 @@ class FullScanner(Scanner): def compute_message(self, channel: ChannelLogs, message: MessageLog): FrequencyScanner.analyse_message(message, self.freq, self.raw_members) CompositionScanner.analyse_message(message, self.comp, self.raw_members) - OtherScanner.analyse_message(channel, message, self.other, self.raw_members) + PresenceScanner.analyse_message(channel, message, self.pres, self.raw_members) EmotesScanner.analyse_message( message, self.emotes, self.raw_members, all_emojis=True ) @@ -52,14 +52,14 @@ class FullScanner(Scanner): def get_results(self, intro: str) -> List[str]: FrequencyScanner.compute_results(self.freq) CompositionScanner.compute_results(self.comp, self.emotes) - OtherScanner.compute_results(self.other, self.emotes) + PresenceScanner.compute_results(self.pres, self.emotes) res = [intro] res += ["__Frequency__:"] res += self.freq.to_string() res += ["__Composition__:"] res += self.comp.to_string() - res += ["__Other__:"] - res += self.other.to_string( + res += ["__Presence__:"] + res += self.pres.to_string( show_top_channel=len(self.channels) > 1, show_mentioned=(len(self.members) > 0), ) diff --git a/src/scanners/other_scanner.py b/src/scanners/presence_scanner.py similarity index 56% rename from src/scanners/other_scanner.py rename to src/scanners/presence_scanner.py index c48e193..82758c6 100644 --- a/src/scanners/other_scanner.py +++ b/src/scanners/presence_scanner.py @@ -6,29 +6,29 @@ import discord from .scanner import Scanner from . import EmotesScanner -from data_types import Other, Emote, get_emote_dict +from data_types import Presence, Emote, get_emote_dict from logs import ChannelLogs, MessageLog -class OtherScanner(Scanner): +class PresenceScanner(Scanner): @staticmethod def help() -> str: return "```\n" - +"%other : Show other statistics\n" + +"%pres : Show presence statistics\n" +"arguments:\n" +"* @member/me : filter for one or more member\n" +"* #channel/here : filter for one or more channel\n" - +"Example: %other #mychannel1 @user\n" + +"Example: %pres #mychannel1 @user\n" +"```" def __init__(self): super().__init__( - help=OtherScanner.help(), - intro_context="Other data", + help=PresenceScanner.help(), + intro_context="Presence", ) async def init(self, message: discord.Message, *args: str) -> bool: - self.other = Other() + self.pres = Presence() # Create emotes dict from custom emojis of the guild self.emotes = get_emote_dict(message.channel.guild) return True @@ -37,40 +37,43 @@ class OtherScanner(Scanner): EmotesScanner.analyse_message( message, self.emotes, self.raw_members, all_emojis=True ) - return OtherScanner.analyse_message( - channel, message, self.other, self.raw_members + return PresenceScanner.analyse_message( + channel, message, self.pres, self.raw_members ) def get_results(self, intro: str) -> List[str]: - OtherScanner.compute_results(self.other, self.emotes) + PresenceScanner.compute_results(self.pres, self.emotes) res = [intro] - res += self.other.to_string( - show_top_channel=len(self.channels) > 1, + res += self.pres.to_string( + show_top_channel=(len(self.channels) > 1), show_mentioned=(len(self.members) > 0), ) return res @staticmethod def analyse_message( - channel: ChannelLogs, message: MessageLog, other: Other, raw_members: List[int] + channel: ChannelLogs, + message: MessageLog, + pres: Presence, + raw_members: List[int], ) -> 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): impacted = True - other.channel_usage[channel.id] += 1 + pres.channel_usage[channel.id] += 1 for mention in message.mentions: if mention in raw_members: - other.mentions[mention] += 1 + pres.mentions[mention] += 1 return impacted @staticmethod - def compute_results(other: Other, emotes: Dict[str, Emote]): + def compute_results(pres: Presence, emotes: Dict[str, Emote]): # calculate total reactions - other.used_reaction_total = sum([emote.reactions for emote in emotes.values()]) - if other.used_reaction_total > 0: + pres.used_reaction_total = sum([emote.reactions for emote in emotes.values()]) + if pres.used_reaction_total > 0: # calculate most used reaction - other.most_used_reaction = sorted( - emotes, key=lambda k: emotes[k].reactions - )[-1] - other.most_used_reaction_count = emotes[other.most_used_reaction].reactions + pres.most_used_reaction = sorted(emotes, key=lambda k: emotes[k].reactions)[ + -1 + ] + pres.most_used_reaction_count = emotes[pres.most_used_reaction].reactions