fixed events/* (not including webhookUpdate.ts)
diff --git a/src/events/roleUpdate.ts b/src/events/roleUpdate.ts
index fc26d6c..924ec3e 100644
--- a/src/events/roleUpdate.ts
+++ b/src/events/roleUpdate.ts
@@ -1,36 +1,36 @@
-import type { Role } from "discord.js";
+import { AuditLogEvent, Guild, GuildAuditLogsEntry, Role } from "discord.js";
import type { NucleusClient } from "../utils/client.js";
import getEmojiByName from "../utils/getEmojiByName.js";
export const event = "roleUpdate";
-export async function callback(client: NucleusClient, or: Role, nr: Role) {
+export async function callback(client: NucleusClient, oldRole: Role, newRole: Role) {
const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger;
- const auditLog = await getAuditLog(nr.guild, "ROLE_UPDATE");
- const audit = auditLog.entries.first();
- if (audit.executor.id === client.user.id) return;
+ const auditLog = (await getAuditLog(newRole.guild as Guild, AuditLogEvent.RoleUpdate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === newRole.id)[0]!;
+ if (auditLog.executor!.id === client.user!.id) return;
const changes: Record<string, ReturnType<typeof entry>> = {
- roleId: entry(nr.id, `\`${nr.id}\``),
- role: entry(nr.id, renderRole(nr)),
+ roleId: entry(newRole.id, `\`${newRole.id}\``),
+ role: entry(newRole.id, renderRole(newRole)),
edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user))
+ editedBy: entry(auditLog.executor!.id, renderUser((await newRole.guild.members.fetch(auditLog.executor!.id)).user))
};
const mentionable = ["", ""];
const hoist = ["", ""];
- mentionable[0] = or.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- mentionable[1] = nr.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- hoist[0] = or.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- hoist[1] = nr.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- if (or.name !== nr.name) changes["name"] = entry([or.name, nr.name], `${or.name} -> ${nr.name}`);
- if (or.position !== nr.position)
- changes["position"] = entry([or.position, nr.position], `${or.position} -> ${nr.position}`);
- if (or.hoist !== nr.hoist) changes["showInMemberList"] = entry([or.hoist, nr.hoist], `${hoist[0]} -> ${hoist[1]}`);
- if (or.mentionable !== nr.mentionable)
- changes["mentionable"] = entry([or.mentionable, nr.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
- if (or.hexColor !== nr.hexColor)
- changes["color"] = entry([or.hexColor, nr.hexColor], `\`${or.hexColor}\` -> \`${nr.hexColor}\``);
+ mentionable[0] = oldRole.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ mentionable[1] = newRole.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ hoist[0] = oldRole.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ hoist[1] = newRole.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ if (oldRole.name !== newRole.name) changes["name"] = entry([oldRole.name, newRole.name], `${oldRole.name} -> ${newRole.name}`);
+ if (oldRole.position !== newRole.position)
+ changes["position"] = entry([oldRole.position.toString(), newRole.position.toString()], `${oldRole.position} -> ${newRole.position}`);
+ if (oldRole.hoist !== newRole.hoist) changes["showInMemberList"] = entry([oldRole.hoist, newRole.hoist], `${hoist[0]} -> ${hoist[1]}`);
+ if (oldRole.mentionable !== newRole.mentionable)
+ changes["mentionable"] = entry([oldRole.mentionable, newRole.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
+ if (oldRole.hexColor !== newRole.hexColor)
+ changes["color"] = entry([oldRole.hexColor, newRole.hexColor], `\`${oldRole.hexColor}\` -> \`${newRole.hexColor}\``);
if (Object.keys(changes).length === 4) return;
@@ -41,11 +41,11 @@
calculateType: "guildRoleUpdate",
color: NucleusColors.yellow,
emoji: "GUILD.ROLES.EDIT",
- timestamp: audit.createdTimestamp
+ timestamp: auditLog.createdTimestamp
},
list: changes,
hidden: {
- guild: nr.guild.id
+ guild: newRole.guild.id
}
}; // TODO: show perms changed (webpage)
log(data);