From 92c9033d1ed8ef8897a0fcb2d34ee72d0eb65825 Mon Sep 17 00:00:00 2001 From: ayeuhugyu Date: Wed, 13 Sep 2023 06:59:53 -0700 Subject: [PATCH] created new logging system, also added logging of commands --- src/commands/dmuser.js | 4 ++-- src/commands/say.js | 2 +- src/util/log.js | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/util/log.js diff --git a/src/commands/dmuser.js b/src/commands/dmuser.js index 41da38a..05a1ef9 100644 --- a/src/commands/dmuser.js +++ b/src/commands/dmuser.js @@ -37,7 +37,7 @@ module.exports = { log( "forcesay.log", message, - this.name, + __filename, `${message.author.username} (${message.author}) attempted to force bot to dm ${user} "${msg}"` ); ableToSend = false; @@ -49,7 +49,7 @@ module.exports = { log( "forcesay.log", message, - this.name, + __filename, `${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 354f9da..785a054 100644 --- a/src/commands/say.js +++ b/src/commands/say.js @@ -24,7 +24,7 @@ module.exports = { log( "forcesay.log", message, - this.name, + __filename, `${message.author.username} (${message.author}) forced bot to say "${msg}"` ); } diff --git a/src/util/log.js b/src/util/log.js new file mode 100644 index 0000000..4c96098 --- /dev/null +++ b/src/util/log.js @@ -0,0 +1,23 @@ +const fs = require("fs"); + +module.exports.execute = function (file, message, from, msg) { + fs.appendFileSync( + `../pepperbot/src/logs/${file}`, + `AT: ${Date()} +SCRIPT: ${from} +FROM: ${message.content} +ADDITIONAL INFORMATION: ${msg} +\n` + ); + console.log( + `AT: ${Date()} +SCRIPT: ${from} +FROM: ${message.content} +ADDITIONAL INFORMATION: ${msg} +` + ); +}; + +// TEMPLATE: +// const log = require('../util/log.js').execute() +// log('failed.log', message, __filename, 'additional content')