From e11bbf032773a5ae4a5dc221a5836b5a97d16add Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 11 Jan 2021 12:42:59 +0100 Subject: [PATCH] template for new scanners --- src/data_types/composition.py | 17 ++++++++++++++++- src/data_types/other.py | 7 ++++++- src/scanners/composition_scanner.py | 6 +++--- src/scanners/full_scanner.py | 4 ++-- src/scanners/other_scanner.py | 17 ++++++++++++----- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/data_types/composition.py b/src/data_types/composition.py index 6bd0805..438859f 100644 --- a/src/data_types/composition.py +++ b/src/data_types/composition.py @@ -6,4 +6,19 @@ class Composition: pass # TODO def to_string(self) -> List[str]: - return [] # TODO + return [ + # f"- **avg characters / message**: n", + # f"- **plain text messages**: n - %", + # f"- **emojis in messages**: n - %", + # f"- **spoilers in messages**: n - %", + # f"- **emoji-only messages**: n - %", + # f"- **most used emoji**: xx (see more with %emotes)", + # f"- **answers**: n - %", + # f"- **links**: n - %", + # f"- **images**: n - %", + # f"- **other media**: n - %", + # f"- **mentions**: n - %", + # f"- **most mentioned member**: @x", + # f"- **everyone/here**: n - %", + # f"- **edited messages**: n - %", + ] # TODO diff --git a/src/data_types/other.py b/src/data_types/other.py index a7dd56c..5b4a0b3 100644 --- a/src/data_types/other.py +++ b/src/data_types/other.py @@ -6,4 +6,9 @@ class Other: pass # TODO def to_string(self) -> List[str]: - return [] # TODO + return [ + # f"- **most visited channel**: #c", + # f"- **mostly mentioned by**: @x", + # f"- **reactions**: n %", + # f"- **most used reaction**: xx (see more with %emotes)", + ] # TODO diff --git a/src/scanners/composition_scanner.py b/src/scanners/composition_scanner.py index 038db69..66f27a4 100644 --- a/src/scanners/composition_scanner.py +++ b/src/scanners/composition_scanner.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Dict from collections import defaultdict import discord @@ -43,7 +43,7 @@ class CompositionScanner(Scanner): return ret def get_results(self, intro: str) -> List[str]: - CompositionScanner.compute_results(self.comp) + CompositionScanner.compute_results(self.comp, self.emotes) res = [intro] res += self.comp.to_string() return res @@ -60,5 +60,5 @@ class CompositionScanner(Scanner): return impacted @staticmethod - def compute_results(comp: Composition): + def compute_results(comp: Composition, emotes: Dict[str, Emote]): pass # TODO diff --git a/src/scanners/full_scanner.py b/src/scanners/full_scanner.py index 3aaf0ad..afdd41f 100644 --- a/src/scanners/full_scanner.py +++ b/src/scanners/full_scanner.py @@ -49,8 +49,8 @@ class FullScanner(Scanner): def get_results(self, intro: str) -> List[str]: FrequencyScanner.compute_results(self.freq) - CompositionScanner.compute_results(self.comp) - OtherScanner.compute_results(self.other) + CompositionScanner.compute_results(self.comp, self.emotes) + OtherScanner.compute_results(self.other, self.emotes) res = [intro] res += ["__Frequency__:"] res += self.freq.to_string() diff --git a/src/scanners/other_scanner.py b/src/scanners/other_scanner.py index a212b84..0a5c6ea 100644 --- a/src/scanners/other_scanner.py +++ b/src/scanners/other_scanner.py @@ -1,11 +1,12 @@ -from typing import List +from typing import List, Dict import discord # Custom libs from .scanner import Scanner -from data_types import Other +from . import EmotesScanner +from data_types import Other, Emote, get_emote_dict from logs import ChannelLogs, MessageLog @@ -28,13 +29,19 @@ class OtherScanner(Scanner): async def init(self, message: discord.Message, *args: str) -> bool: self.other = Other() + # Create emotes dict from custom emojis of the guild + self.emotes = get_emote_dict(message.channel.guild) return True def compute_message(self, channel: ChannelLogs, message: MessageLog): - return OtherScanner.analyse_message(message, self.other, self.raw_members) + ret = OtherScanner.analyse_message(message, self.other, self.raw_members) + ret &= EmotesScanner.analyse_message( + message, self.emotes, self.raw_members, all_emojis=True + ) + return ret def get_results(self, intro: str) -> List[str]: - OtherScanner.compute_results(self.other) + OtherScanner.compute_results(self.other, self.emotes) res = [intro] res += self.other.to_string() return res @@ -51,5 +58,5 @@ class OtherScanner(Scanner): return impacted @staticmethod - def compute_results(other: Other): + def compute_results(other: Other, emotes: Dict[str, Emote]): pass # TODO