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;
@ -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}"`
);
}
}

View file

@ -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}"`
);
}
},

View file

@ -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");
},
};

View file

@ -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);