fixed some crashes relating to dmming users outside a guild, also fixed recursive p/says

This commit is contained in:
ayeuhugyu 2023-09-09 15:32:01 -07:00
parent 9a09f7fd49
commit 4970f1a10f
2 changed files with 120 additions and 56 deletions

View file

@ -11,8 +11,10 @@ function delay(time) {
module.exports = { module.exports = {
name: "dmuser", name: "dmuser",
description: "forces bot to dm a user something (this will ghost ping them)", description: "forces bot to dm a user something (this will ghost ping them)",
execute(message, args, client) { execute(message, args) {
const user = message.mentions.users.first(); const user = message.mentions.users.first();
const guild = message.guild;
if (!user) { if (!user) {
return; return;
} }
@ -22,13 +24,51 @@ module.exports = {
console.log(typeof user); console.log(typeof user);
console.log(user.username); console.log(user.username);
//const usercache = client.users.fetch(user.id, false, true);
const msg = msgnoprefix.slice(0, 2000); const msg = msgnoprefix.slice(0, 2000);
let ableToSend = true;
if (msg !== "") { if (msg !== "") {
user.send(msg); user.send(msg).catch(() => {
message.channel.send(
`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"
);
ableToSend = false;
});
message.delete(); message.delete();
if (ableToSend) {
fs.appendFileSync( fs.appendFileSync(
"../pepperbot/src/logs/forcesay.log", "../pepperbot/src/logs/forcesay.log",
Date() + Date() +
@ -61,5 +101,6 @@ module.exports = {
"\n" "\n"
); );
} }
}
}, },
}; };

View file

@ -1,30 +1,53 @@
const fs = require('fs') const fs = require("fs");
const prefix = process.env.PREFIX const prefix = process.env.PREFIX;
function delay(time) { function delay(time) {
return new Promise(resolve => { return new Promise((resolve) => {
setTimeout(resolve, time); setTimeout(resolve, time);
}); });
} }
module.exports = { module.exports = {
name: 'say', name: "say",
description: 'forces bot to say something', description: "forces bot to say something",
execute(message, args){ execute(message, args) {
const msgnoprefix = message.content.slice(prefix.length + this.name.length) if (message.author.bot) return;
const msg = msgnoprefix.slice(0, 2000) const msgnoprefix = message.content.slice(prefix.length + this.name.length);
const msg = msgnoprefix.slice(0, 2000);
if (msg !== '') { if (msg !== "") {
message.channel.send(msg) message.channel.send(msg);
message.delete() message.delete();
fs.appendFileSync("../pepperbot/src/logs/forcesay.log", Date() + " " + message.author.username + " (" + message.author + ") forced bot to say " + msg + "\n", (err) => { fs.appendFileSync(
"../pepperbot/src/logs/forcesay.log",
Date() +
" " +
message.author.username +
" (" +
message.author +
") forced bot to say " +
msg +
"\n",
(err) => {
if (err !== null) { if (err !== null) {
console.error(err) console.error(err);
fs.appendFileSync("../pepperbot/src/logs/errors.log", err + ' from: ' + message.content + " at " + Date()) 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) );
} }
} }
} );
console.log(
Date() +
" " +
message.author.username +
" (" +
message.author +
") forced bot to say " +
msg
);
}
},
};