Equicord/src/equicordplugins/voiceChannelLog/logs.ts
2024-09-20 18:03:34 -04:00

40 lines
1.1 KiB
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
export interface VoiceChannelLogEntry {
userId: string;
oldChannel: string | null;
newChannel: string | null;
timestamp: Date;
}
export const vcLogs = new Map<string, VoiceChannelLogEntry[]>();
let vcLogSubscriptions: (() => void)[] = [];
export function getVcLogs(channel?: string): VoiceChannelLogEntry[] {
if (!channel) return [];
if (!vcLogs.has(channel)) vcLogs.set(channel, []);
return vcLogs.get(channel) || [];
}
export function addLogEntry(logEntry: VoiceChannelLogEntry, channel?: string) {
if (!channel) return;
vcLogs.set(channel, [...getVcLogs(channel), logEntry]);
vcLogSubscriptions.forEach(u => u());
}
export function clearLogs(channel?: string) {
if (!channel) return;
vcLogs.set(channel, []);
vcLogSubscriptions.forEach(u => u());
}
export function vcLogSubscribe(listener: () => void) {
vcLogSubscriptions = [...vcLogSubscriptions, listener];
return () => {
vcLogSubscriptions = vcLogSubscriptions.filter(l => l !== listener);
};
}