From d18afd63f0780c7608ff38134348d249866c2523 Mon Sep 17 00:00:00 2001 From: ayeuhugyu Date: Wed, 13 Sep 2023 06:57:58 -0700 Subject: [PATCH] created new logging system, also added logging of commands --- src/commands/dmuser.js | 72 ++++++--------------------------- src/commands/say.js | 35 +++------------- src/commands/test.js | 5 ++- src/index.js | 90 +++++++++++++----------------------------- 4 files changed, 48 insertions(+), 154 deletions(-) diff --git a/src/commands/dmuser.js b/src/commands/dmuser.js index e705e96..41da38a 100644 --- a/src/commands/dmuser.js +++ b/src/commands/dmuser.js @@ -1,4 +1,4 @@ -const fs = require("fs"); +const log = require("../util/log.js").execute; const prefix = process.env.PREFIX; @@ -34,36 +34,11 @@ module.exports = { message.channel.send( `${message.author}, cannot send message to ${user}, this is usually caused by them not being inside the server` ); - fs.appendFileSync( - "../pepperbot/src/logs/forcesay.log", - Date() + - " " + - message.author.username + - " (" + - message.author + - ") attempted to force bot to dm " + - user.username + - msg + - "\n", - (err) => { - if (err !== null) { - console.error(err); - fs.appendFileSync( - "../pepperbot/src/logs/errors.log", - err + " from: " + message.content + " at " + Date() - ); - } - } - ); - console.log( - Date() + - message.author.username + - " (" + - message.author + - ") attempted to force bot to dm " + - user.username + - msg + - "\n" + log( + "forcesay.log", + message, + this.name, + `${message.author.username} (${message.author}) attempted to force bot to dm ${user} "${msg}"` ); ableToSend = false; }); @@ -71,36 +46,11 @@ module.exports = { message.delete(); } if (ableToSend) { - fs.appendFileSync( - "../pepperbot/src/logs/forcesay.log", - Date() + - " " + - message.author.username + - " (" + - message.author + - ") forced bot to dm " + - user.username + - msg + - "\n", - (err) => { - if (err !== null) { - console.error(err); - fs.appendFileSync( - "../pepperbot/src/logs/errors.log", - err + " from: " + message.content + " at " + Date() - ); - } - } - ); - console.log( - Date() + - message.author.username + - " (" + - message.author + - ") forced bot to dm " + - user.username + - msg + - "\n" + log( + "forcesay.log", + message, + this.name, + `${message.author.username} (${message.author}) forced bot to dm ${user.username} (${user}) "${msg}"` ); } } diff --git a/src/commands/say.js b/src/commands/say.js index 9c4e7da..354f9da 100644 --- a/src/commands/say.js +++ b/src/commands/say.js @@ -1,4 +1,4 @@ -const fs = require("fs"); +const log = require("../util/log.js").execute; const prefix = process.env.PREFIX; @@ -21,34 +21,11 @@ module.exports = { if (message.deletable) { message.delete(); } - fs.appendFileSync( - "../pepperbot/src/logs/forcesay.log", - Date() + - " " + - message.author.username + - " (" + - message.author + - ") forced bot to say " + - msg + - "\n", - (err) => { - if (err !== null) { - console.error(err); - fs.appendFileSync( - "../pepperbot/src/logs/errors.log", - err + " from: " + message.content + " at " + Date() - ); - } - } - ); - console.log( - Date() + - " " + - message.author.username + - " (" + - message.author + - ") forced bot to say " + - msg + log( + "forcesay.log", + message, + this.name, + `${message.author.username} (${message.author}) forced bot to say "${msg}"` ); } }, diff --git a/src/commands/test.js b/src/commands/test.js index cd1f2ce..1b89f18 100644 --- a/src/commands/test.js +++ b/src/commands/test.js @@ -1,7 +1,10 @@ +const log = require("../util/log.js").execute; + module.exports = { name: "test", description: "test command", execute(message, args) { - message.reply("MOTHAFUCKA SHUT UPPPPPP"); + log("failed.log", message, __filename, "test command"); + message.reply("log test completed, don't contact me again"); }, }; diff --git a/src/index.js b/src/index.js index e76482e..2ddfc9f 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const { Partials, } = require("discord.js"); +const log = require("./util/log.js").execute; const fs = require("fs"); const client = new Client({ @@ -57,48 +58,30 @@ client.on("messageDelete", async (message) => { const args = message.content.slice(prefix.length).split(/ +/); const command = args.shift().toLowerCase(); if (!client.commands.has(command)) { - fs.appendFileSync( - "../pepperbot/src/logs/deletedmessages.log", - "deleted message from: " + - message.author.username + - "(" + - message.author + - ") at " + - Date() + - ' with: "' + - message.content + - '"\n' + log( + "deletedmessages.log", + message, + __filename, + `deleted message from ${message.author.username} (${message.author}) with: "${message.content}"` ); } } else { - fs.appendFileSync( - "../pepperbot/src/logs/deletedmessages.log", - "deleted message from: " + - message.author.username + - "(" + - message.author + - ") at " + - Date() + - ' with: "' + - message.content + - '"\n' + log( + "deletedmessages.log", + message, + __filename, + `deleted message from ${message.author.username} (${message.author}) with: "${message.content}"` ); } }); client.on("messageCreate", async (message) => { if (message.channel.type === 1) { - fs.appendFileSync( - "../pepperbot/src/logs/directmessages.log", - "direct message from: " + - message.author.username + - "(" + - message.author + - ") at " + - Date() + - ' with: "' + - message.content + - '"\n' + log( + "directmessages.log", + message, + __filename, + `direct message from ${message.author.username} (${message.author}) with: "${message.content}"` ); } if (!message.content.startsWith(prefix)) return; @@ -116,42 +99,23 @@ client.on("messageCreate", async (message) => { if (!client.commands.has(command)) { message.reply("idiot thats not a command"); - fs.appendFileSync( - "../pepperbot/src/logs/failed.log", - "invalid command: " + "from: " + message.content + " at " + Date() + "\n" + log( + "failed.log", + message, + __filename, + `attempt to use invalid command: ${command} by: ${message.author.username} (${message.author})"` ); } if (client.commands.get(command)) { + log( + "commands.log", + message, + __filename, + `use of command: ${command} by: ${message.author.username} (${message.author})"` + ); client.commands.get(command).execute(message, args, client); } }); -client.on("interactionCreate", (interaction) => { - if (!interaction.isChatInputCommand()) return; - - if (interaction.commandName === "test") { - interaction.reply( - "mothafucka you contacted my ass from a slash command end urself" - ); - } - - if (interaction.commandName === "say") { - try { - const msg = interaction.options.get("message"); - interaction.reply(msg.value); - } catch (error) { - console.log(error); - fs.appendFile( - "../pepperbot/src/logs/errors.log", - error + "from: " + interaction.msg + " at " + Date() - ); - } - } - - if (interaction.commandName === "commands") { - client.commands.get("commands").execute(interaction, undefined); - } -}); - client.login(process.env.TOKEN);