Adding Message deletion logging and join logging

This commit is contained in:
hax4dayz 2020-04-10 20:16:35 +02:00
parent 7d83f3cc6c
commit 463f16b184
2 changed files with 93 additions and 49 deletions

141
Index.js
View File

@ -4,23 +4,10 @@ const client = new Discord.Client();
client.commands = new Discord.Collection();
const { MessageEmbed } = require('discord.js');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
global.version = '2.0.0'
const { prefix,
Token,
SetStatusCommand,
} = require('./config.json');
const { BotLog,
MessageLog,
RequirePermissons,
StaffRoleID,
} = require('./info.json');
const { NoPermReply,
BootSuccessful
} = require('./strings.json');
const {prefix, Token, SetStatusCommand} = require ('./config.json')
const {BotLog, MessageLog, RequirePermissions, ModLog} = require('./info.json')
const {BootSuccessful} = require('./strings.json')
global.version = '1.0.0'
//Bootup check
@ -126,35 +113,91 @@ client.on('message', message => {
}
});
/*client.on('message', message => {
if (message.content === prefix + 'updates') {
//Check for updates
const https = require('https');
const file = fs.createWriteStream("version.txt");
const request = https.get("https://hax4dazy.github.io/Komet-JS/version/latestversion.txt", function(response) {
response.pipe(file);
const changedfile = fs.createWriteStream("changelog.txt");
const changedrequest = https.get("https://hax4dazy.github.io/Komet-JS/version/changelog.txt", function(changedresponse) {
changedresponse.pipe(changedfile);
fs.readFile('./changelog.txt', function(err, data){
const changelog = data.toString()
fs.readFile('./version.txt', function(err, data){
const latestversion = data.toString().replace(/[\r\n]+/g, '');
if(version != latestversion){
const UpdateAvailableEmbed = new Discord.MessageEmbed()
.setTitle('Update Available')
.setColor('ffa500')
.setDescription(`An update is available.\nLatest version: ${latestversion}\nYour version: ${version}`)
.addField('Changelog',changelog,false)
.setTimestamp()
.setFooter('Komet-JS | Version '+version)
message.channel.send(UpdateAvailableEmbed);
}
try {
fs.unlinkSync(`./version.txt`)
fs.unlinkSync(`./changelog.txt`)
} catch(err) {
console.error(err)
}
})})})})
}}); */
//Member join
client.on('guildMemberAdd', member => {
var today = new Date();
var date = today.getMonth()+1+'-'+(today.getDate())+'-'+today.getFullYear();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
global.dateTime = date+' '+time;
const channel = member.guild.channels.cache.find(ch => ch.id === `${ModLog}`);
const guild = member.guild
if (!channel) return;
const MemberJoinEmbed = new Discord.MessageEmbed()
.setColor('#00FF00')
.setTitle('Member Join')
.addFields(
{ name: 'Username', value: member.user.tag, inline: false },
{ name: 'Member ID', value: member.id, inline: false },
{ name: 'Account creation date', value: member.user.createdAt, inline: false },
{ name: 'Server join date', value: dateTime, inline: false },
{ name: 'Server member count', value: `${guild.memberCount}`, inline: false },
)
.setTimestamp()
channel.send(MemberJoinEmbed)
}
);
//Log deleted messages
client.on('messageDelete', async message => {
const fetchedLogs = await message.guild.fetchAuditLogs({
limit: 1,
type: 'MESSAGE_DELETE',
});
// Since we only have 1 audit log entry in this collection, we can simply grab the first one
const deletionLog = fetchedLogs.entries.first();
// Let's perform a sanity check here and make sure we got *something*
if (!deletionLog) { console.log(`A message by ${message.author.tag} was deleted, but no relevant audit logs were found.`);
const DeletionEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Message Deleted')
.addFields(
{ name: 'Message sent by', value: message.author.tag, inline: false },
{ name: 'Deleted by', value: 'Unknown - Audit log not found.', inline: false },
{ name: 'Sent in', value: message.channel.name, inline: false },
{ name: 'Message', value: message.content, inline: false },
)
.setTimestamp()
const channel = client.channels.cache.get(`${ModLog}`);
channel.send(DeletionEmbed)}
// We now grab the user object of the person who deleted the message
// Let us also grab the target of this action to double check things
const { executor, target } = deletionLog;
// And now we can update our output with a bit more information
// We will also run a check to make sure the log we got was for the same author's message
if (target.id === message.author.id) {
console.log(`A message by ${message.author.tag} was deleted by ${executor.tag}.`)
const DeletionEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Message Deleted')
.addFields(
{ name: 'Message sent by', value: message.author.tag, inline: false },
{ name: 'Deleted by', value: executor.tag, inline: false },
{ name: 'Sent in', value: message.channel.name, inline: false },
{ name: 'Message', value: message.content, inline: false },
)
.setTimestamp()
const channel = client.channels.cache.get(`${ModLog}`);
channel.send(DeletionEmbed)
return;
} else {
if (target.id === message.author.id) return;
console.log(`A message by ${message.author.tag} was deleted, but we don't know by who.`)
const DeletionEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Message Deleted')
.addFields(
{ name: 'Message sent by', value: message.author.tag, inline: false },
{ name: 'Deleted by', value: 'Unknown - Unable to find who deleted message. - May occur when the message author erases their own message', inline: false },
{ name: 'Sent in', value: message.channel.name, inline: false },
{ name: 'Message', value: message.content, inline: false },
)
.setTimestamp()
const channel = client.channels.cache.get(`${ModLog}`);
channel.send(DeletionEmbed)
return;
}
});

View File

@ -1,4 +1,5 @@
{
"BotLog": "697531276017795132",
"MessageLog": "697536398164754492",
"ModLog": "697536398164754492"
}