blacked
This commit is contained in:
@@ -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 = []
|
||||||
@@ -40,7 +41,7 @@ class History:
|
|||||||
message = random.choice(self.messages)
|
message = random.choice(self.messages)
|
||||||
real_message = await message.fetch()
|
real_message = await message.fetch()
|
||||||
tries += 1
|
tries += 1
|
||||||
|
|
||||||
if real_message is None:
|
if real_message is None:
|
||||||
return ["There was no messages matching your filters"]
|
return ["There was no messages matching your filters"]
|
||||||
image = "<Error>"
|
image = "<Error>"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -76,14 +76,13 @@ class MessageLog:
|
|||||||
self.reactions[str(reaction.emoji)] = []
|
self.reactions[str(reaction.emoji)] = []
|
||||||
async for user in reaction.users():
|
async for user in reaction.users():
|
||||||
self.reactions[str(reaction.emoji)] += [user.id]
|
self.reactions[str(reaction.emoji)] += [user.id]
|
||||||
|
|
||||||
async def fetch(self) -> Optional[discord.Message]:
|
async def fetch(self) -> Optional[discord.Message]:
|
||||||
try:
|
try:
|
||||||
return await self.channel.channel.fetch_message(self.id)
|
return await self.channel.channel.fetch_message(self.id)
|
||||||
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"]
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
+28
-14
@@ -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,
|
||||||
@@ -149,18 +159,22 @@ class Scanner(ABC):
|
|||||||
self.nsfw = FilterLevel.ONLY
|
self.nsfw = FilterLevel.ONLY
|
||||||
else:
|
else:
|
||||||
self.nsfw = FilterLevel.NONE
|
self.nsfw = FilterLevel.NONE
|
||||||
|
|
||||||
# fix nsfw filter if channel specified
|
# fix nsfw filter if channel specified
|
||||||
if not self.full and any(channel.nsfw for channel in self.channels):
|
if not self.full and any(channel.nsfw for channel in self.channels):
|
||||||
self.nsfw = FilterLevel.ALLOW
|
self.nsfw = FilterLevel.ALLOW
|
||||||
elif all(channel.nsfw for channel in self.channels):
|
elif all(channel.nsfw for channel in self.channels):
|
||||||
self.nsfw = FilterLevel.ONLY
|
self.nsfw = FilterLevel.ONLY
|
||||||
|
|
||||||
# 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
|
||||||
@@ -244,15 +258,15 @@ class Scanner(ABC):
|
|||||||
# Display results
|
# Display results
|
||||||
t0 = datetime.now()
|
t0 = datetime.now()
|
||||||
intro = get_intro(
|
intro = get_intro(
|
||||||
self.intro_context,
|
self.intro_context,
|
||||||
self.full,
|
self.full,
|
||||||
self.channels,
|
self.channels,
|
||||||
self.members,
|
self.members,
|
||||||
self.msg_count,
|
self.msg_count,
|
||||||
self.chan_count,
|
self.chan_count,
|
||||||
self.start_date,
|
self.start_date,
|
||||||
self.stop_date,
|
self.stop_date,
|
||||||
)
|
)
|
||||||
if inspect.iscoroutinefunction(self.get_results):
|
if inspect.iscoroutinefunction(self.get_results):
|
||||||
results = await self.get_results(intro)
|
results = await self.get_results(intro)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class FakeMessage:
|
|||||||
def __init__(self, id: int):
|
def __init__(self, id: int):
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
|
||||||
# FILE
|
# FILE
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user