created new logging system, also added logging of commands

This commit is contained in:
ayeuhugyu 2023-09-13 06:57:58 -07:00
parent cb16a007d3
commit d18afd63f0
4 changed files with 48 additions and 154 deletions

View file

@ -1,4 +1,4 @@
const fs = require("fs"); const log = require("../util/log.js").execute;
const prefix = process.env.PREFIX; const prefix = process.env.PREFIX;
@ -34,36 +34,11 @@ module.exports = {
message.channel.send( message.channel.send(
`${message.author}, cannot send message to ${user}, this is usually caused by them not being inside the server` `${message.author}, cannot send message to ${user}, this is usually caused by them not being inside the server`
); );
fs.appendFileSync( log(
"../pepperbot/src/logs/forcesay.log", "forcesay.log",
Date() + message,
" " + this.name,
message.author.username + `${message.author.username} (${message.author}) attempted to force bot to dm ${user} "${msg}"`
" (" +
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"
); );
ableToSend = false; ableToSend = false;
}); });
@ -71,36 +46,11 @@ module.exports = {
message.delete(); message.delete();
} }
if (ableToSend) { if (ableToSend) {
fs.appendFileSync( log(
"../pepperbot/src/logs/forcesay.log", "forcesay.log",
Date() + message,
" " + this.name,
message.author.username + `${message.author.username} (${message.author}) forced bot to dm ${user.username} (${user}) "${msg}"`
" (" +
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"
); );
} }
} }

View file

@ -1,4 +1,4 @@
const fs = require("fs"); const log = require("../util/log.js").execute;
const prefix = process.env.PREFIX; const prefix = process.env.PREFIX;
@ -21,34 +21,11 @@ module.exports = {
if (message.deletable) { if (message.deletable) {
message.delete(); message.delete();
} }
fs.appendFileSync( log(
"../pepperbot/src/logs/forcesay.log", "forcesay.log",
Date() + message,
" " + this.name,
message.author.username + `${message.author.username} (${message.author}) forced bot to say "${msg}"`
" (" +
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
); );
} }
}, },

View file

@ -1,7 +1,10 @@
const log = require("../util/log.js").execute;
module.exports = { module.exports = {
name: "test", name: "test",
description: "test command", description: "test command",
execute(message, args) { 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");
}, },
}; };

View file

@ -6,6 +6,7 @@ const {
Partials, Partials,
} = require("discord.js"); } = require("discord.js");
const log = require("./util/log.js").execute;
const fs = require("fs"); const fs = require("fs");
const client = new Client({ const client = new Client({
@ -57,48 +58,30 @@ client.on("messageDelete", async (message) => {
const args = message.content.slice(prefix.length).split(/ +/); const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
if (!client.commands.has(command)) { if (!client.commands.has(command)) {
fs.appendFileSync( log(
"../pepperbot/src/logs/deletedmessages.log", "deletedmessages.log",
"deleted message from: " + message,
message.author.username + __filename,
"(" + `deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
); );
} }
} else { } else {
fs.appendFileSync( log(
"../pepperbot/src/logs/deletedmessages.log", "deletedmessages.log",
"deleted message from: " + message,
message.author.username + __filename,
"(" + `deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
); );
} }
}); });
client.on("messageCreate", async (message) => { client.on("messageCreate", async (message) => {
if (message.channel.type === 1) { if (message.channel.type === 1) {
fs.appendFileSync( log(
"../pepperbot/src/logs/directmessages.log", "directmessages.log",
"direct message from: " + message,
message.author.username + __filename,
"(" + `direct message from ${message.author.username} (${message.author}) with: "${message.content}"`
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
); );
} }
if (!message.content.startsWith(prefix)) return; if (!message.content.startsWith(prefix)) return;
@ -116,42 +99,23 @@ client.on("messageCreate", async (message) => {
if (!client.commands.has(command)) { if (!client.commands.has(command)) {
message.reply("idiot thats not a command"); message.reply("idiot thats not a command");
fs.appendFileSync( log(
"../pepperbot/src/logs/failed.log", "failed.log",
"invalid command: " + "from: " + message.content + " at " + Date() + "\n" message,
__filename,
`attempt to use invalid command: ${command} by: ${message.author.username} (${message.author})"`
); );
} }
if (client.commands.get(command)) { 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.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); client.login(process.env.TOKEN);