fixing event logs
diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts
index 81b2337..412ac96 100644
--- a/src/events/guildMemberUpdate.ts
+++ b/src/events/guildMemberUpdate.ts
@@ -1,15 +1,60 @@
import { AuditLogEvent, GuildAuditLogsEntry, GuildMember } from "discord.js";
import type { NucleusClient } from "../utils/client.js";
+import type { LoggerOptions } from "../utils/log.js";
export const event = "guildMemberUpdate";
export async function callback(client: NucleusClient, before: GuildMember, after: GuildMember) {
- const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
- if (!await isLogging(after.guild.id, "memberUpdate")) return;
- const auditLog = (await getAuditLog(after.guild, AuditLogEvent.EmojiCreate))
+ const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
+
+ const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberUpdate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id)[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
+ if(!before.roles.cache.equals(after.roles.cache)) {
+ let rolesAdded = after.roles.cache.filter(role => !before.roles.cache.has(role.id));
+ let rolesRemoved = before.roles.cache.filter(role => !after.roles.cache.has(role.id));
+ let displayName = "Roles Removed";
+ let color = NucleusColors.red;
+ let emoji = "GUILD.ROLES.DELETE";
+ if(rolesAdded.size > 0 && rolesRemoved.size > 0) {displayName = "Roles Changed"; color = NucleusColors.yellow; emoji = "GUILD.ROLES.EDIT";}
+ else if(rolesAdded.size > 0) {displayName = "Roles Added"; color = NucleusColors.green; emoji = "GUILD.ROLES.CREATE";}
+ let removedEntry = rolesRemoved.map(role => role.id);
+ let addedEntry = rolesAdded.map(role => role.id);
+
+ let list = {
+ memberId: entry(after.id, `\`${after.id}\``),
+ name: entry(after.user.id, renderUser(after.user)),
+ changed: entry(Date.now(), renderDelta(Date.now())),
+ changedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
+ };
+
+ let data: LoggerOptions = {
+ meta: {
+ type: "memberUpdate",
+ displayName: displayName,
+ calculateType: "guildMemberUpdate",
+ color: color,
+ emoji: emoji,
+ timestamp: Date.now()
+ },
+ list: {
+
+ },
+ hidden: {
+ guild: after.guild.id
+ }
+ };
+
+ if(rolesAdded.size > 0) {
+ list = Object.assign(list, {rolesAdded: entry(addedEntry, addedEntry.map(id => `<@&${id}>`).join(", "))});
+ }
+ if(rolesRemoved.size > 0) {
+ list = Object.assign(list, {rolesRemoved: entry(removedEntry, removedEntry.map(id => `<@&${id}>`).join(", "))});
+ }
+ data = Object.assign(data, {list: list});
+ log(data);
+ }
if (before.nickname !== after.nickname) {
await client.database.history.create(
"nickname",
@@ -42,7 +87,8 @@
}
};
log(data);
- } else if (
+ }
+ if (
(before.communicationDisabledUntilTimestamp ?? 0) < Date.now() &&
(after.communicationDisabledUntil ?? 0) > Date.now()
) {
@@ -86,7 +132,8 @@
user: after.id,
expires: after.communicationDisabledUntilTimestamp
});
- } else if (
+ }
+ if (
after.communicationDisabledUntil === null &&
before.communicationDisabledUntilTimestamp !== null &&
Date.now() >= auditLog.createdTimestamp