prepare history scanner for images

This commit is contained in:
Klemek
2021-05-18 18:13:51 +02:00
parent b2858cca95
commit d5a3667cfb
4 changed files with 26 additions and 7 deletions
+3
View File
@@ -14,5 +14,8 @@ class FirstScanner(HistoryScanner):
def __init__(self):
super().__init__(help=FirstScanner.help())
def allow_message(self, *_) -> bool:
return True
def get_results(self, intro: str) -> List[str]:
return self.history.to_string(type="first")
+17 -7
View File
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import List
from typing import Callable, List
import discord
# Custom libs
@@ -10,10 +10,10 @@ from logs import ChannelLogs, MessageLog
class HistoryScanner(Scanner, ABC):
def __init__(self, *, help: str):
def __init__(self, *, valid_args: List[str] = [], help: str):
super().__init__(
has_digit_args=True,
valid_args=["all", "everyone"],
valid_args=["all", "everyone"] + valid_args,
help=help,
intro_context="",
)
@@ -30,12 +30,17 @@ class HistoryScanner(Scanner, ABC):
self.history,
self.raw_members,
all_messages=self.all_messages,
allow_message=self.allow_message,
)
@abstractmethod
def get_results(self, intro: str):
pass
@abstractmethod
def allow_message(self, channel: ChannelLogs, message: MessageLog) -> bool:
pass
@staticmethod
def analyse_message(
channel: ChannelLogs,
@@ -44,14 +49,19 @@ class HistoryScanner(Scanner, ABC):
raw_members: List[int],
*,
all_messages: bool,
allow_message: Callable
) -> bool:
impacted = False
# If author is included in the selection (empty list is all)
if (
(not message.bot or all_messages)
and len(raw_members) == 0
or message.author in raw_members
) and (message.content or message.attachment):
(
(not message.bot or all_messages)
and len(raw_members) == 0
or message.author in raw_members
)
and (message.content or message.attachment)
and allow_message(channel, message)
):
impacted = True
history.messages += [message]
return impacted
+3
View File
@@ -14,5 +14,8 @@ class LastScanner(HistoryScanner):
def __init__(self):
super().__init__(help=LastScanner.help())
def allow_message(self, *_) -> bool:
return True
def get_results(self, intro: str) -> List[str]:
return self.history.to_string(type="last")
+3
View File
@@ -14,5 +14,8 @@ class RandomScanner(HistoryScanner):
def __init__(self):
super().__init__(help=RandomScanner.help())
def allow_message(self, *_) -> bool:
return True
def get_results(self, intro: str) -> List[str]:
return self.history.to_string(type="random")