From 85d612ab6985d0cafe65f79bf4a1124625f0a9fd Mon Sep 17 00:00:00 2001 From: loicbersier Date: Tue, 2 Jun 2020 23:34:36 +0200 Subject: [PATCH] Basic role update logging Signed-off-by: loicbersier --- event/listeners/log/roleUpdate.js | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 event/listeners/log/roleUpdate.js diff --git a/event/listeners/log/roleUpdate.js b/event/listeners/log/roleUpdate.js new file mode 100644 index 00000000..34d63b06 --- /dev/null +++ b/event/listeners/log/roleUpdate.js @@ -0,0 +1,41 @@ +/* TODO + * Show more details about the update like what permissions changed, if a name change occurred ect... + */ +const { Listener } = require('discord-akairo'); +const LogStats = require('../../../models/').LogStats; + +class roleUpdateListener extends Listener { + constructor() { + super('roleUpdate', { + emitter: 'client', + event: 'roleUpdate' + }); + } + + async exec(role) { + const guild = role.guild; + const logStats = await LogStats.findOne({where: {guild: guild.id}}); + if (logStats) { + const fetchedLogs = await guild.fetchAuditLogs({ + limit: 1, + type: 'ROLE_UPDATE', + }); + + const creationLog = fetchedLogs.entries.first(); + + const channel = this.client.channels.resolve(await logStats.get('channel')); + let Embed = this.client.util.embed() + .setColor('NAVY') + .setTitle('Role updated') + .setDescription(`${role.name} got updated!`) + .setTimestamp(); + + if (!creationLog) return channel.send(Embed); + + Embed.setDescription(`${role.name} got updated by ${creationLog.executor}`); + + channel.send(Embed); + } + } +} +module.exports = roleUpdateListener;