1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-30 05:01:00 -04:00
Daggerbot-TS/src/events/roleUpdate.ts

31 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-11-22 01:38:40 -05:00
import Discord, { AuditLogEvent } from 'discord.js';
2023-01-27 21:33:55 -05:00
import TClient from '../client';
2022-11-22 01:38:40 -05:00
export default {
async run(client:TClient, oldRole:Discord.Role, newRole:Discord.Role){
2022-11-22 01:38:40 -05:00
const fetchRoleUpdoot = await client.guilds.cache.get(oldRole.guild.id).fetchAuditLogs({
limit: 1,
type: AuditLogEvent.RoleUpdate
})
2022-11-26 03:52:43 -05:00
if (oldRole.guild?.id != client.config.mainServer.id) return;
2022-11-22 01:38:40 -05:00
const roleLog = fetchRoleUpdoot.entries.first();
if (!roleLog) return
const {executor, target} = roleLog;
if (target) {
2022-11-22 08:00:47 -05:00
const embed = new client.embed().setColor(newRole.hexColor).setThumbnail(newRole?.iconURL()).setTimestamp().setTitle(`Role modified: ${newRole.name}`).setDescription(`🔹 **Role**\n${target}\n\`${target.id}\``).addFields(
{name: `${executor.bot ? '🔹 Bot' : '🔹 Admin'}`, value: `<@${executor.id}>\n\`${executor.id}\``}
2022-11-22 01:38:40 -05:00
);
(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [embed]})
2022-11-22 08:00:47 -05:00
// Moved addFields to these below cuz yes for each role changes, it seems inefficent to me but it will do. :)
// Permissions field seems to trigger when role is hoisted/unhoisted atleast to me.
if (oldRole.hexColor !== newRole.hexColor) {
embed.addFields({name: '🔹 Role changes', value: `**Old color:** ${oldRole.hexColor}\n**New color:** ${newRole.hexColor}`})
} else if (oldRole.name !== newRole.name) {
embed.addFields({name: '🔹 Role changes', value: `**Old name:** ${oldRole.name}\n**New name:** ${newRole.name}`})
2022-11-26 03:52:43 -05:00
} else if (!oldRole.permissions.equals(newRole.permissions)) {
embed.addFields({name: '🔹 Role changes', value: `**Old permission(s):** ${newRole.permissions.missing(oldRole.permissions).join(', ')}\n**New permission(s):** ${oldRole.permissions.missing(newRole.permissions).join(', ')}`})
2022-11-22 08:00:47 -05:00
}
2022-11-22 01:38:40 -05:00
} else {
console.log(`${target.id} was modified from ${client.guilds.cache.get(oldRole.guild.name)} but no audit log could be fetched.`)
}
}
}