Base for new scanner
This commit is contained in:
+13
-7
@@ -2,7 +2,7 @@ from miniscord import Bot
|
||||
import logging
|
||||
|
||||
from utils import emojis
|
||||
from scanners import EmotesScanner
|
||||
from scanners import EmotesScanner, FrequencyScanner
|
||||
|
||||
logging.basicConfig(
|
||||
format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO
|
||||
@@ -11,16 +11,22 @@ logging.basicConfig(
|
||||
emojis.load_emojis()
|
||||
|
||||
bot = Bot(
|
||||
"Discord Analyst", # name
|
||||
"1.6(wip)", # version
|
||||
alias="%", # respond to '|command' messages
|
||||
"Discord Analyst",
|
||||
"1.6(wip)",
|
||||
alias="%",
|
||||
)
|
||||
bot.log_calls = True
|
||||
bot.client.bot = bot # TODO place in miniscord
|
||||
bot.register_command(
|
||||
"emotes", # command text (regex)
|
||||
lambda *args: EmotesScanner().compute(*args), # command function
|
||||
"emotes: Emotes analysis", # short help
|
||||
"freq(ency)?",
|
||||
lambda *args: FrequencyScanner().compute(*args),
|
||||
"freq: Frequency analysis",
|
||||
FrequencyScanner.help(),
|
||||
)
|
||||
bot.register_command(
|
||||
"emotes",
|
||||
lambda *args: EmotesScanner().compute(*args),
|
||||
"emotes: Emotes analysis",
|
||||
EmotesScanner.help(),
|
||||
)
|
||||
bot.start()
|
||||
|
||||
@@ -1 +1 @@
|
||||
from .emotes_scanner import EmotesScanner
|
||||
from .emotes_scanner import EmotesScanner, FrequencyScanner
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
from typing import List
|
||||
import discord
|
||||
|
||||
|
||||
# Custom libs
|
||||
|
||||
from .scanner import Scanner
|
||||
from utils.log_manager import ChannelLogs, MessageLog
|
||||
|
||||
|
||||
class FrequencyScanner(Scanner):
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return "```\n"
|
||||
+"%freq : Show frequency-related statistics\n"
|
||||
+"arguments:\n"
|
||||
+"* @member : filter for one or more member\n"
|
||||
+"* #channel : filter for one or more channel\n"
|
||||
+"Example: %freq #mychannel1 @user\n"
|
||||
+"```"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
help=FrequencyScanner.help(),
|
||||
intro_context="frequency",
|
||||
)
|
||||
|
||||
async def compute_args(self, message: discord.Message, *args: str) -> bool:
|
||||
return True
|
||||
|
||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||
return FrequencyScanner.analyse_message(message, self.raw_members)
|
||||
|
||||
def get_results(self, intro: str) -> List[str]:
|
||||
res = [intro]
|
||||
# TODO
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def analyse_message(message: MessageLog, 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
|
||||
# TODO
|
||||
return impacted
|
||||
|
||||
@@ -12,8 +12,8 @@ class Scanner(ABC):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
has_digit_args: bool,
|
||||
valid_args: List[str],
|
||||
has_digit_args: bool = False,
|
||||
valid_args: List[str] = [],
|
||||
help: str,
|
||||
intro_context: str,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user