diff --git a/resources/eventsLogger/guildUpdate.js b/resources/eventsLogger/guildUpdate.js index 6c84440..99b82ec 100644 --- a/resources/eventsLogger/guildUpdate.js +++ b/resources/eventsLogger/guildUpdate.js @@ -1,6 +1,10 @@ 'use strict'; const { Guild } = require("discord.js"); +const { Interval } = require("luxon"); +const { intervalToDuration } = require("../../cmds/moderation/src/duration"); +const { defaultEventLogEmbed, trySend } = require("../functions"); +const getColor = require("../getColor"); /** * @param {Guild} oldGuild @@ -8,6 +12,30 @@ const { Guild } = require("discord.js"); */ module.exports = async (oldGuild, newGuild) => { if (!newGuild.DB) await newGuild.dbLoad(); - let audit = (await newGuild.fetchAuditLogs({ "limit": 1, "type": "GUILD_UPDATE" })).entries.first(); - console.log(audit); + if (newGuild.DB.eventChannels.guild) { + const logChannel = newGuild.channels.cache.get(newGuild.DB.eventChannels.guild); + if (!logChannel) return; + let audit = {}; + if (newGuild.me.hasPermission("VIEW_AUDIT_LOG")) { + audit = (await newGuild.fetchAuditLogs({ "limit": 1, "type": "GUILD_UPDATE" })).entries.first(); + } else audit.reason = "Unknown reason"; + const emb = defaultEventLogEmbed(newGuild).setColor(getColor("cyan")); + if (oldGuild.afkChannelID !== newGuild.afkChannelID) { + emb.addField("Inactive Channel", "Changed from " + (oldGuild.afkChannelID ? "<#" + oldGuild.afkChannelID + ">" : "`[NONE]`") + + " to " + (newGuild.afkChannelID ? "<#" + newGuild.afkChannelID + ">" : "`[NONE]`")); + }; + if (oldGuild.afkTimeout !== newGuild.afkTimeout) { + const newAfkTDuration = intervalToDuration(Interval.after(new Date(), + newGuild.afkTimeout * 1000)).strings.join(" "); + const oldAfkTDuration = intervalToDuration(Interval.after(new Date(), + oldGuild.afkTimeout * 1000)).strings.join(" "); + emb.addField("Inactive Timeout", "Changed from `" + oldAfkTDuration + "` to `" + newAfkTDuration + "`"); + }; + + emb.setTitle(`Guild Settings Updated ${audit.executor ? "by `" + audit.executor.tag + "`" : ""}`) + .setDescription(audit.reason || "No reason provided"); + if (audit.executor) + emb.setAuthor(emb.author.name, audit.executor.displayAvatarURL({ size: 128, format: "png", dynamic: true })); + return trySend(newGuild.client, logChannel, emb); + } } \ No newline at end of file