Base for new scanner
This commit is contained in:
+13
-7
@@ -2,7 +2,7 @@ from miniscord import Bot
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from utils import emojis
|
from utils import emojis
|
||||||
from scanners import EmotesScanner
|
from scanners import EmotesScanner, FrequencyScanner
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO
|
format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO
|
||||||
@@ -11,16 +11,22 @@ logging.basicConfig(
|
|||||||
emojis.load_emojis()
|
emojis.load_emojis()
|
||||||
|
|
||||||
bot = Bot(
|
bot = Bot(
|
||||||
"Discord Analyst", # name
|
"Discord Analyst",
|
||||||
"1.6(wip)", # version
|
"1.6(wip)",
|
||||||
alias="%", # respond to '|command' messages
|
alias="%",
|
||||||
)
|
)
|
||||||
bot.log_calls = True
|
bot.log_calls = True
|
||||||
bot.client.bot = bot # TODO place in miniscord
|
bot.client.bot = bot # TODO place in miniscord
|
||||||
bot.register_command(
|
bot.register_command(
|
||||||
"emotes", # command text (regex)
|
"freq(ency)?",
|
||||||
lambda *args: EmotesScanner().compute(*args), # command function
|
lambda *args: FrequencyScanner().compute(*args),
|
||||||
"emotes: Emotes analysis", # short help
|
"freq: Frequency analysis",
|
||||||
|
FrequencyScanner.help(),
|
||||||
|
)
|
||||||
|
bot.register_command(
|
||||||
|
"emotes",
|
||||||
|
lambda *args: EmotesScanner().compute(*args),
|
||||||
|
"emotes: Emotes analysis",
|
||||||
EmotesScanner.help(),
|
EmotesScanner.help(),
|
||||||
)
|
)
|
||||||
bot.start()
|
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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
has_digit_args: bool,
|
has_digit_args: bool = False,
|
||||||
valid_args: List[str],
|
valid_args: List[str] = [],
|
||||||
help: str,
|
help: str,
|
||||||
intro_context: str,
|
intro_context: str,
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user