fixing log manager messages

This commit is contained in:
klemek
2021-01-07 10:59:11 +01:00
parent f779c699cf
commit 377012cf4a
2 changed files with 15 additions and 9 deletions
+11 -9
View File
@@ -6,6 +6,8 @@ import gzip
from datetime import datetime
import logging
from utils import code_message
LOG_DIR = "logs"
if not os.path.exists(LOG_DIR):
@@ -154,12 +156,11 @@ class GuildLogs:
async def load(
self, progress: discord.Message, target_channels: List[discord.TextChannel] = []
) -> Tuple[int, int]:
global current_analysis
if self.log_file in current_analysis:
return -1, -1
current_analysis += [self.log_file]
await progress.edit(
content=f"```Reading history...\n(this might take a while)```"
)
await code_message(progress, "Reading history...\n(this might take a while)")
# read logs
t0 = datetime.now()
if os.path.exists(self.log_file):
@@ -205,15 +206,16 @@ class GuildLogs:
"(some channels are new, this might take a long while)"
)
dt = (datetime.now() - t0).total_seconds()
await progress.edit(
content=f"```Reading history...\n{tmp_msg} messages in {total_chan + 1}/{max_chan} channels ({round(tmp_msg/dt)}m/s)\n{warning_msg}```"
await code_message(
progress,
f"Reading history...\n{tmp_msg} messages in {total_chan + 1}/{max_chan} channels ({round(tmp_msg/dt)}m/s)\n{warning_msg}",
)
if done:
total_chan += 1
total_msg += len(self.channels[channel.id].messages)
dt = (datetime.now() - t0).total_seconds()
await progress.edit(
content=f"```Saving...\n{total_msg} messages in {total_chan} channels```"
await code_message(
progress, f"Saving...\n{total_msg} messages in {total_chan} channels"
)
logging.info(f"log {self.guild.id} > queried in {dt} s -> {total_msg / dt} m/s")
# write logs
@@ -222,8 +224,8 @@ class GuildLogs:
f.write(gzip.compress(bytes(json.dumps(self.dict()), "utf-8")))
dt = (datetime.now() - t0).total_seconds()
logging.info(f"log {self.guild.id} > written in {dt} s")
await progress.edit(
content=f"```Analysing...\n{total_msg} messages in {total_chan} channels```"
await code_message(
progress, f"Analysing...\n{total_msg} messages in {total_chan} channels"
)
current_analysis.remove(self.log_file)
return total_msg, total_chan
+4
View File
@@ -9,6 +9,10 @@ def debug(message: discord.Message, txt: str):
logging.info(f"{message.guild} > #{message.channel}: {txt}")
async def code_message(message: discord.Message, content: str):
await message.edit(content=f"```\n{content}\n```")
# LISTS