import { friendlyErrorText } from "../../core/error-messages.js";
export async function startDiscordBridgeOrDisable(config, bridge) {
    if (!config.discordEnabled || !bridge) {
        return undefined;
    }
    try {
        await bridge.start();
        return bridge;
    }
    catch (error) {
        await bridge.stop().catch(() => undefined);
        config.discordEnabled = false;
        const warning = `Discord disabled: failed to start Discord adapter (${friendlyErrorText(error)}).`;
        config.adapterWarnings = [...(config.adapterWarnings ?? []), warning];
        return undefined;
    }
}
