fixing log manager messages
This commit is contained in:
+11
-9
@@ -6,6 +6,8 @@ import gzip
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from utils import code_message
|
||||||
|
|
||||||
LOG_DIR = "logs"
|
LOG_DIR = "logs"
|
||||||
|
|
||||||
if not os.path.exists(LOG_DIR):
|
if not os.path.exists(LOG_DIR):
|
||||||
@@ -154,12 +156,11 @@ class GuildLogs:
|
|||||||
async def load(
|
async def load(
|
||||||
self, progress: discord.Message, target_channels: List[discord.TextChannel] = []
|
self, progress: discord.Message, target_channels: List[discord.TextChannel] = []
|
||||||
) -> Tuple[int, int]:
|
) -> Tuple[int, int]:
|
||||||
|
global current_analysis
|
||||||
if self.log_file in current_analysis:
|
if self.log_file in current_analysis:
|
||||||
return -1, -1
|
return -1, -1
|
||||||
current_analysis += [self.log_file]
|
current_analysis += [self.log_file]
|
||||||
await progress.edit(
|
await code_message(progress, "Reading history...\n(this might take a while)")
|
||||||
content=f"```Reading history...\n(this might take a while)```"
|
|
||||||
)
|
|
||||||
# read logs
|
# read logs
|
||||||
t0 = datetime.now()
|
t0 = datetime.now()
|
||||||
if os.path.exists(self.log_file):
|
if os.path.exists(self.log_file):
|
||||||
@@ -205,15 +206,16 @@ class GuildLogs:
|
|||||||
"(some channels are new, this might take a long while)"
|
"(some channels are new, this might take a long while)"
|
||||||
)
|
)
|
||||||
dt = (datetime.now() - t0).total_seconds()
|
dt = (datetime.now() - t0).total_seconds()
|
||||||
await progress.edit(
|
await code_message(
|
||||||
content=f"```Reading history...\n{tmp_msg} messages in {total_chan + 1}/{max_chan} channels ({round(tmp_msg/dt)}m/s)\n{warning_msg}```"
|
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:
|
if done:
|
||||||
total_chan += 1
|
total_chan += 1
|
||||||
total_msg += len(self.channels[channel.id].messages)
|
total_msg += len(self.channels[channel.id].messages)
|
||||||
dt = (datetime.now() - t0).total_seconds()
|
dt = (datetime.now() - t0).total_seconds()
|
||||||
await progress.edit(
|
await code_message(
|
||||||
content=f"```Saving...\n{total_msg} messages in {total_chan} channels```"
|
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")
|
logging.info(f"log {self.guild.id} > queried in {dt} s -> {total_msg / dt} m/s")
|
||||||
# write logs
|
# write logs
|
||||||
@@ -222,8 +224,8 @@ class GuildLogs:
|
|||||||
f.write(gzip.compress(bytes(json.dumps(self.dict()), "utf-8")))
|
f.write(gzip.compress(bytes(json.dumps(self.dict()), "utf-8")))
|
||||||
dt = (datetime.now() - t0).total_seconds()
|
dt = (datetime.now() - t0).total_seconds()
|
||||||
logging.info(f"log {self.guild.id} > written in {dt} s")
|
logging.info(f"log {self.guild.id} > written in {dt} s")
|
||||||
await progress.edit(
|
await code_message(
|
||||||
content=f"```Analysing...\n{total_msg} messages in {total_chan} channels```"
|
progress, f"Analysing...\n{total_msg} messages in {total_chan} channels"
|
||||||
)
|
)
|
||||||
current_analysis.remove(self.log_file)
|
current_analysis.remove(self.log_file)
|
||||||
return total_msg, total_chan
|
return total_msg, total_chan
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ def debug(message: discord.Message, txt: str):
|
|||||||
logging.info(f"{message.guild} > #{message.channel}: {txt}")
|
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
|
# LISTS
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user