From a665cffcb95f84a63f22505883f4b625e1d2c0a9 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 4 May 2023 09:33:47 -0600 Subject: [PATCH] Fancy logging to Discord go brrt --- index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7f5f74f..5b3d5ef 100644 --- a/index.js +++ b/index.js @@ -214,11 +214,23 @@ const rest = new REST({ }).setToken(config.discord.token); var logChannel; var sendLog; - +var logMsg = null; // Used to store the log message, so it can be edited instead of sending a new one +var curMsg = ""; // Used to calculate the length of the log message, so it can be edited instead of sending a new one dcClient.on('ready', async () => { - await dcClient.channels.fetch(config.discord.logId).then((channel) => { - sendLog = (message) => { - channel.send(`\`\`\`ansi\n${message}\`\`\``); + await dcClient.channels.fetch(config.discord.logId).then(async (channel) => { + await channel.send(`\`\`\`ansi\n${curMsg}\`\`\``).then((msg) => { + logMsg = msg; + }); + sendLog = async (message) => { + if(curMsg.length + message.length < 2000) { + curMsg = `${curMsg}\n${message}`; + await logMsg.edit(`\`\`\`ansi\n${curMsg}\`\`\``); + } else { + curMsg = message; + await channel.send(`\`\`\`ansi\n${message}\`\`\``).then((msg) => { + logMsg = msg; + }); + } console.log(message); };