diff --git a/event/listeners/log/channelCreate.js b/event/listeners/log/channelCreate.js index 0140ca26..2861c571 100644 --- a/event/listeners/log/channelCreate.js +++ b/event/listeners/log/channelCreate.js @@ -12,6 +12,13 @@ class channelCreateListener extends Listener { async exec(GuildChannel) { const logStats = await LogStats.findOne({where: {guild: GuildChannel.guild.id}}); if (logStats) { + const fetchedLogs = await GuildChannel.guild.fetchAuditLogs({ + limit: 1, + type: 'CHANNEL_CREATE', + }); + + const creationLog = fetchedLogs.entries.first(); + const channel = this.client.channels.resolve(await logStats.get('channel')); let Embed = this.client.util.embed() .setColor('NAVY') @@ -20,6 +27,10 @@ class channelCreateListener extends Listener { .setFooter(`Channel ID: ${GuildChannel.id}`) .setTimestamp(); + if (!creationLog) return channel.send(Embed); + + Embed.setDescription(`${GuildChannel.type} channel ${GuildChannel} got created by ${creationLog.executor}`); + channel.send(Embed); } } diff --git a/event/listeners/log/channelDelete.js b/event/listeners/log/channelDelete.js index e05c1420..8657306d 100644 --- a/event/listeners/log/channelDelete.js +++ b/event/listeners/log/channelDelete.js @@ -12,13 +12,24 @@ class channelDeleteListener extends Listener { async exec(GuildChannel) { const logStats = await LogStats.findOne({where: {guild: GuildChannel.guild.id}}); if (logStats) { + const fetchedLogs = await GuildChannel.guild.fetchAuditLogs({ + limit: 1, + type: 'CHANNEL_DELETE', + }); + + const deletionLog = fetchedLogs.entries.first(); + const channel = this.client.channels.resolve(await logStats.get('channel')); let Embed = this.client.util.embed() .setColor('NAVY') .setTitle('Channel created!') - .setDescription(`${GuildChannel.type} channel ${GuildChannel.name} got deleted!`) + .setDescription(`${GuildChannel.type} channel ${GuildChannel} got deleted!`) .setTimestamp(); + if (!deletionLog) return channel.send(Embed); + + Embed.setDescription(`${GuildChannel.type} channel ${GuildChannel} got deleted by ${deletionLog.executor}`); + channel.send(Embed); } } diff --git a/event/listeners/log/channelUpdate.js b/event/listeners/log/channelUpdate.js index 05e28449..c565d59d 100644 --- a/event/listeners/log/channelUpdate.js +++ b/event/listeners/log/channelUpdate.js @@ -13,10 +13,17 @@ class channelUpdateListener extends Listener { const logStats = await LogStats.findOne({where: {guild: newChannel.guild.id}}); if (logStats) { + const fetchedLogs = await newChannel.guild.fetchAuditLogs({ + limit: 1, + type: 'CHANNEL_CREATE', + }); + + const updateLog = fetchedLogs.entries.first(); + const channel = this.client.channels.resolve(await logStats.get('channel')); let Embed = this.client.util.embed() .setColor('NAVY') - .setTitle(`${newChannel.type} channel updated!`) + .setDescription(`**${newChannel} channel updated!**`) .setTimestamp(); if (oldChannel.name !== newChannel.name) { @@ -39,6 +46,10 @@ class channelUpdateListener extends Listener { .addField('New channel slowmode', `${newChannel.rateLimitPerUser} seconds`, true); } + if (!updateLog) return channel.send(Embed); + + Embed.setDescription(`**${newChannel} channel updated by ${updateLog.executor}**`); + channel.send(Embed); } } diff --git a/event/listeners/log/guildBanAdd.js b/event/listeners/log/guildBanAdd.js new file mode 100644 index 00000000..68ad57c1 --- /dev/null +++ b/event/listeners/log/guildBanAdd.js @@ -0,0 +1,37 @@ +const { Listener } = require('discord-akairo'); +const LogStats = require('../../../models/').LogStats; + +class guildBanAddListener extends Listener { + constructor() { + super('guildBanAdd', { + emitter: 'client', + event: 'guildBanAdd' + }); + } + + async exec(guild, user) { + const logStats = await LogStats.findOne({where: {guild: guild.id}}); + if (logStats) { + const fetchedLogs = await guild.fetchAuditLogs({ + limit: 1, + type: 'MEMBER_BAN_ADD', + }); + + const banLog = fetchedLogs.entries.first(); + + const channel = this.client.channels.resolve(await logStats.get('channel')); + let Embed = this.client.util.embed() + .setColor('NAVY') + .setTitle('A user got banned!') + .setDescription(`${user.tag} got banned!`) + .setTimestamp(); + + if (!banLog) return channel.send(Embed); + + Embed.setDescription(`${user.tag} got banned by ${banLog.executor}`); + + channel.send(Embed); + } + } +} +module.exports = guildBanAddListener; \ No newline at end of file diff --git a/event/listeners/log/guildBanRemove.js b/event/listeners/log/guildBanRemove.js new file mode 100644 index 00000000..5506b5ba --- /dev/null +++ b/event/listeners/log/guildBanRemove.js @@ -0,0 +1,37 @@ +const { Listener } = require('discord-akairo'); +const LogStats = require('../../../models/').LogStats; + +class guildBanRemoveListener extends Listener { + constructor() { + super('guildBanRemove', { + emitter: 'client', + event: 'guildBanRemove' + }); + } + + async exec(guild, user) { + const logStats = await LogStats.findOne({where: {guild: guild.id}}); + if (logStats) { + const fetchedLogs = await guild.fetchAuditLogs({ + limit: 1, + type: 'MEMBER_BAN_REMOVE', + }); + + const unbanLog = fetchedLogs.entries.first(); + + const channel = this.client.channels.resolve(await logStats.get('channel')); + let Embed = this.client.util.embed() + .setColor('NAVY') + .setTitle('A user got unbanned!') + .setDescription(`${user.tag} got unbanned!`) + .setTimestamp(); + + if (!unbanLog) return channel.send(Embed); + + Embed.setDescription(`${user.tag} got unbanned by ${unbanLog.executor}`); + + channel.send(Embed); + } + } +} +module.exports = guildBanRemoveListener; \ No newline at end of file diff --git a/event/listeners/log/messageDelete.js b/event/listeners/log/messageDelete.js index 95e8b580..efd74b33 100644 --- a/event/listeners/log/messageDelete.js +++ b/event/listeners/log/messageDelete.js @@ -12,15 +12,27 @@ class messageDeleteListener extends Listener { async exec(message) { const logStats = await LogStats.findOne({where: {guild: message.guild.id}}); if (logStats) { + const fetchedLogs = await message.guild.fetchAuditLogs({ + limit: 1, + type: 'MESSAGE_DELETE', + }); + + const deletionLog = fetchedLogs.entries.first(); + const channel = this.client.channels.resolve(await logStats.get('channel')); let Embed = this.client.util.embed() .setColor('NAVY') .setAuthor(`${message.author.username}#${message.author.discriminator}`) - .setDescription(`**${message.author} deleted their message in ${message.channel}**`) + .setDescription(`**${message.author} message got deleted in ${message.channel}**`) .addField('Message deleted', message) .setFooter(`Author ID: ${message.author.id}`) .setTimestamp(); + if (!deletionLog) return channel.send(Embed); + else if (deletionLog.target === message.author) { + Embed.setDescription(`**${message.author} message was deleted by ${deletionLog.executor} in ${message.channel}**`); + } + channel.send(Embed); } }