This commit is contained in:
Klemek
2021-05-19 13:33:15 +02:00
parent 516eb75b5c
commit da5e3fdb35
7 changed files with 47 additions and 23 deletions
+7 -2
View File
@@ -48,7 +48,10 @@ class FindScanner(Scanner):
reference=message,
)
return False
self.queries = [(query, query.strip("`") if re.match(r"^`.*`$", query) else None) for query in self.other_args]
self.queries = [
(query, query.strip("`") if re.match(r"^`.*`$", query) else None)
for query in self.other_args
]
return True
def compute_message(self, channel: ChannelLogs, message: MessageLog):
@@ -125,5 +128,7 @@ class FindScanner(Scanner):
if count > 0:
matches[message.author].update_use(count, message.created_at)
else:
matches[query[0]].update_use(count, message.created_at, message.author)
matches[query[0]].update_use(
count, message.created_at, message.author
)
return impacted
+7 -1
View File
@@ -25,7 +25,13 @@ class HistoryScanner(Scanner, ABC):
self.all_messages = "all" in args or "everyone" in args
self.images_only = "image" in args
if not self.images_only:
self.queries = [(query.lower(), query.strip("`") if re.match(r"^`.*`$", query) else None) for query in self.other_args]
self.queries = [
(
query.lower(),
query.strip("`") if re.match(r"^`.*`$", query) else None,
)
for query in self.other_args
]
else:
self.queries = []
return True
+28 -14
View File
@@ -30,7 +30,17 @@ from logs import (
class Scanner(ABC):
VALID_ARGS = ["me", "here", "fast", "fresh", "mobile", "mention", "nsfw", "nsfw:allow", "nsfw:only"]
VALID_ARGS = [
"me",
"here",
"fast",
"fresh",
"mobile",
"mention",
"nsfw",
"nsfw:allow",
"nsfw:only",
]
def __init__(
self,
@@ -149,18 +159,22 @@ class Scanner(ABC):
self.nsfw = FilterLevel.ONLY
else:
self.nsfw = FilterLevel.NONE
# fix nsfw filter if channel specified
if not self.full and any(channel.nsfw for channel in self.channels):
self.nsfw = FilterLevel.ALLOW
elif all(channel.nsfw for channel in self.channels):
self.nsfw = FilterLevel.ONLY
# filter nsfw channels
if self.nsfw == FilterLevel.NONE:
self.channels = list(filter(lambda channel:not channel.nsfw, self.channels))
self.channels = list(
filter(lambda channel: not channel.nsfw, self.channels)
)
elif self.nsfw == FilterLevel.ONLY:
self.channels = list(filter(lambda channel:channel.nsfw, self.channels))
self.channels = list(
filter(lambda channel: channel.nsfw, self.channels)
)
if not await self.init(message, *args):
return
@@ -244,15 +258,15 @@ class Scanner(ABC):
# Display results
t0 = datetime.now()
intro = get_intro(
self.intro_context,
self.full,
self.channels,
self.members,
self.msg_count,
self.chan_count,
self.start_date,
self.stop_date,
)
self.intro_context,
self.full,
self.channels,
self.members,
self.msg_count,
self.chan_count,
self.start_date,
self.stop_date,
)
if inspect.iscoroutinefunction(self.get_results):
results = await self.get_results(intro)
else: