Files
Vencord-Plugins/watchCord/native.ts
T
X4Lo bd8f826bb6 watchCord: fix tracking bugs, add Vencord Toolbox actions
- Seed voice channels and statuses on start and when adding a user so
  the first leave/move/status change is detected
- Match server-specific status entries by guild membership
- Webhooks never ping (allowed_mentions) and are capped at 2000 chars
- Throttle repeated typing events, reuse a single AudioContext
- Dedupe associated voice logs, stable ids for legacy entries,
  cache parsed watch list, escape newlines in log file
- Replace fragile toolbar patch with toolbox actions and a modal
- Migrate to new Heading/Paragraph/Button and Modal components
2026-11-11 18:56:00 +00:00

99 lines
3.0 KiB
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { app, IpcMainInvokeEvent, shell } from "electron";
import { appendFile, writeFile } from "fs/promises";
import { join } from "path";
const LOG_FILE = "watchcord-logs.txt";
const STATUS_CHANGE_FILE = "watchcord-full-status-changes.json";
function getLogPath(): string {
return join(app.getPath("userData"), LOG_FILE);
}
function getStatusChangePath(): string {
return join(app.getPath("userData"), STATUS_CHANGE_FILE);
}
export async function appendLog(
_: IpcMainInvokeEvent,
logLine: string
): Promise<void> {
const logPath = getLogPath();
await appendFile(logPath, logLine + "\n", "utf-8");
}
export async function clearLogs(_: IpcMainInvokeEvent): Promise<void> {
const logPath = getLogPath();
await writeFile(logPath, "", "utf-8");
}
export async function openLogFile(_: IpcMainInvokeEvent): Promise<void> {
const logPath = getLogPath();
// Create file if it doesn't exist
try {
await appendFile(logPath, "", { flag: "a" });
} catch {
// ignore
}
shell.openPath(logPath);
}
export async function sendWebhook(
_: IpcMainInvokeEvent,
webhookUrl: string,
content: string
): Promise<{ ok: boolean; error?: string }> {
try {
// Webhook messages are capped at 2000 characters
const safeContent = content.length > 2000 ? content.slice(0, 1997) + "..." : content;
const res = await fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
content: safeContent,
// Never ping anyone: logged messages may contain @everyone/@here or
// user mentions, and our own <@id> references should only render.
allowed_mentions: { parse: [] },
}),
});
if (!res.ok) return { ok: false, error: `HTTP ${res.status}` };
return { ok: true };
} catch (e) {
return { ok: false, error: String(e) };
}
}
export async function logFullStatusChange(
_: IpcMainInvokeEvent,
statusChangeObject: any
): Promise<void> {
const statusChangePath = getStatusChangePath();
const timestamp = new Date().toISOString();
const logEntry = {
timestamp,
data: statusChangeObject
};
await appendFile(statusChangePath, JSON.stringify(logEntry, null, 2) + "\n---\n", "utf-8");
}
export async function openStatusChangeFile(_: IpcMainInvokeEvent): Promise<void> {
const statusChangePath = getStatusChangePath();
// Create file if it doesn't exist
try {
await appendFile(statusChangePath, "", { flag: "a" });
} catch {
// ignore
}
shell.openPath(statusChangePath);
}
export async function clearStatusChanges(_: IpcMainInvokeEvent): Promise<void> {
const statusChangePath = getStatusChangePath();
await writeFile(statusChangePath, "", "utf-8");
}