diff --git a/source/library/stores/journalling.ts b/source/library/stores/journalling.ts index 47b7a04ef..4d830eec7 100644 --- a/source/library/stores/journalling.ts +++ b/source/library/stores/journalling.ts @@ -4,6 +4,7 @@ import type { Client } from "logos/client"; import { Collector } from "logos/collectors"; import { Logger } from "logos/logger"; import loggers from "logos/stores/journalling/loggers"; +import { AuditLogEvents, snowflakeToTimestamp } from "@discordeno/bot"; type Events = Logos.Events & Discord.Events; @@ -131,7 +132,12 @@ class JournallingStore { } async #guildMemberRemove(user: Discord.User, guildId: bigint): Promise { - await this.tryLog("guildMemberRemove", { guildId, args: [user, guildId] }); + const wasKicked = await this.#wasKicked({ user, guildId }); + if (wasKicked) { + await this.tryLog("guildMemberKick", { guildId, args: [user, guildId] }); + } else { + await this.tryLog("guildMemberRemove", { guildId, args: [user, guildId] }); + } } async #messageDelete( @@ -154,6 +160,15 @@ class JournallingStore { await this.tryLog("messageUpdate", { guildId, args: [message, oldMessage] }); } + + async #wasKicked({ user, guildId }: { user: Logos.User; guildId: bigint }): Promise { + const now = Date.now(); + + const auditLog = await this.#client.bot.helpers.getAuditLog(guildId, { actionType: AuditLogEvents.MemberKick }); + return auditLog.auditLogEntries + .filter((entry) => snowflakeToTimestamp(BigInt(entry.id)) >= now - constants.time.second * 5) + .some((entry) => entry.targetId === user.id.toString()); + } } export { JournallingStore }; diff --git a/source/types.d.ts b/source/types.d.ts index 0fddde8be..e168904d2 100644 --- a/source/types.d.ts +++ b/source/types.d.ts @@ -99,6 +99,9 @@ declare global { /** Type representing events that occur within a guild. */ type Events = { + /** Fill-in Discord event for a member having been kicked. */ + guildMemberKick: [user: Logos.User, guildId: bigint]; + } & { /** An entry request has been submitted. */ entryRequestSubmit: [user: Logos.User, entryRequest: EntryRequest];