Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 1x 1x 16x 16x 15x 15x 15x 15x 16x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 7x 7x 7x 7x 7x 12x 12x 6x 6x 6x 13x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 5x 6x 6x 6x 6x 6x 6x 5x 4x 6x 6x 6x 6x 6x 6x 6x 1x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 24x 24x 24x 24x 24x 24x 24x 11x 11x 14x 24x 7x 7x 9x 24x 24x 1x 1x 1x 1x | import { escapeMarkdown } from "discord.js"
import type {
DiscordGuildRuntimeConfig,
DiscordGuildRuntimeConfigDisabledReason,
DiscordGuildRuntimeConfigResult,
} from "@/services/guildRuntimeConfig"
export const CLEO_DASHBOARD_BASE_URL = "https://cleoai.cloud"
export type CleoGuildStatusView = {
content: string
dashboardUrl: string
}
type GuildStatusViewInput = {
discordGuildId: string
guildName: string
result: DiscordGuildRuntimeConfigResult
dashboardBaseUrl?: string
}
export function buildCleoGuildDashboardUrl(
discordGuildId: string,
dashboardBaseUrl = CLEO_DASHBOARD_BASE_URL
): string {
const dashboardUrl = new URL(dashboardBaseUrl)
if (dashboardUrl.protocol !== "https:") {
throw new Error("Cleo dashboard URL must use HTTPS.")
}
dashboardUrl.pathname = `/dashboard/${encodeURIComponent(discordGuildId)}`
dashboardUrl.search = ""
dashboardUrl.hash = ""
return dashboardUrl.toString()
}
export function buildCleoGuildStatusView({
discordGuildId,
guildName,
result,
dashboardBaseUrl,
}: GuildStatusViewInput): CleoGuildStatusView {
const dashboardUrl = buildCleoGuildDashboardUrl(
discordGuildId,
dashboardBaseUrl
)
const heading = `## Cleo status · ${escapeMarkdown(guildName)}`
if (result.status === "disabled") {
return {
content: formatDisabledStatus(heading, result.reason),
dashboardUrl,
}
}
return {
content: formatReadyStatus(heading, result.config),
dashboardUrl,
}
}
function formatReadyStatus(
heading: string,
config: DiscordGuildRuntimeConfig
): string {
return [
heading,
"Configuration is connected and loaded from Cleo.",
"",
formatModuleLine("Moderation", config.moderationEnabled, true),
formatModuleLine(
"Welcome",
config.welcomeEnabled,
Boolean(config.welcomeChannelId),
config.welcomeChannelId ? `<#${config.welcomeChannelId}>` : undefined
),
formatModuleLine(
"Logging",
config.loggingEnabled,
Boolean(config.logChannelId || config.modLogChannelId),
config.logLevel && config.logLevel !== "none"
? `${capitalize(config.logLevel)} detail`
: undefined
),
formatModuleLine(
"Support",
config.supportEnabled,
Boolean(
config.supportTargetId &&
config.supportTargetType &&
config.supportStaffRoleIds?.length
),
config.supportTargetId ? `<#${config.supportTargetId}>` : undefined
),
"",
"Use the dashboard to change settings or finish any incomplete setup.",
].join("\n")
}
function formatDisabledStatus(
heading: string,
reason: DiscordGuildRuntimeConfigDisabledReason
): string {
switch (reason) {
case "missingConfig":
return [
heading,
"⚠️ **Setup is incomplete**",
"",
"Cleo is installed, but this server does not have an active configuration yet.",
"Use the dashboard to finish setup before enabling config-driven features.",
].join("\n")
case "unknownGuild":
return [
heading,
"⚠️ **Server is not connected**",
"",
"Cleo could not find this server in the control plane.",
"Use the dashboard to connect the server and create its configuration.",
].join("\n")
case "botLeft":
return [
heading,
"⚠️ **Installation needs attention**",
"",
"Cleo's saved state says the bot is no longer installed in this server.",
"Open the dashboard to repair or reinstall the connection.",
].join("\n")
case "convexUnavailable":
return [
heading,
"⚠️ **Configuration service is temporarily unavailable**",
"",
"Cleo could not verify this server's settings right now. Config-driven features remain safely disabled unless a valid cached configuration is available.",
"Try again shortly or use the dashboard to check the service state.",
].join("\n")
case "invalidBackendResponse":
return [
heading,
"⚠️ **Configuration was disabled for safety**",
"",
"Cleo received a configuration response it could not validate and did not apply it.",
"Use the dashboard to review the server configuration.",
].join("\n")
case "invalidGuildId":
return [
heading,
"⚠️ **This server could not be identified**",
"",
"Cleo could not safely load configuration for this server.",
].join("\n")
}
}
function formatModuleLine(
label: string,
enabled: boolean,
configured: boolean,
detail?: string
): string {
if (!enabled) {
return `◻️ **${label}** · Off`
}
if (!configured) {
return `⚠️ **${label}** · On, setup incomplete`
}
return `✅ **${label}** · On${detail ? ` · ${detail}` : ""}`
}
function capitalize(value: string): string {
return `${value.charAt(0).toUpperCase()}${value.slice(1)}`
}
|