full scanner
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .emote import Emote
|
||||
from .emote import Emote, get_emote_dict
|
||||
from .frequency import Frequency
|
||||
from .composition import Composition
|
||||
from .other import Other
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Dict
|
||||
from datetime import datetime
|
||||
from collections import defaultdict
|
||||
import discord
|
||||
@@ -77,3 +77,10 @@ class Emote:
|
||||
if show_members:
|
||||
output += f" (mostly by {mention(self.get_top_member())}: {self.members[self.get_top_member()]})"
|
||||
return output
|
||||
|
||||
|
||||
def get_emote_dict(guild: discord.Guild) -> Dict[str, Emote]:
|
||||
emotes = defaultdict(Emote)
|
||||
for emoji in guild.emojis:
|
||||
emotes[str(emoji)] = Emote(emoji)
|
||||
return emotes
|
||||
|
||||
+13
-1
@@ -2,7 +2,13 @@ from miniscord import Bot
|
||||
import logging
|
||||
|
||||
from utils import emojis
|
||||
from scanners import EmotesScanner, FrequencyScanner, CompositionScanner, OtherScanner
|
||||
from scanners import (
|
||||
EmotesScanner,
|
||||
FullScanner,
|
||||
FrequencyScanner,
|
||||
CompositionScanner,
|
||||
OtherScanner,
|
||||
)
|
||||
|
||||
logging.basicConfig(
|
||||
format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO
|
||||
@@ -43,5 +49,11 @@ bot.register_command(
|
||||
"freq: frequency analysis",
|
||||
FrequencyScanner.help(),
|
||||
)
|
||||
bot.register_command(
|
||||
"full",
|
||||
lambda *args: FullScanner().compute(*args),
|
||||
"full: full analysis",
|
||||
FullScanner.help(),
|
||||
)
|
||||
|
||||
bot.start()
|
||||
|
||||
@@ -2,3 +2,4 @@ from .emotes_scanner import EmotesScanner
|
||||
from .frequency_scanner import FrequencyScanner
|
||||
from .composition_scanner import CompositionScanner
|
||||
from .other_scanner import OtherScanner
|
||||
from .full_scanner import FullScanner
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
from typing import List
|
||||
from collections import defaultdict
|
||||
import discord
|
||||
|
||||
|
||||
# Custom libs
|
||||
|
||||
from .scanner import Scanner
|
||||
from data_types import Composition
|
||||
from . import EmotesScanner
|
||||
from data_types import Composition, Emote, get_emote_dict
|
||||
from logs import ChannelLogs, MessageLog
|
||||
|
||||
|
||||
@@ -27,14 +29,21 @@ class CompositionScanner(Scanner):
|
||||
)
|
||||
|
||||
async def init(self, message: discord.Message, *args: str) -> bool:
|
||||
guild = message.channel.guild
|
||||
self.comp = Composition()
|
||||
# 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 Composition.analyse_message(message, self.comp, self.raw_members)
|
||||
ret = CompositionScanner.analyse_message(message, self.comp, 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]:
|
||||
Composition.compute_results(self.comp)
|
||||
CompositionScanner.compute_results(self.comp)
|
||||
res = [intro]
|
||||
res += self.comp.to_string()
|
||||
return res
|
||||
@@ -46,6 +55,7 @@ class CompositionScanner(Scanner):
|
||||
impacted = False
|
||||
# If author is included in the selection (empty list is all)
|
||||
if len(raw_members) == 0 or message.author in raw_members:
|
||||
impacted = True
|
||||
pass # TODO
|
||||
return impacted
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import discord
|
||||
# Custom libs
|
||||
|
||||
from logs import ChannelLogs, MessageLog
|
||||
from data_types import Emote
|
||||
from data_types import Emote, get_emote_dict
|
||||
from .scanner import Scanner
|
||||
from utils import emojis
|
||||
|
||||
@@ -49,9 +49,8 @@ class EmotesScanner(Scanner):
|
||||
len(self.members) == 0 or len(self.members) > 1
|
||||
)
|
||||
# Create emotes dict from custom emojis of the guild
|
||||
self.emotes = defaultdict(Emote)
|
||||
for emoji in guild.emojis:
|
||||
self.emotes[str(emoji)] = Emote(emoji)
|
||||
# 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):
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
from typing import List
|
||||
from collections import defaultdict
|
||||
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 logs import ChannelLogs, MessageLog
|
||||
|
||||
|
||||
class FullScanner(Scanner):
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return "```\n"
|
||||
+"%full : Show full statistics\n"
|
||||
+"arguments:\n"
|
||||
+"* @member : filter for one or more member\n"
|
||||
+"* #channel : filter for one or more channel\n"
|
||||
+"Example: %full #mychannel1 @user\n"
|
||||
+"```"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
help=FullScanner.help(),
|
||||
intro_context="Full analysis",
|
||||
)
|
||||
|
||||
async def init(self, message: discord.Message, *args: str) -> bool:
|
||||
guild = message.channel.guild
|
||||
self.freq = Frequency()
|
||||
self.comp = Composition()
|
||||
self.other = Other()
|
||||
# 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)
|
||||
return True
|
||||
|
||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||
ret = FrequencyScanner.analyse_message(message, self.freq, self.raw_members)
|
||||
ret &= CompositionScanner.analyse_message(message, self.comp, 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]:
|
||||
FrequencyScanner.compute_results(self.freq)
|
||||
CompositionScanner.compute_results(self.comp)
|
||||
OtherScanner.compute_results(self.other)
|
||||
res = [intro]
|
||||
res += ["__Frequency__:"]
|
||||
res += self.freq.to_string()
|
||||
res += ["__Composition__:"]
|
||||
res += self.comp.to_string()
|
||||
res += ["__Other__:"]
|
||||
res += self.other.to_string()
|
||||
return res
|
||||
@@ -46,6 +46,7 @@ class OtherScanner(Scanner):
|
||||
impacted = False
|
||||
# If author is included in the selection (empty list is all)
|
||||
if len(raw_members) == 0 or message.author in raw_members:
|
||||
impacted = True
|
||||
pass # TODO
|
||||
return impacted
|
||||
|
||||
|
||||
Reference in New Issue
Block a user