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
+1
View File
@@ -7,6 +7,7 @@ from utils import mention, from_now, str_datetime, message_link, SPLIT_TOKEN
MAX_RANDOM_TRIES = 10 MAX_RANDOM_TRIES = 10
class History: class History:
def __init__(self): def __init__(self):
self.messages = [] self.messages = []
+1 -3
View File
@@ -131,8 +131,6 @@ class ChannelLogs:
yield len(self.messages), True yield len(self.messages), True
def dict(self) -> dict: def dict(self) -> dict:
channel = serialize( channel = serialize(self, not_serialized=["channel", "guild", "start_date"])
self, not_serialized=["channel", "guild", "start_date"]
)
channel["messages"] = [message.dict() for message in self.messages] channel["messages"] = [message.dict() for message in self.messages]
return channel return channel
-1
View File
@@ -83,7 +83,6 @@ class MessageLog:
except (discord.NotFound, discord.Forbidden, discord.HTTPException): except (discord.NotFound, discord.Forbidden, discord.HTTPException):
return None return None
def dict(self) -> dict: def dict(self) -> dict:
return serialize( return serialize(
self, not_serialized=["channel"], dates=["created_at", "edited_at"] self, not_serialized=["channel"], dates=["created_at", "edited_at"]
+7 -2
View File
@@ -48,7 +48,10 @@ class FindScanner(Scanner):
reference=message, reference=message,
) )
return False 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 return True
def compute_message(self, channel: ChannelLogs, message: MessageLog): def compute_message(self, channel: ChannelLogs, message: MessageLog):
@@ -125,5 +128,7 @@ class FindScanner(Scanner):
if count > 0: if count > 0:
matches[message.author].update_use(count, message.created_at) matches[message.author].update_use(count, message.created_at)
else: 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 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.all_messages = "all" in args or "everyone" in args
self.images_only = "image" in args self.images_only = "image" in args
if not self.images_only: 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: else:
self.queries = [] self.queries = []
return True return True
+17 -3
View File
@@ -30,7 +30,17 @@ from logs import (
class Scanner(ABC): 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__( def __init__(
self, self,
@@ -158,9 +168,13 @@ class Scanner(ABC):
# filter nsfw channels # filter nsfw channels
if self.nsfw == FilterLevel.NONE: 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: 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): if not await self.init(message, *args):
return return
+1
View File
@@ -99,6 +99,7 @@ class FakeMessage:
def __init__(self, id: int): def __init__(self, id: int):
self.id = id self.id = id
# FILE # FILE