Add dashboard UI source and track it in the repository.
Expose the Vite/React website source under dashboard/ (with node_modules still ignored) so the full dashboard can be built and maintained from this repo.
This commit is contained in:
1 parent
e97e281bda
commit
b82f69783d
117 files changed
+18615
-3
No files matched your search
@@ -0,0 +1,128 @@
|
||||
import { isValidHex, normalizeHex } from "@/lib/normalize-hex";
|
||||
|
||||
export const ACCENT_STORAGE_KEY = "supportbot-dashboard-accent";
|
||||
export const DEFAULT_ACCENT_HEX = "#45b46c";
|
||||
|
||||
const CSS_VARS = [
|
||||
"--primary",
|
||||
"--ring",
|
||||
"--chart-1",
|
||||
"--sidebar-primary",
|
||||
"--sidebar-ring",
|
||||
"--accent",
|
||||
"--accent-foreground",
|
||||
"--sidebar-accent",
|
||||
"--sidebar-accent-foreground",
|
||||
] as const;
|
||||
|
||||
export function hexToHsl(hex: string): { h: number; s: number; l: number } {
|
||||
const normalized = normalizeHex(hex, DEFAULT_ACCENT_HEX);
|
||||
const r = parseInt(normalized.slice(1, 3), 16) / 255;
|
||||
const g = parseInt(normalized.slice(3, 5), 16) / 255;
|
||||
const b = parseInt(normalized.slice(5, 7), 16) / 255;
|
||||
|
||||
const max = Math.max(r, g, b);
|
||||
const min = Math.min(r, g, b);
|
||||
const l = (max + min) / 2;
|
||||
let h = 0;
|
||||
let s = 0;
|
||||
|
||||
if (max !== min) {
|
||||
const d = max - min;
|
||||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||
switch (max) {
|
||||
case r:
|
||||
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
||||
break;
|
||||
case g:
|
||||
h = ((b - r) / d + 2) / 6;
|
||||
break;
|
||||
default:
|
||||
h = ((r - g) / d + 4) / 6;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
h: Math.round(h * 360),
|
||||
s: Math.round(s * 100),
|
||||
l: Math.round(l * 100),
|
||||
};
|
||||
}
|
||||
|
||||
function hsl(h: number, s: number, l: number): string {
|
||||
return `${h} ${s}% ${l}%`;
|
||||
}
|
||||
|
||||
/** Apply accent colour to dashboard CSS variables (replaces default purple). */
|
||||
export function applyAccentTheme(hex: string): string {
|
||||
const normalized = normalizeHex(hex, DEFAULT_ACCENT_HEX);
|
||||
const { h, s, l } = hexToHsl(normalized);
|
||||
const root = document.documentElement;
|
||||
|
||||
const primaryS = Math.min(Math.max(s, 45), 85);
|
||||
const primaryL = Math.min(Math.max(l, 42), 62);
|
||||
|
||||
root.style.setProperty("--primary", hsl(h, primaryS, primaryL));
|
||||
root.style.setProperty("--ring", hsl(h, primaryS, primaryL));
|
||||
root.style.setProperty("--chart-1", hsl(h, primaryS, primaryL));
|
||||
root.style.setProperty("--sidebar-primary", hsl(h, primaryS, primaryL));
|
||||
root.style.setProperty("--sidebar-ring", hsl(h, primaryS, primaryL));
|
||||
root.style.setProperty("--primary-foreground", "0 0% 100%");
|
||||
root.style.setProperty("--sidebar-primary-foreground", "0 0% 100%");
|
||||
|
||||
root.style.setProperty("--accent", hsl(h, Math.round(primaryS * 0.64), 18));
|
||||
root.style.setProperty(
|
||||
"--accent-foreground",
|
||||
hsl(h, Math.min(Math.round(primaryS * 1.15), 90), 78),
|
||||
);
|
||||
root.style.setProperty("--sidebar-accent", hsl(h, Math.round(primaryS * 0.57), 14));
|
||||
root.style.setProperty(
|
||||
"--sidebar-accent-foreground",
|
||||
hsl(h, Math.min(Math.round(primaryS * 1.07), 88), 82),
|
||||
);
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function clearAccentTheme(): void {
|
||||
for (const name of CSS_VARS) {
|
||||
document.documentElement.style.removeProperty(name);
|
||||
}
|
||||
document.documentElement.style.removeProperty("--primary-foreground");
|
||||
document.documentElement.style.removeProperty("--sidebar-primary-foreground");
|
||||
}
|
||||
|
||||
export function getStoredAccentHex(): string | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(ACCENT_STORAGE_KEY);
|
||||
if (!raw || !isValidHex(raw)) return null;
|
||||
return normalizeHex(raw);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveAccentTheme(hex: string): string {
|
||||
const normalized = applyAccentTheme(hex);
|
||||
try {
|
||||
localStorage.setItem(ACCENT_STORAGE_KEY, normalized);
|
||||
} catch {
|
||||
/* ignore quota */
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function resetAccentTheme(): void {
|
||||
try {
|
||||
localStorage.removeItem(ACCENT_STORAGE_KEY);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
clearAccentTheme();
|
||||
}
|
||||
|
||||
export function initAccentTheme(): void {
|
||||
const stored = getStoredAccentHex();
|
||||
if (stored) applyAccentTheme(stored);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
export const ADDON_CONFIG_PREFIX = "addon:";
|
||||
|
||||
export function addonConfigFileParam(filename: string): string {
|
||||
return `${ADDON_CONFIG_PREFIX}${filename}`;
|
||||
}
|
||||
|
||||
export function parseConfigFileParam(
|
||||
file: string | null,
|
||||
): { type: "main" | "addon"; file: string } | null {
|
||||
if (!file) return null;
|
||||
if (file.startsWith(ADDON_CONFIG_PREFIX)) {
|
||||
return {
|
||||
type: "addon",
|
||||
file: file.slice(ADDON_CONFIG_PREFIX.length),
|
||||
};
|
||||
}
|
||||
return { type: "main", file };
|
||||
}
|
||||
|
||||
export function addonConfigLabel(filename: string): string {
|
||||
return filename
|
||||
.replace(/\.(yml|yaml|json)$/i, "")
|
||||
.replace(/[-_]/g, " ")
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { DashboardBranding } from "@/lib/branding-types";
|
||||
|
||||
const FAVICON_LINK_ID = "supportbot-dashboard-favicon";
|
||||
|
||||
export function applyDashboardBranding(branding: DashboardBranding) {
|
||||
if (branding.pageTitle) {
|
||||
document.title = branding.pageTitle;
|
||||
}
|
||||
|
||||
let link = document.getElementById(FAVICON_LINK_ID) as HTMLLinkElement | null;
|
||||
if (branding.faviconUrl) {
|
||||
const href = `${branding.faviconUrl}${branding.updatedAt ? `?v=${branding.updatedAt}` : ""}`;
|
||||
if (!link) {
|
||||
link = document.createElement("link");
|
||||
link.id = FAVICON_LINK_ID;
|
||||
link.rel = "icon";
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
link.href = href;
|
||||
} else if (link) {
|
||||
link.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface DashboardBranding {
|
||||
title: string;
|
||||
pageTitle: string;
|
||||
hasFavicon: boolean;
|
||||
faviconUrl: string | null;
|
||||
updatedAt: number | null;
|
||||
}
|
||||
|
||||
export const DEFAULT_BRANDING: DashboardBranding = {
|
||||
title: "SupportBot",
|
||||
pageTitle: "SupportBot Dashboard",
|
||||
hasFavicon: false,
|
||||
faviconUrl: null,
|
||||
updatedAt: null,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { ConfigSchema } from "./types";
|
||||
import { messagesSchema } from "./messages";
|
||||
import { supportbotSchema } from "./supportbot";
|
||||
import { supportbotAiSchema } from "./supportbot-ai";
|
||||
import { ticketPanelSchema } from "./ticket-panel";
|
||||
|
||||
export type ConfigFileName =
|
||||
| "supportbot"
|
||||
| "ticket-panel"
|
||||
| "commands"
|
||||
| "messages"
|
||||
| "supportbot-ai";
|
||||
|
||||
export const configSchemas: Record<ConfigFileName, ConfigSchema | "commands"> = {
|
||||
supportbot: supportbotSchema,
|
||||
"ticket-panel": ticketPanelSchema,
|
||||
commands: "commands",
|
||||
messages: messagesSchema,
|
||||
"supportbot-ai": supportbotAiSchema,
|
||||
};
|
||||
|
||||
export function getSchema(file: string): ConfigSchema | "commands" | null {
|
||||
if (file in configSchemas) {
|
||||
return configSchemas[file as ConfigFileName];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export * from "./types";
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { ConfigSchema } from "./types";
|
||||
|
||||
export const messagesSchema: ConfigSchema = [
|
||||
{
|
||||
title: "Info command",
|
||||
fields: [
|
||||
{ path: "Info.Title", label: "Title", type: "text" },
|
||||
{ path: "Info.Description", label: "Description", type: "textarea" },
|
||||
{ path: "Info.Button", label: "Button label", type: "text" },
|
||||
{ path: "Info.URL", label: "Button URL", type: "text" },
|
||||
{ path: "Info.Colour", label: "Colour", type: "color" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Welcome message",
|
||||
fields: [
|
||||
{ path: "Welcome.Enabled", label: "Enabled", type: "boolean" },
|
||||
{
|
||||
path: "Welcome.LayoutStyle",
|
||||
label: "Layout style",
|
||||
type: "select",
|
||||
options: [
|
||||
{ value: "modern", label: "Modern (components)" },
|
||||
{ value: "classic", label: "Classic embed" },
|
||||
],
|
||||
},
|
||||
{ path: "Welcome.Embed.Colour", label: "Embed colour", type: "color" },
|
||||
{ path: "Welcome.Embed.Title", label: "Embed title", type: "text" },
|
||||
{ path: "Welcome.Embed.Message", label: "Embed message", type: "textarea" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Leave message",
|
||||
fields: [
|
||||
{ path: "Leave.Enabled", label: "Enabled", type: "boolean" },
|
||||
{ path: "Leave.Embed.Colour", label: "Embed colour", type: "color" },
|
||||
{ path: "Leave.Embed.Title", label: "Embed title", type: "text" },
|
||||
{ path: "Leave.Embed.Message", label: "Embed message", type: "textarea" },
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,142 @@
|
||||
import type { ConfigSchema } from "./types";
|
||||
|
||||
const providers = [
|
||||
{ value: "openai", label: "OpenAI" },
|
||||
{ value: "groq", label: "Groq" },
|
||||
{ value: "claude", label: "Claude" },
|
||||
];
|
||||
|
||||
const messageTypes = [
|
||||
{ value: "text", label: "Plain text" },
|
||||
{ value: "embed", label: "Embed" },
|
||||
{ value: "components_v2", label: "Components v2" },
|
||||
];
|
||||
|
||||
const memoryScopes = [
|
||||
{ value: "channel", label: "Per channel" },
|
||||
{ value: "guild", label: "Per server" },
|
||||
];
|
||||
|
||||
export const supportbotAiSchema: ConfigSchema = [
|
||||
{
|
||||
title: "General",
|
||||
fields: [
|
||||
{ path: "Enabled", label: "AI enabled", type: "boolean" },
|
||||
{
|
||||
path: "General.Provider",
|
||||
label: "Provider",
|
||||
type: "select",
|
||||
options: providers,
|
||||
},
|
||||
{ path: "General.Model", label: "Model", type: "text" },
|
||||
{
|
||||
path: "General.Model_API_Key",
|
||||
label: "API key",
|
||||
type: "secret",
|
||||
placeholder: "MODEL_API_KEY",
|
||||
},
|
||||
{ path: "General.Tokens", label: "Max tokens", type: "number" },
|
||||
{
|
||||
path: "General.Temperature",
|
||||
label: "Temperature",
|
||||
type: "number",
|
||||
},
|
||||
{ path: "General.Name", label: "Display name", type: "text" },
|
||||
{
|
||||
path: "General.PastebinAPI_Key",
|
||||
label: "Pastebin API key",
|
||||
type: "secret",
|
||||
placeholder: "PASTEBIN_API_KEY",
|
||||
},
|
||||
{
|
||||
path: "General.PastebinAPI_URL",
|
||||
label: "Pastebin API URL",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Style & channel",
|
||||
fields: [
|
||||
{
|
||||
path: "Style.MessageType",
|
||||
label: "Message type",
|
||||
type: "select",
|
||||
options: messageTypes,
|
||||
},
|
||||
{
|
||||
path: "Features.SuggestTickets",
|
||||
label: "Suggest tickets",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Channels.AIChannel",
|
||||
label: "AI channel ID",
|
||||
type: "discordId",
|
||||
},
|
||||
{ path: "Embed.Color", label: "Embed colour", type: "color" },
|
||||
{ path: "Embed.Footer", label: "Embed footer", type: "text" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Memory",
|
||||
fields: [
|
||||
{ path: "Memory.Enabled", label: "Memory enabled", type: "boolean" },
|
||||
{ path: "Memory.StoreFacts", label: "Store facts", type: "boolean" },
|
||||
{
|
||||
path: "Memory.StoreSummaries",
|
||||
label: "Store summaries",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Memory.MaxRecentMessages",
|
||||
label: "Max recent messages",
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
path: "Memory.Scope",
|
||||
label: "Memory scope",
|
||||
type: "select",
|
||||
options: memoryScopes,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Custom instructions",
|
||||
fields: [
|
||||
{
|
||||
path: "CustomInstructions",
|
||||
label: "Instruction lines",
|
||||
type: "stringList",
|
||||
description: "One instruction per line sent to the AI.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Messages",
|
||||
fields: [
|
||||
{
|
||||
path: "Messages.ErrorResponse",
|
||||
label: "Error response",
|
||||
type: "text",
|
||||
},
|
||||
{ path: "Messages.AIError", label: "AI error", type: "text" },
|
||||
{ path: "Messages.AIDisabled", label: "AI disabled", type: "text" },
|
||||
{
|
||||
path: "Messages.MessageTooLong",
|
||||
label: "Message too long",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Messages.SuggestTicketText",
|
||||
label: "Suggest ticket text",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Messages.SuggestTicketReaction",
|
||||
label: "Suggest ticket emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,507 @@
|
||||
import type { ConfigSchema } from "./types";
|
||||
|
||||
const activityTypes = [
|
||||
{ value: "Playing", label: "Playing" },
|
||||
{ value: "Watching", label: "Watching" },
|
||||
{ value: "Listening", label: "Listening" },
|
||||
{ value: "Competing", label: "Competing" },
|
||||
{ value: "Streaming", label: "Streaming" },
|
||||
];
|
||||
|
||||
const suggestionModes = [
|
||||
{ value: "Channel", label: "Channel" },
|
||||
{ value: "Forum", label: "Forum" },
|
||||
];
|
||||
|
||||
const ticketTypes = [
|
||||
{ value: "channels", label: "Channels" },
|
||||
{ value: "threads", label: "Threads" },
|
||||
];
|
||||
|
||||
const ticketSubjects = [
|
||||
{ value: "description", label: "Channel description" },
|
||||
{ value: "embed", label: "Embed" },
|
||||
];
|
||||
|
||||
const buttonStyles = [
|
||||
{ value: "1", label: "Blurple" },
|
||||
{ value: "2", label: "Grey" },
|
||||
{ value: "3", label: "Green" },
|
||||
{ value: "4", label: "Red" },
|
||||
];
|
||||
|
||||
export const supportbotSchema: ConfigSchema = [
|
||||
{
|
||||
title: "General",
|
||||
fields: [
|
||||
{ path: "General.Name", label: "Bot name", type: "text" },
|
||||
{
|
||||
path: "General.Token",
|
||||
label: "Bot token",
|
||||
type: "secret",
|
||||
description: "Masked in the dashboard. Your real token is preserved on save.",
|
||||
},
|
||||
{
|
||||
path: "General.GuildId",
|
||||
label: "Server (guild) ID",
|
||||
type: "discordId",
|
||||
description:
|
||||
"Right-click your Discord server icon → Copy Server ID. The bot should only stay in this server.",
|
||||
placeholder: "Discord server snowflake ID",
|
||||
},
|
||||
{
|
||||
path: "General.Addons.Enabled",
|
||||
label: "Addons enabled",
|
||||
type: "boolean",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Activity",
|
||||
fields: [
|
||||
{ path: "Activity.Status", label: "Status text", type: "text" },
|
||||
{
|
||||
path: "Activity.Type",
|
||||
label: "Activity type",
|
||||
type: "select",
|
||||
options: activityTypes,
|
||||
},
|
||||
{
|
||||
path: "Activity.StreamingURL",
|
||||
label: "Streaming URL",
|
||||
type: "text",
|
||||
description: "Required when type is Streaming.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Embeds",
|
||||
fields: [
|
||||
{ path: "Embed.Colours.General", label: "General colour", type: "color" },
|
||||
{ path: "Embed.Colours.Success", label: "Success colour", type: "color" },
|
||||
{ path: "Embed.Colours.Error", label: "Error colour", type: "color" },
|
||||
{ path: "Embed.Colours.Warn", label: "Warn colour", type: "color" },
|
||||
{ path: "Embed.Footer", label: "Footer text", type: "text" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Roles",
|
||||
fields: [
|
||||
{
|
||||
path: "Roles.AutoRole.Enabled",
|
||||
label: "Auto role enabled",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Roles.AutoRole.Role",
|
||||
label: "Auto role",
|
||||
type: "discordRole",
|
||||
},
|
||||
{
|
||||
path: "Roles.StaffMember.Staff",
|
||||
label: "Staff role",
|
||||
type: "discordRole",
|
||||
},
|
||||
{
|
||||
path: "Roles.StaffMember.Admin",
|
||||
label: "Admin role",
|
||||
type: "discordRole",
|
||||
},
|
||||
{
|
||||
path: "Roles.StaffMember.Moderator",
|
||||
label: "Moderator role",
|
||||
type: "discordRole",
|
||||
},
|
||||
{
|
||||
path: "Roles.Mod.AllowSupportStaff",
|
||||
label: "Allow support staff /mod",
|
||||
type: "boolean",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Welcome & leave",
|
||||
fields: [
|
||||
{ path: "Welcome.Enabled", label: "Welcome enabled", type: "boolean" },
|
||||
{
|
||||
path: "Welcome.Channel",
|
||||
label: "Welcome channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{ path: "Leave.Enabled", label: "Leave enabled", type: "boolean" },
|
||||
{
|
||||
path: "Leave.Channel",
|
||||
label: "Leave channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Suggestions",
|
||||
fields: [
|
||||
{
|
||||
path: "Suggestions.Mode",
|
||||
label: "Mode",
|
||||
type: "select",
|
||||
options: suggestionModes,
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Channel",
|
||||
label: "Suggestions channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.ForumChannel",
|
||||
label: "Forum channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.UpvoteEmoji",
|
||||
label: "Upvote emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.DownvoteEmoji",
|
||||
label: "Downvote emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
{ path: "Suggestions.OwnSuggestion", label: "Own suggestion votes", type: "boolean" },
|
||||
{ path: "Suggestions.ShowUsers", label: "Show users", type: "boolean" },
|
||||
{
|
||||
path: "Suggestions.UpvoteTitle",
|
||||
label: "Upvote button title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.DownvoteTitle",
|
||||
label: "Downvote button title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Threads.Enabled",
|
||||
label: "Suggestion threads",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Threads.Title",
|
||||
label: "Thread title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Threads.Reason",
|
||||
label: "Thread reason",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Buttons.Upvote",
|
||||
label: "Upvote button style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Buttons.Downvote",
|
||||
label: "Downvote button style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Buttons.RemoveVote",
|
||||
label: "Remove vote button style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Buttons.RemoveVote_Title",
|
||||
label: "Remove vote title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Tags.Created",
|
||||
label: "Tag: created",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Tags.Considering",
|
||||
label: "Tag: considering",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Tags.Solved",
|
||||
label: "Tag: solved",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Suggestions.Tags.Denied",
|
||||
label: "Tag: denied",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Tickets",
|
||||
fields: [
|
||||
{
|
||||
path: "Ticket.TicketType",
|
||||
label: "Ticket type",
|
||||
type: "select",
|
||||
options: ticketTypes,
|
||||
},
|
||||
{
|
||||
path: "Ticket.UserManagement.DMOnAdd",
|
||||
label: "DM when added to ticket",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.UserManagement.DMOnRemove",
|
||||
label: "DM when removed from ticket",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.UserManagement.DMTranscript",
|
||||
label: "DM transcript on close",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.TicketHome",
|
||||
label: "Ticket home channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Ticket.TicketChannelsCategory",
|
||||
label: "Ticket category",
|
||||
type: "discordCategory",
|
||||
},
|
||||
{
|
||||
path: "Ticket.TicketChannelsCategory2",
|
||||
label: "Overflow ticket category",
|
||||
type: "discordCategory",
|
||||
description: "Used when the first category is full.",
|
||||
},
|
||||
{
|
||||
path: "Ticket.TicketArchiveCategory",
|
||||
label: "Archive category",
|
||||
type: "discordCategory",
|
||||
},
|
||||
{ path: "Ticket.Channel", label: "Channel prefix", type: "text" },
|
||||
{
|
||||
path: "Ticket.TicketSubject",
|
||||
label: "Ticket subject display",
|
||||
type: "select",
|
||||
options: ticketSubjects,
|
||||
},
|
||||
{ path: "Ticket.Timeout", label: "Close timeout (minutes)", type: "number" },
|
||||
{
|
||||
path: "Ticket.TicketsPerUser",
|
||||
label: "Tickets per user",
|
||||
type: "number",
|
||||
},
|
||||
{ path: "Ticket.TicketReason", label: "Require reason", type: "boolean" },
|
||||
{
|
||||
path: "Ticket.Close.StaffOnly",
|
||||
label: "Close staff only",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Invites.StaffOnly",
|
||||
label: "Ticket invites staff only",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ClaimTickets.Enabled",
|
||||
label: "Claim tickets",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ClaimTickets.Channel",
|
||||
label: "Claim log channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ClaimTickets.ClaimAcceptTime",
|
||||
label: "Claim accept time (ms)",
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ClaimTickets.ButtonTitle",
|
||||
label: "Claim button title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ClaimTickets.ButtonEmoji",
|
||||
label: "Claim button emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ClaimTickets.Button",
|
||||
label: "Claim button style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{
|
||||
path: "Ticket.ReviewSystem.Enabled",
|
||||
label: "Review system",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ReviewSystem.Channel",
|
||||
label: "Review channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Ticket.ReviewSystem.UseModal",
|
||||
label: "Review uses modal",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Log.TicketDataLog",
|
||||
label: "Ticket data log channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Log.TickeDataTitle",
|
||||
label: "Ticket data log title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Log.TicketBlacklistLog",
|
||||
label: "Blacklist log channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "Ticket.AIMode.Enabled",
|
||||
label: "AI mode in tickets",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.AIMode.ThreadName",
|
||||
label: "AI thread name",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Ticket.AIMode.WelcomeMessage",
|
||||
label: "AI welcome message",
|
||||
type: "textarea",
|
||||
},
|
||||
{
|
||||
path: "Ticket.DepartmentSystem.Enabled",
|
||||
label: "Departments enabled",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.DepartmentSystem.Placeholder",
|
||||
label: "Department placeholder",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Ticket.DepartmentSystem.DefaultDepartment",
|
||||
label: "Default department key",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Ticket.PrioritySystem.Enabled",
|
||||
label: "Priority system",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.PrioritySystem.DefaultPriority",
|
||||
label: "Default priority",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Ticket.PrioritySystem.AllowUsersToChooseOnOpen",
|
||||
label: "User picks priority on open",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Questions.Enabled",
|
||||
label: "Ticket questions",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Questions.List",
|
||||
label: "Default questions",
|
||||
type: "stringList",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Voice tickets",
|
||||
fields: [
|
||||
{ path: "VoiceTickets.Name", label: "VC name format", type: "text" },
|
||||
{
|
||||
path: "VoiceTickets.Category",
|
||||
label: "VC category",
|
||||
type: "discordCategory",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Logging",
|
||||
fields: [
|
||||
{
|
||||
path: "MessageDelete.Channel",
|
||||
label: "Message delete log channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "MessageDelete.Colour",
|
||||
label: "Message delete embed colour",
|
||||
type: "color",
|
||||
},
|
||||
{
|
||||
path: "MessageUpdate.Channel",
|
||||
label: "Message update log channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
{
|
||||
path: "MessageUpdate.Colour",
|
||||
label: "Message update embed colour",
|
||||
type: "color",
|
||||
},
|
||||
{
|
||||
path: "Translate.TranslateLog",
|
||||
label: "Translate log channel",
|
||||
type: "discordChannel",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Buttons & menus",
|
||||
description: "Ticket panel and control button labels and styles.",
|
||||
fields: [
|
||||
{ path: "Buttons.General.Delete", label: "Delete emoji", type: "emoji" },
|
||||
{
|
||||
path: "Buttons.General.DeleteStyle",
|
||||
label: "Delete button style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{
|
||||
path: "Buttons.Voice.TicketDeleteText",
|
||||
label: "Voice delete label",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Buttons.Tickets.ClaimEmoji",
|
||||
label: "Ticket claim emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
{
|
||||
path: "Buttons.Tickets.ClaimStyle",
|
||||
label: "Ticket claim style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{
|
||||
path: "SelectMenus.Tickets.PanelEmoji",
|
||||
label: "Panel menu emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
{
|
||||
path: "SelectMenus.Tickets.CloseEmoji",
|
||||
label: "Close menu emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,109 @@
|
||||
import type { ConfigSchema } from "./types";
|
||||
|
||||
const buttonStyles = [
|
||||
{ value: "1", label: "Blurple" },
|
||||
{ value: "2", label: "Grey" },
|
||||
{ value: "3", label: "Green" },
|
||||
{ value: "4", label: "Red" },
|
||||
];
|
||||
|
||||
const layouts = [
|
||||
{ value: "1", label: "Style 1" },
|
||||
{ value: "2", label: "Style 2" },
|
||||
{ value: "3", label: "Style 3" },
|
||||
{ value: "4", label: "Style 4 (classic embed)" },
|
||||
];
|
||||
|
||||
export const ticketPanelSchema: ConfigSchema = [
|
||||
{
|
||||
title: "Panel",
|
||||
fields: [{ path: "Panel", label: "Panel enabled", type: "boolean" }],
|
||||
},
|
||||
{
|
||||
title: "Embed style",
|
||||
fields: [
|
||||
{ path: "Style.Title", label: "Title", type: "text" },
|
||||
{ path: "Style.Description", label: "Description", type: "textarea" },
|
||||
{ path: "Style.Image", label: "Image URL", type: "text" },
|
||||
{ path: "Style.Color", label: "Embed colour", type: "color" },
|
||||
{
|
||||
path: "Style.Layout",
|
||||
label: "Layout",
|
||||
type: "select",
|
||||
options: layouts,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Create button",
|
||||
fields: [
|
||||
{ path: "Button.Text", label: "Button text", type: "text" },
|
||||
{ path: "Button.Emoji", label: "Button emoji", type: "emoji" },
|
||||
{
|
||||
path: "Button.Color",
|
||||
label: "Button style",
|
||||
type: "select",
|
||||
options: buttonStyles,
|
||||
},
|
||||
{ path: "Button.CustomId", label: "Custom ID", type: "text" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Department menu",
|
||||
fields: [
|
||||
{ path: "DepartmentMenu.CustomId", label: "Custom ID", type: "text" },
|
||||
{ path: "DepartmentMenu.Placeholder", label: "Placeholder", type: "text" },
|
||||
{
|
||||
path: "DepartmentMenu.DefaultDescription",
|
||||
label: "Default description",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "DepartmentMenu.DefaultEmoji",
|
||||
label: "Default emoji",
|
||||
type: "emoji",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Panel settings",
|
||||
fields: [
|
||||
{ path: "Settings.Image", label: "Show image", type: "boolean" },
|
||||
{ path: "Settings.TopTitle", label: "Top title", type: "boolean" },
|
||||
{ path: "Settings.TopDivider", label: "Top divider", type: "boolean" },
|
||||
{
|
||||
path: "Settings.BottomTitle",
|
||||
label: "Bottom title",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Settings.BottomDivider",
|
||||
label: "Bottom divider",
|
||||
type: "boolean",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Messages",
|
||||
description: "Bot messages when using the ticket panel command.",
|
||||
fields: [
|
||||
{
|
||||
path: "Messages.NotConfigured",
|
||||
label: "Not configured",
|
||||
type: "textarea",
|
||||
},
|
||||
{
|
||||
path: "Messages.InvalidChannel",
|
||||
label: "Invalid channel",
|
||||
type: "textarea",
|
||||
},
|
||||
{ path: "Messages.PanelSent", label: "Panel sent", type: "text" },
|
||||
{
|
||||
path: "Messages.PanelSentWithDepartments",
|
||||
label: "Panel sent (departments)",
|
||||
type: "text",
|
||||
},
|
||||
{ path: "Messages.SendError", label: "Send error", type: "text" },
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
export type FieldType =
|
||||
| "text"
|
||||
| "textarea"
|
||||
| "boolean"
|
||||
| "number"
|
||||
| "color"
|
||||
| "emoji"
|
||||
| "select"
|
||||
| "discordId"
|
||||
| "discordChannel"
|
||||
| "discordRole"
|
||||
| "discordCategory"
|
||||
| "secret"
|
||||
| "stringList"
|
||||
| "googleFont";
|
||||
|
||||
export interface ConfigField {
|
||||
path: string;
|
||||
label: string;
|
||||
type: FieldType;
|
||||
description?: string;
|
||||
options?: { value: string; label: string }[];
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export interface ConfigSection {
|
||||
title: string;
|
||||
description?: string;
|
||||
fields: ConfigField[];
|
||||
}
|
||||
|
||||
export type ConfigSchema = ConfigSection[];
|
||||
@@ -0,0 +1,57 @@
|
||||
export function getByPath(obj: Record<string, unknown>, path: string): unknown {
|
||||
const keys = path.split(".");
|
||||
let cur: unknown = obj;
|
||||
for (const key of keys) {
|
||||
if (cur == null || typeof cur !== "object") return undefined;
|
||||
cur = (cur as Record<string, unknown>)[key];
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
|
||||
export function setByPath(
|
||||
obj: Record<string, unknown>,
|
||||
path: string,
|
||||
value: unknown,
|
||||
): Record<string, unknown> {
|
||||
const keys = path.split(".");
|
||||
const clone = structuredClone(obj);
|
||||
let cur: Record<string, unknown> = clone;
|
||||
for (let i = 0; i < keys.length - 1; i++) {
|
||||
const key = keys[i];
|
||||
if (cur[key] == null || typeof cur[key] !== "object") {
|
||||
cur[key] = {};
|
||||
}
|
||||
cur = cur[key] as Record<string, unknown>;
|
||||
}
|
||||
cur[keys[keys.length - 1]] = value;
|
||||
return clone;
|
||||
}
|
||||
|
||||
export function flattenUpdates(
|
||||
configFile: string,
|
||||
obj: Record<string, unknown>,
|
||||
prefix = "",
|
||||
): Record<string, unknown> {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const [key, val] of Object.entries(obj)) {
|
||||
const path = prefix ? `${prefix}.${key}` : key;
|
||||
if (
|
||||
val !== null &&
|
||||
typeof val === "object" &&
|
||||
!Array.isArray(val) &&
|
||||
Object.keys(val as object).length > 0 &&
|
||||
!isLeafObject(val as Record<string, unknown>)
|
||||
) {
|
||||
Object.assign(out, flattenUpdates(configFile, val as Record<string, unknown>, path));
|
||||
} else {
|
||||
out[`${configFile}:${path}`] = val;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function isLeafObject(o: Record<string, unknown>): boolean {
|
||||
return Object.values(o).every(
|
||||
(v) => v === null || typeof v !== "object" || Array.isArray(v),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { api } from "@/api/client";
|
||||
import type {
|
||||
ClientAlertProvider,
|
||||
DashboardAlertPayload,
|
||||
DashboardAlertSeverity,
|
||||
} from "./types";
|
||||
|
||||
const SEVERITY_ORDER: Record<DashboardAlertSeverity, number> = {
|
||||
error: 0,
|
||||
warning: 1,
|
||||
info: 2,
|
||||
};
|
||||
|
||||
function sortAlerts(alerts: DashboardAlertPayload[]) {
|
||||
return [...alerts].sort((a, b) => {
|
||||
const sa = SEVERITY_ORDER[a.severity] ?? 9;
|
||||
const sb = SEVERITY_ORDER[b.severity] ?? 9;
|
||||
if (sa !== sb) return sa - sb;
|
||||
return a.title.localeCompare(b.title);
|
||||
});
|
||||
}
|
||||
|
||||
function dedupeAlerts(alerts: DashboardAlertPayload[]) {
|
||||
const seen = new Set<string>();
|
||||
return alerts.filter((alert) => {
|
||||
if (seen.has(alert.id)) return false;
|
||||
seen.add(alert.id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side alert registry. Server alerts come from GET /api/alerts;
|
||||
* register providers here for browser-only checks (feature flags, UI hints, etc.).
|
||||
*
|
||||
* Example:
|
||||
* dashboardAlertBuilder.register({
|
||||
* id: "local-hint",
|
||||
* evaluate: () => [{
|
||||
* id: "local:hint",
|
||||
* severity: "info",
|
||||
* category: "local",
|
||||
* title: "Tip",
|
||||
* message: "You can customise accent colour in Settings.",
|
||||
* }],
|
||||
* });
|
||||
*/
|
||||
class DashboardAlertBuilder {
|
||||
private clientProviders = new Map<string, ClientAlertProvider>();
|
||||
|
||||
register(provider: ClientAlertProvider) {
|
||||
this.clientProviders.set(provider.id, provider);
|
||||
return this;
|
||||
}
|
||||
|
||||
unregister(id: string) {
|
||||
this.clientProviders.delete(id);
|
||||
}
|
||||
|
||||
private async evaluateClientProviders() {
|
||||
const alerts: DashboardAlertPayload[] = [];
|
||||
for (const provider of this.clientProviders.values()) {
|
||||
const result = await provider.evaluate();
|
||||
if (Array.isArray(result) && result.length) {
|
||||
alerts.push(...result);
|
||||
}
|
||||
}
|
||||
return alerts;
|
||||
}
|
||||
|
||||
async loadAll(): Promise<DashboardAlertPayload[]> {
|
||||
const [serverRes, clientAlerts] = await Promise.all([
|
||||
api.getAlerts().catch(() => ({ data: [] as DashboardAlertPayload[] })),
|
||||
this.evaluateClientProviders(),
|
||||
]);
|
||||
|
||||
const serverAlerts = serverRes.data ?? [];
|
||||
return sortAlerts(dedupeAlerts([...serverAlerts, ...clientAlerts]));
|
||||
}
|
||||
}
|
||||
|
||||
export const dashboardAlertBuilder = new DashboardAlertBuilder();
|
||||
@@ -0,0 +1,12 @@
|
||||
export { dashboardAlertBuilder } from "./builder";
|
||||
export type {
|
||||
ClientAlertProvider,
|
||||
DashboardAlertAction,
|
||||
DashboardAlertDefinition,
|
||||
DashboardAlertGuildMeta,
|
||||
DashboardAlertModuleMeta,
|
||||
DashboardAlertPayload,
|
||||
DashboardAlertRenderContext,
|
||||
DashboardAlertSeverity,
|
||||
} from "./types";
|
||||
export { SEVERITY_STYLES } from "./types";
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { ReactNode } from "react";
|
||||
import type { GuildHealthStatus, GuildSummary } from "@/api/client";
|
||||
|
||||
export type DashboardAlertSeverity = "error" | "warning" | "info";
|
||||
|
||||
export interface DashboardAlertAction {
|
||||
label: string;
|
||||
href: string;
|
||||
}
|
||||
|
||||
export interface DashboardAlertGuildMeta {
|
||||
status?: GuildHealthStatus;
|
||||
configuredGuildId?: string | null;
|
||||
configuredGuild?: GuildSummary | null;
|
||||
extraGuilds?: GuildSummary[];
|
||||
}
|
||||
|
||||
export interface DashboardAlertModuleMeta {
|
||||
moduleId?: string;
|
||||
status?: "todo" | "progress" | "done";
|
||||
passed?: number;
|
||||
total?: number;
|
||||
progress?: string | null;
|
||||
}
|
||||
|
||||
export interface DashboardAlertPayload {
|
||||
id: string;
|
||||
severity: DashboardAlertSeverity;
|
||||
category: string;
|
||||
title: string;
|
||||
message: string;
|
||||
action?: DashboardAlertAction;
|
||||
meta?: DashboardAlertGuildMeta & DashboardAlertModuleMeta & Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface DashboardAlertRenderContext {
|
||||
canLeaveGuild: boolean;
|
||||
onLeaveGuild: (guildId: string) => Promise<void>;
|
||||
leavingGuildId: string | null;
|
||||
actionError: string;
|
||||
}
|
||||
|
||||
export interface ClientAlertProvider {
|
||||
id: string;
|
||||
evaluate: () => DashboardAlertPayload[] | Promise<DashboardAlertPayload[]>;
|
||||
}
|
||||
|
||||
export interface DashboardAlertDefinition extends DashboardAlertPayload {
|
||||
/** Optional custom body rendered below the message */
|
||||
body?: ReactNode;
|
||||
}
|
||||
|
||||
export const SEVERITY_STYLES: Record<
|
||||
DashboardAlertSeverity,
|
||||
{ border: string; bg: string; icon: string; title: string }
|
||||
> = {
|
||||
error: {
|
||||
border: "border-destructive/40",
|
||||
bg: "bg-destructive/10",
|
||||
icon: "text-destructive",
|
||||
title: "text-destructive",
|
||||
},
|
||||
warning: {
|
||||
border: "border-amber-500/40",
|
||||
bg: "bg-amber-500/10",
|
||||
icon: "text-amber-500",
|
||||
title: "text-amber-200",
|
||||
},
|
||||
info: {
|
||||
border: "border-sky-500/40",
|
||||
bg: "bg-sky-500/10",
|
||||
icon: "text-sky-400",
|
||||
title: "text-sky-100",
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
/** Discord custom emoji mention: <:name:id> or <a:name:id> */
|
||||
const CUSTOM_EMOJI_RE = /^<(a?):([^:>]+):(\d{17,20})>$/;
|
||||
|
||||
export interface GuildEmojiOption {
|
||||
id: string;
|
||||
name: string;
|
||||
animated: boolean;
|
||||
url: string | null;
|
||||
}
|
||||
|
||||
export interface ParsedEmoji {
|
||||
kind: "unicode" | "custom" | "empty";
|
||||
/** Value stored in YAML */
|
||||
value: string;
|
||||
name?: string;
|
||||
id?: string;
|
||||
animated?: boolean;
|
||||
}
|
||||
|
||||
export function formatCustomEmoji(
|
||||
name: string,
|
||||
id: string,
|
||||
animated = false,
|
||||
): string {
|
||||
const prefix = animated ? "<a" : "<";
|
||||
return `${prefix}:${name}:${id}>`;
|
||||
}
|
||||
|
||||
export function parseEmojiValue(raw: unknown): ParsedEmoji {
|
||||
const value = String(raw ?? "").trim();
|
||||
if (!value) {
|
||||
return { kind: "empty", value: "" };
|
||||
}
|
||||
|
||||
const match = value.match(CUSTOM_EMOJI_RE);
|
||||
if (match) {
|
||||
return {
|
||||
kind: "custom",
|
||||
value,
|
||||
animated: match[1] === "a",
|
||||
name: match[2],
|
||||
id: match[3],
|
||||
};
|
||||
}
|
||||
|
||||
return { kind: "unicode", value };
|
||||
}
|
||||
|
||||
export function emojiCdnUrl(id: string, animated = false): string {
|
||||
return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}?size=64`;
|
||||
}
|
||||
|
||||
export function resolveEmojiPreview(
|
||||
value: unknown,
|
||||
guildEmojis: GuildEmojiOption[] = [],
|
||||
): ParsedEmoji {
|
||||
const parsed = parseEmojiValue(value);
|
||||
if (parsed.kind === "custom" && parsed.id && !parsed.name) {
|
||||
const found = guildEmojis.find((e) => e.id === parsed.id);
|
||||
if (found) {
|
||||
return {
|
||||
kind: "custom",
|
||||
value: formatCustomEmoji(found.name, found.id, found.animated),
|
||||
name: found.name,
|
||||
id: found.id,
|
||||
animated: found.animated,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (parsed.kind === "custom" && parsed.id) {
|
||||
const found = guildEmojis.find((e) => e.id === parsed.id);
|
||||
if (found && parsed.value !== formatCustomEmoji(found.name, found.id, found.animated)) {
|
||||
return {
|
||||
kind: "custom",
|
||||
value: formatCustomEmoji(found.name, found.id, found.animated),
|
||||
name: found.name,
|
||||
id: found.id,
|
||||
animated: found.animated,
|
||||
};
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export function isEmojiFieldKey(key: string): boolean {
|
||||
return /emoji/i.test(key);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export function formatLogTime(iso: string | null): string {
|
||||
if (!iso) return "—";
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return iso;
|
||||
return d.toLocaleTimeString(undefined, {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import type { ConfigField, ConfigSchema, FieldType } from "@/lib/config-schemas";
|
||||
|
||||
function labelFromKey(key: string): string {
|
||||
return key
|
||||
.replace(/_/g, " ")
|
||||
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
function inferFieldType(key: string, value: unknown): FieldType {
|
||||
if (typeof value === "boolean") return "boolean";
|
||||
if (typeof value === "number") return "number";
|
||||
if (Array.isArray(value)) return "stringList";
|
||||
|
||||
if (typeof value === "string") {
|
||||
const k = key.toLowerCase();
|
||||
if (/emoji/.test(k)) return "emoji";
|
||||
if (/guild.?id|guild_id/.test(k)) return "discordId";
|
||||
if (/category/.test(k)) return "discordCategory";
|
||||
if (/channel|forum/.test(k)) return "discordChannel";
|
||||
if (/role|staff|admin|moderator/.test(k)) return "discordRole";
|
||||
if (value.length > 100) return "textarea";
|
||||
return "text";
|
||||
}
|
||||
|
||||
return "text";
|
||||
}
|
||||
|
||||
export function collectConfigFields(
|
||||
obj: Record<string, unknown>,
|
||||
prefix = "",
|
||||
): ConfigField[] {
|
||||
const fields: ConfigField[] = [];
|
||||
|
||||
for (const [key, val] of Object.entries(obj)) {
|
||||
const path = prefix ? `${prefix}.${key}` : key;
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
const hasObjects =
|
||||
val.length > 0 &&
|
||||
typeof val[0] === "object" &&
|
||||
val[0] !== null &&
|
||||
!Array.isArray(val[0]);
|
||||
if (hasObjects) continue;
|
||||
fields.push({
|
||||
path,
|
||||
label: labelFromKey(key),
|
||||
type: "stringList",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
val &&
|
||||
typeof val === "object" &&
|
||||
Object.keys(val as object).length > 0
|
||||
) {
|
||||
fields.push(...collectConfigFields(val as Record<string, unknown>, path));
|
||||
continue;
|
||||
}
|
||||
|
||||
fields.push({
|
||||
path,
|
||||
label: labelFromKey(key),
|
||||
type: inferFieldType(key, val),
|
||||
});
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
export function schemaFromObject(data: Record<string, unknown>): ConfigSchema {
|
||||
const fields = collectConfigFields(data);
|
||||
if (fields.length === 0) {
|
||||
return [
|
||||
{
|
||||
title: "Configuration",
|
||||
fields: [],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
title: "Settings",
|
||||
description: "Values from this addon’s config file.",
|
||||
fields,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/** Curated Google Fonts (keep in sync with Structures/googleFonts.js). */
|
||||
|
||||
export const SYSTEM_FONT_ID = "system";
|
||||
|
||||
export const GOOGLE_FONTS = [
|
||||
{ id: "Inter", label: "Inter" },
|
||||
{ id: "Roboto", label: "Roboto" },
|
||||
{ id: "Open Sans", label: "Open Sans" },
|
||||
{ id: "Lato", label: "Lato" },
|
||||
{ id: "Montserrat", label: "Montserrat" },
|
||||
{ id: "Poppins", label: "Poppins" },
|
||||
{ id: "Nunito", label: "Nunito" },
|
||||
{ id: "Raleway", label: "Raleway" },
|
||||
{ id: "Work Sans", label: "Work Sans" },
|
||||
{ id: "Source Sans 3", label: "Source Sans 3" },
|
||||
{ id: "DM Sans", label: "DM Sans" },
|
||||
{ id: "Manrope", label: "Manrope" },
|
||||
{ id: "Outfit", label: "Outfit" },
|
||||
{ id: "Rubik", label: "Rubik" },
|
||||
{ id: "Ubuntu", label: "Ubuntu" },
|
||||
{ id: "Fira Sans", label: "Fira Sans" },
|
||||
{ id: "PT Sans", label: "PT Sans" },
|
||||
{ id: "Noto Sans", label: "Noto Sans" },
|
||||
{ id: "Oswald", label: "Oswald" },
|
||||
{ id: "Merriweather", label: "Merriweather" },
|
||||
{ id: "Playfair Display", label: "Playfair Display" },
|
||||
{ id: "Libre Baskerville", label: "Libre Baskerville" },
|
||||
{ id: "JetBrains Mono", label: "JetBrains Mono" },
|
||||
{ id: "Fira Code", label: "Fira Code" },
|
||||
] as const;
|
||||
|
||||
export const GOOGLE_FONT_IDS = new Set<string>(
|
||||
GOOGLE_FONTS.map((f) => f.id),
|
||||
);
|
||||
|
||||
export function googleFontsCssUrl(familyIds: string[]) {
|
||||
const families = familyIds
|
||||
.map((id) => {
|
||||
const encoded = encodeURIComponent(id).replace(/%20/g, "+");
|
||||
return `family=${encoded}:wght@400;600;700;800`;
|
||||
})
|
||||
.join("&");
|
||||
return `https://fonts.googleapis.com/css2?${families}&display=swap`;
|
||||
}
|
||||
|
||||
/** Load all curated fonts in the dashboard (dropdown + preview labels). */
|
||||
export function injectGoogleFontsStylesheet() {
|
||||
const id = "supportbot-google-fonts";
|
||||
if (document.getElementById(id)) return;
|
||||
const link = document.createElement("link");
|
||||
link.id = id;
|
||||
link.rel = "stylesheet";
|
||||
link.href = googleFontsCssUrl(GOOGLE_FONTS.map((f) => f.id));
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
|
||||
export function normalizeGoogleFontValue(fontFamily: unknown): string {
|
||||
if (!fontFamily || typeof fontFamily !== "string") return "Inter";
|
||||
const trimmed = fontFamily.trim();
|
||||
if (trimmed === SYSTEM_FONT_ID) return SYSTEM_FONT_ID;
|
||||
if (!trimmed.includes(",")) {
|
||||
return GOOGLE_FONT_IDS.has(trimmed) ? trimmed : "Inter";
|
||||
}
|
||||
const match = trimmed.match(/^["']?([^"',]+)["']?/);
|
||||
const first = match?.[1]?.trim();
|
||||
if (first && GOOGLE_FONT_IDS.has(first)) {
|
||||
return first;
|
||||
}
|
||||
return "Inter";
|
||||
}
|
||||
|
||||
export function fontFamilyCss(fontId: string): string {
|
||||
if (fontId === SYSTEM_FONT_ID) {
|
||||
return 'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
||||
}
|
||||
return `"${fontId}", ui-sans-serif, system-ui, sans-serif`;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { ConfigField, ConfigSchema } from "@/lib/config-schemas";
|
||||
import { collectConfigFields } from "@/lib/generic-config-schema";
|
||||
|
||||
function labelFromTopKey(key: string): string {
|
||||
return key
|
||||
.replace(/_/g, " ")
|
||||
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
/** Adds any leaf paths from `data` that are not already in `schema`. */
|
||||
export function mergeSchemaWithData(
|
||||
schema: ConfigSchema,
|
||||
data: Record<string, unknown>,
|
||||
): ConfigSchema {
|
||||
const known = new Set(schema.flatMap((s) => s.fields.map((f) => f.path)));
|
||||
const discovered = collectConfigFields(data).filter((f) => !known.has(f.path));
|
||||
|
||||
if (discovered.length === 0) return schema;
|
||||
|
||||
const byTop = new Map<string, ConfigField[]>();
|
||||
for (const field of discovered) {
|
||||
const top = field.path.split(".")[0] ?? "Other";
|
||||
const list = byTop.get(top) ?? [];
|
||||
list.push(field);
|
||||
byTop.set(top, list);
|
||||
}
|
||||
|
||||
const extraSections = [...byTop.entries()]
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([top, fields]) => ({
|
||||
title: labelFromTopKey(top),
|
||||
description:
|
||||
"These options exist in your config file but are not in the main editor sections.",
|
||||
fields: fields.sort((a, b) => a.path.localeCompare(b.path)),
|
||||
}));
|
||||
|
||||
return [...schema, ...extraSections];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { ModuleStatus } from "@/components/overview/module-strip-card";
|
||||
|
||||
export interface ModuleStatusInfo {
|
||||
status: ModuleStatus;
|
||||
subtitle: string;
|
||||
passed?: number;
|
||||
total?: number;
|
||||
}
|
||||
|
||||
export const STATUS_BADGE: Record<ModuleStatus, string> = {
|
||||
todo: "Needs setup",
|
||||
progress: "In progress",
|
||||
done: "Active",
|
||||
};
|
||||
|
||||
export function getPluginModuleMeta(
|
||||
pluginId: string,
|
||||
modules?: Record<string, ModuleStatusInfo>,
|
||||
fallbackSubtitle = "Configure module",
|
||||
): ModuleStatusInfo {
|
||||
const info = modules?.[pluginId];
|
||||
if (info) return info;
|
||||
return {
|
||||
status: "todo",
|
||||
subtitle: fallbackSubtitle,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/** Normalize user/config colour strings to #rrggbb (lowercase). */
|
||||
export function normalizeHex(value: string, fallback = "#000000"): string {
|
||||
let s = String(value ?? "").trim();
|
||||
if (!s) return fallback;
|
||||
if (!s.startsWith("#")) s = `#${s}`;
|
||||
const hex = s.slice(1);
|
||||
if (/^[0-9a-fA-F]{3}$/.test(hex)) {
|
||||
return `#${hex
|
||||
.split("")
|
||||
.map((c) => c + c)
|
||||
.join("")
|
||||
.toLowerCase()}`;
|
||||
}
|
||||
if (/^[0-9a-fA-F]{6}$/.test(hex)) {
|
||||
return `#${hex.toLowerCase()}`;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function isValidHex(value: string): boolean {
|
||||
const s = String(value ?? "").trim();
|
||||
return /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(s) || /^[0-9a-fA-F]{6}$/.test(s);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { toast } from "sonner";
|
||||
import type { ApiResponse } from "@/api/client";
|
||||
|
||||
export async function notifyConfigSave<T>(
|
||||
saveFn: () => Promise<ApiResponse<T>>,
|
||||
): Promise<ApiResponse<T>> {
|
||||
const saveToast = toast.loading("Saving changes…");
|
||||
|
||||
try {
|
||||
const res = await saveFn();
|
||||
toast.success("Changes saved", { id: saveToast });
|
||||
|
||||
if (res.botRestart) {
|
||||
const restartToast = toast.loading("Restarting bot…");
|
||||
if (res.botRestart.success) {
|
||||
toast.success("Bot started", { id: restartToast });
|
||||
} else {
|
||||
toast.error(res.botRestart.error ?? "Could not start bot", {
|
||||
id: restartToast,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : "Save failed", {
|
||||
id: saveToast,
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
export const CONFIG_FILES = [
|
||||
"supportbot",
|
||||
"ticket-panel",
|
||||
"commands",
|
||||
"messages",
|
||||
"supportbot-ai",
|
||||
] as const;
|
||||
|
||||
export type ConfigFile = (typeof CONFIG_FILES)[number];
|
||||
|
||||
export type DashboardRole =
|
||||
| "owner"
|
||||
| "admin"
|
||||
| "moderator"
|
||||
| "editor"
|
||||
| "viewer"
|
||||
| "custom";
|
||||
|
||||
export interface ConfigFilePermission {
|
||||
view: boolean;
|
||||
edit: boolean;
|
||||
}
|
||||
|
||||
export interface DashboardPermissions {
|
||||
overview: boolean;
|
||||
logs: boolean;
|
||||
transcripts: boolean;
|
||||
settings: { view: boolean; update: boolean };
|
||||
configs: Record<ConfigFile, ConfigFilePermission>;
|
||||
users: { view: boolean; manage: boolean };
|
||||
}
|
||||
|
||||
export interface DashboardUser {
|
||||
id: string;
|
||||
username: string;
|
||||
globalName: string | null;
|
||||
avatar: string;
|
||||
role: DashboardRole;
|
||||
isOwner: boolean;
|
||||
permissions: DashboardPermissions;
|
||||
}
|
||||
|
||||
export interface StoredDashboardUser extends DashboardUser {
|
||||
enabled: boolean;
|
||||
yamlOwner: boolean;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
export const ROLE_LABELS: Record<DashboardRole, string> = {
|
||||
owner: "Owner",
|
||||
admin: "Admin",
|
||||
moderator: "Moderator",
|
||||
editor: "Editor",
|
||||
viewer: "Viewer",
|
||||
custom: "Custom",
|
||||
};
|
||||
|
||||
export const ROLE_HINTS: Record<DashboardRole, string> = {
|
||||
owner: "Full access to everything",
|
||||
admin: "Full access including user management",
|
||||
moderator: "View dashboard, logs, transcripts, and configs",
|
||||
editor: "Edit configuration files",
|
||||
viewer: "View-only access",
|
||||
custom: "Permissions you configure below",
|
||||
};
|
||||
|
||||
export const CONFIG_FILE_LABELS: Record<ConfigFile, string> = {
|
||||
supportbot: "Bot config",
|
||||
"ticket-panel": "Ticket system",
|
||||
commands: "Commands",
|
||||
messages: "Messages",
|
||||
"supportbot-ai": "AI assistant",
|
||||
};
|
||||
|
||||
export function hasPermission(
|
||||
permissions: DashboardPermissions | null | undefined,
|
||||
key: string,
|
||||
): boolean {
|
||||
if (!permissions) return false;
|
||||
|
||||
if (key === "overview") return permissions.overview;
|
||||
if (key === "logs") return permissions.logs;
|
||||
if (key === "transcripts") return permissions.transcripts;
|
||||
if (key === "settings.view") return permissions.settings.view;
|
||||
if (key === "settings.update") return permissions.settings.update;
|
||||
if (key === "users.view") return permissions.users.view;
|
||||
if (key === "users.manage") return permissions.users.manage;
|
||||
|
||||
const viewMatch = key.match(/^configs\.([a-z0-9-]+)\.view$/);
|
||||
if (viewMatch) {
|
||||
const file = viewMatch[1] as ConfigFile;
|
||||
return Boolean(permissions.configs[file]?.view);
|
||||
}
|
||||
|
||||
const editMatch = key.match(/^configs\.([a-z0-9-]+)\.edit$/);
|
||||
if (editMatch) {
|
||||
const file = editMatch[1] as ConfigFile;
|
||||
return Boolean(permissions.configs[file]?.edit);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function canViewConfig(
|
||||
permissions: DashboardPermissions | null | undefined,
|
||||
file: string,
|
||||
): boolean {
|
||||
return hasPermission(permissions, `configs.${file}.view`);
|
||||
}
|
||||
|
||||
export function canEditConfig(
|
||||
permissions: DashboardPermissions | null | undefined,
|
||||
file: string,
|
||||
): boolean {
|
||||
return hasPermission(permissions, `configs.${file}.edit`);
|
||||
}
|
||||
|
||||
export function canViewAnyConfig(
|
||||
permissions: DashboardPermissions | null | undefined,
|
||||
): boolean {
|
||||
return CONFIG_FILES.some((file) => canViewConfig(permissions, file));
|
||||
}
|
||||
|
||||
function configMap(view: boolean, edit: boolean): Record<ConfigFile, ConfigFilePermission> {
|
||||
return CONFIG_FILES.reduce(
|
||||
(acc, file) => {
|
||||
acc[file] = { view, edit };
|
||||
return acc;
|
||||
},
|
||||
{} as Record<ConfigFile, ConfigFilePermission>,
|
||||
);
|
||||
}
|
||||
|
||||
export function fullPermissions(): DashboardPermissions {
|
||||
return {
|
||||
overview: true,
|
||||
logs: true,
|
||||
transcripts: true,
|
||||
settings: { view: true, update: true },
|
||||
configs: configMap(true, true),
|
||||
users: { view: true, manage: true },
|
||||
};
|
||||
}
|
||||
|
||||
export function defaultPermissionsForRole(
|
||||
role: DashboardRole,
|
||||
custom?: DashboardPermissions,
|
||||
): DashboardPermissions {
|
||||
switch (role) {
|
||||
case "owner":
|
||||
case "admin":
|
||||
return fullPermissions();
|
||||
case "moderator":
|
||||
return {
|
||||
overview: true,
|
||||
logs: true,
|
||||
transcripts: true,
|
||||
settings: { view: true, update: false },
|
||||
configs: configMap(true, false),
|
||||
users: { view: false, manage: false },
|
||||
};
|
||||
case "editor":
|
||||
return {
|
||||
overview: true,
|
||||
logs: true,
|
||||
transcripts: false,
|
||||
settings: { view: true, update: false },
|
||||
configs: configMap(true, true),
|
||||
users: { view: false, manage: false },
|
||||
};
|
||||
case "viewer":
|
||||
return {
|
||||
overview: true,
|
||||
logs: true,
|
||||
transcripts: true,
|
||||
settings: { view: true, update: false },
|
||||
configs: configMap(true, false),
|
||||
users: { view: false, manage: false },
|
||||
};
|
||||
case "custom":
|
||||
return custom ?? defaultPermissionsForRole("viewer");
|
||||
default:
|
||||
return defaultPermissionsForRole("viewer");
|
||||
}
|
||||
}
|
||||
|
||||
export function displayDiscordName(
|
||||
user: Pick<DashboardUser, "username" | "globalName">,
|
||||
): string {
|
||||
return user.globalName || user.username;
|
||||
}
|
||||
|
||||
export function firstAllowedPath(
|
||||
permissions: DashboardPermissions | null | undefined,
|
||||
): string {
|
||||
if (hasPermission(permissions, "overview")) return "/";
|
||||
if (hasPermission(permissions, "logs")) return "/logs";
|
||||
if (canViewAnyConfig(permissions)) return "/configs?file=supportbot";
|
||||
if (hasPermission(permissions, "transcripts")) return "/transcripts";
|
||||
if (hasPermission(permissions, "settings.view")) return "/settings";
|
||||
if (hasPermission(permissions, "users.view")) return "/users";
|
||||
return "/login";
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import type { IconSvgElement } from "@hugeicons/react";
|
||||
import {
|
||||
AiBrain01Icon,
|
||||
CommandIcon,
|
||||
File02Icon,
|
||||
Message01Icon,
|
||||
Settings02Icon,
|
||||
Ticket01Icon,
|
||||
} from "@hugeicons/core-free-icons";
|
||||
|
||||
export type PluginCategory =
|
||||
| "all"
|
||||
| "tickets"
|
||||
| "community"
|
||||
| "server";
|
||||
|
||||
export interface PluginModule {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
icon: IconSvgElement;
|
||||
href: string;
|
||||
category: PluginCategory;
|
||||
}
|
||||
|
||||
export const plugins: PluginModule[] = [
|
||||
{
|
||||
id: "tickets",
|
||||
title: "Ticket system",
|
||||
description:
|
||||
"Create and manage support tickets with departments, priorities, and AI assistance.",
|
||||
icon: Ticket01Icon,
|
||||
href: "/configs?file=ticket-panel",
|
||||
category: "tickets",
|
||||
},
|
||||
{
|
||||
id: "supportbot",
|
||||
title: "Core bot settings",
|
||||
description:
|
||||
"General bot options, activity status, embed colours, roles, and welcome messages.",
|
||||
icon: Settings02Icon,
|
||||
href: "/configs?file=supportbot",
|
||||
category: "server",
|
||||
},
|
||||
{
|
||||
id: "transcripts",
|
||||
title: "Ticket transcripts",
|
||||
description:
|
||||
"Browse and preview HTML transcripts saved when tickets are closed.",
|
||||
icon: File02Icon,
|
||||
href: "/transcripts",
|
||||
category: "tickets",
|
||||
},
|
||||
{
|
||||
id: "suggestions",
|
||||
title: "Suggestions",
|
||||
description:
|
||||
"Configure suggestion channels, voting emojis, and forum thread behaviour.",
|
||||
icon: Message01Icon,
|
||||
href: "/configs?file=messages",
|
||||
category: "community",
|
||||
},
|
||||
{
|
||||
id: "ai",
|
||||
title: "AI assistant",
|
||||
description:
|
||||
"SupportBot AI mode settings for in-ticket conversational help.",
|
||||
icon: AiBrain01Icon,
|
||||
href: "/configs?file=supportbot-ai",
|
||||
category: "community",
|
||||
},
|
||||
{
|
||||
id: "commands",
|
||||
title: "Commands",
|
||||
description:
|
||||
"Enable or disable slash commands and customise command permissions.",
|
||||
icon: CommandIcon,
|
||||
href: "/configs?file=commands",
|
||||
category: "server",
|
||||
},
|
||||
];
|
||||
|
||||
export const pluginTabs: { id: PluginCategory | "all"; label: string }[] = [
|
||||
{ id: "all", label: "All modules" },
|
||||
{ id: "tickets", label: "Tickets" },
|
||||
{ id: "community", label: "Community" },
|
||||
{ id: "server", label: "Server" },
|
||||
];
|
||||
@@ -0,0 +1,254 @@
|
||||
import type { IconSvgElement } from "@hugeicons/react";
|
||||
import {
|
||||
AiBrain01Icon,
|
||||
CommandIcon,
|
||||
ComputerTerminal01Icon,
|
||||
DashboardSquare02Icon,
|
||||
File02Icon,
|
||||
Message01Icon,
|
||||
Settings02Icon,
|
||||
Ticket01Icon,
|
||||
} from "@hugeicons/core-free-icons";
|
||||
import {
|
||||
configSchemas,
|
||||
type ConfigFileName,
|
||||
type ConfigSchema,
|
||||
} from "@/lib/config-schemas";
|
||||
import { plugins } from "@/lib/plugins";
|
||||
|
||||
export type SearchCategory = "page" | "module" | "setting" | "command";
|
||||
|
||||
export interface SearchItem {
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
href: string;
|
||||
category: SearchCategory;
|
||||
icon?: IconSvgElement;
|
||||
keywords: string[];
|
||||
}
|
||||
|
||||
const FILE_LABELS: Record<ConfigFileName, string> = {
|
||||
supportbot: "Bot config",
|
||||
"ticket-panel": "Ticket panel",
|
||||
commands: "Commands",
|
||||
messages: "Messages",
|
||||
"supportbot-ai": "AI assistant",
|
||||
};
|
||||
|
||||
const COMMAND_ENTRIES: {
|
||||
key: string;
|
||||
label: string;
|
||||
description: string;
|
||||
}[] = [
|
||||
{ key: "Help", label: "Help", description: "List all slash commands" },
|
||||
{ key: "Info", label: "Info", description: "Server information" },
|
||||
{ key: "TicketPanel", label: "Ticket panel", description: "Create ticket panel" },
|
||||
{ key: "OpenTicket", label: "Open ticket", description: "Open a support ticket" },
|
||||
{ key: "CloseTicket", label: "Close ticket", description: "Close a ticket" },
|
||||
{ key: "TicketManage", label: "Manage ticket", description: "Manage an existing ticket" },
|
||||
{ key: "Suggestion", label: "Suggestion", description: "Submit a suggestion" },
|
||||
{ key: "Embed", label: "Embed", description: "Send an embed message" },
|
||||
{ key: "Translate", label: "Translate", description: "Translate text" },
|
||||
{ key: "Ping", label: "Ping", description: "Check bot latency" },
|
||||
{ key: "AI", label: "AI", description: "AI assistant command" },
|
||||
{ key: "Settings", label: "Settings command", description: "Bot settings via Discord" },
|
||||
{ key: "Mod", label: "Moderation", description: "Moderation tools" },
|
||||
];
|
||||
|
||||
function walkSchema(
|
||||
file: ConfigFileName,
|
||||
schema: ConfigSchema,
|
||||
items: SearchItem[],
|
||||
) {
|
||||
const fileLabel = FILE_LABELS[file];
|
||||
for (const section of schema) {
|
||||
for (const field of section.fields) {
|
||||
items.push({
|
||||
id: `setting:${file}:${field.path}`,
|
||||
title: field.label,
|
||||
subtitle: `${fileLabel} · ${section.title}`,
|
||||
href: `/configs?file=${file}`,
|
||||
category: "setting",
|
||||
icon: iconForFile(file),
|
||||
keywords: [
|
||||
field.path,
|
||||
field.label,
|
||||
section.title,
|
||||
fileLabel,
|
||||
file,
|
||||
field.description ?? "",
|
||||
field.type,
|
||||
].map((s) => s.toLowerCase()),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function iconForFile(file: ConfigFileName): IconSvgElement {
|
||||
switch (file) {
|
||||
case "supportbot":
|
||||
return Settings02Icon;
|
||||
case "ticket-panel":
|
||||
return Ticket01Icon;
|
||||
case "messages":
|
||||
return Message01Icon;
|
||||
case "supportbot-ai":
|
||||
return AiBrain01Icon;
|
||||
case "commands":
|
||||
return CommandIcon;
|
||||
default:
|
||||
return Settings02Icon;
|
||||
}
|
||||
}
|
||||
|
||||
function buildSearchIndex(): SearchItem[] {
|
||||
const items: SearchItem[] = [
|
||||
{
|
||||
id: "page:dashboard",
|
||||
title: "Dashboard",
|
||||
subtitle: "Overview and module status",
|
||||
href: "/",
|
||||
category: "page",
|
||||
icon: DashboardSquare02Icon,
|
||||
keywords: ["home", "overview", "stats"],
|
||||
},
|
||||
{
|
||||
id: "page:logs",
|
||||
title: "Logs",
|
||||
subtitle: "Live bot console output",
|
||||
href: "/logs",
|
||||
category: "page",
|
||||
icon: ComputerTerminal01Icon,
|
||||
keywords: ["console", "output", "errors", "warn"],
|
||||
},
|
||||
{
|
||||
id: "page:settings",
|
||||
title: "Settings",
|
||||
subtitle: "Updates and maintenance",
|
||||
href: "/settings",
|
||||
category: "page",
|
||||
icon: Settings02Icon,
|
||||
keywords: ["update", "version", "software"],
|
||||
},
|
||||
{
|
||||
id: "page:transcripts",
|
||||
title: "Transcripts",
|
||||
subtitle: "Closed ticket transcripts",
|
||||
href: "/transcripts",
|
||||
category: "page",
|
||||
icon: File02Icon,
|
||||
keywords: ["tickets", "archive", "html"],
|
||||
},
|
||||
];
|
||||
|
||||
for (const plugin of plugins) {
|
||||
items.push({
|
||||
id: `module:${plugin.id}`,
|
||||
title: plugin.title,
|
||||
subtitle: plugin.description,
|
||||
href: plugin.href,
|
||||
category: "module",
|
||||
icon: plugin.icon,
|
||||
keywords: [
|
||||
plugin.id,
|
||||
plugin.title,
|
||||
plugin.description,
|
||||
plugin.category,
|
||||
].map((s) => s.toLowerCase()),
|
||||
});
|
||||
}
|
||||
|
||||
for (const [file, schema] of Object.entries(configSchemas)) {
|
||||
if (schema === "commands") continue;
|
||||
walkSchema(file as ConfigFileName, schema, items);
|
||||
}
|
||||
|
||||
for (const cmd of COMMAND_ENTRIES) {
|
||||
items.push({
|
||||
id: `command:${cmd.key}`,
|
||||
title: cmd.label,
|
||||
subtitle: `Command · ${cmd.description}`,
|
||||
href: "/configs?file=commands",
|
||||
category: "command",
|
||||
icon: CommandIcon,
|
||||
keywords: [
|
||||
cmd.key,
|
||||
cmd.label,
|
||||
cmd.description,
|
||||
"slash",
|
||||
"commands",
|
||||
].map((s) => s.toLowerCase()),
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
id: "setting:commands:all",
|
||||
title: "Slash commands",
|
||||
subtitle: "Commands · Enable and configure all commands",
|
||||
href: "/configs?file=commands",
|
||||
category: "setting",
|
||||
icon: CommandIcon,
|
||||
keywords: ["commands", "slash", "enable", "permissions"],
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
export const SEARCH_INDEX = buildSearchIndex();
|
||||
|
||||
const CATEGORY_LABEL: Record<SearchCategory, string> = {
|
||||
page: "Pages",
|
||||
module: "Modules",
|
||||
setting: "Settings",
|
||||
command: "Commands",
|
||||
};
|
||||
|
||||
export function searchDashboard(query: string, limit = 12): SearchItem[] {
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return [];
|
||||
|
||||
const scored = SEARCH_INDEX.map((item) => {
|
||||
let score = 0;
|
||||
const title = item.title.toLowerCase();
|
||||
const subtitle = (item.subtitle ?? "").toLowerCase();
|
||||
|
||||
if (title === q) score += 100;
|
||||
else if (title.startsWith(q)) score += 40;
|
||||
else if (title.includes(q)) score += 20;
|
||||
|
||||
if (subtitle.includes(q)) score += 10;
|
||||
|
||||
for (const kw of item.keywords) {
|
||||
if (kw === q) score += 15;
|
||||
else if (kw.startsWith(q)) score += 8;
|
||||
else if (kw.includes(q)) score += 4;
|
||||
}
|
||||
|
||||
return { item, score };
|
||||
})
|
||||
.filter((r) => r.score > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.slice(0, limit);
|
||||
|
||||
return scored.map((r) => r.item);
|
||||
}
|
||||
|
||||
export function groupSearchResults(items: SearchItem[]) {
|
||||
const groups: { category: SearchCategory; label: string; items: SearchItem[] }[] =
|
||||
[];
|
||||
const order: SearchCategory[] = ["page", "module", "setting", "command"];
|
||||
|
||||
for (const cat of order) {
|
||||
const inCat = items.filter((i) => i.category === cat);
|
||||
if (inCat.length) {
|
||||
groups.push({
|
||||
category: cat,
|
||||
label: CATEGORY_LABEL[cat],
|
||||
items: inCat,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
export interface SetupStep {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
complete: boolean;
|
||||
}
|
||||
|
||||
export interface SetupStatus {
|
||||
complete: boolean;
|
||||
steps: SetupStep[];
|
||||
suggestedRedirectUri: string;
|
||||
oauthCallbackPath: string;
|
||||
}
|
||||
|
||||
export interface FieldValidationResult {
|
||||
ok: boolean;
|
||||
error?: string;
|
||||
warning?: string;
|
||||
bot?: { id: string; username: string };
|
||||
applicationId?: string;
|
||||
users?: { id: string; username: string; globalName: string | null }[];
|
||||
redirectUri?: string;
|
||||
ownerUserIds?: string[];
|
||||
}
|
||||
|
||||
export interface SetupValidateResponse {
|
||||
ok: boolean;
|
||||
results: Record<string, FieldValidationResult>;
|
||||
}
|
||||
|
||||
export interface SetupFormValues {
|
||||
botToken: string;
|
||||
secretKey: string;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
redirectUri: string;
|
||||
ownerUserIds: string;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import type { ConfigSchema } from "@/lib/config-schemas";
|
||||
|
||||
export const transcriptTemplateSchema: ConfigSchema = [
|
||||
{
|
||||
title: "Colors",
|
||||
description: "Theme colors used across the transcript page.",
|
||||
fields: [
|
||||
{ path: "Theme.Background", label: "Page background", type: "color" },
|
||||
{ path: "Theme.Panel", label: "Panel background", type: "color" },
|
||||
{ path: "Theme.PanelSecondary", label: "Secondary panel", type: "color" },
|
||||
{ path: "Theme.Border", label: "Borders", type: "color" },
|
||||
{ path: "Theme.Text", label: "Main text", type: "color" },
|
||||
{ path: "Theme.Muted", label: "Muted text", type: "color" },
|
||||
{ path: "Theme.Accent", label: "Accent", type: "color" },
|
||||
{ path: "Theme.Link", label: "Links", type: "color" },
|
||||
{ path: "Theme.AttachmentLink", label: "Attachment links", type: "color" },
|
||||
{ path: "Theme.CodeBackground", label: "Code blocks", type: "color" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Typography",
|
||||
fields: [
|
||||
{
|
||||
path: "Typography.FontFamily",
|
||||
label: "Font family",
|
||||
type: "googleFont",
|
||||
description: "Google Fonts are loaded automatically in saved transcripts.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Header",
|
||||
fields: [
|
||||
{ path: "Header.Title", label: "Title", type: "text" },
|
||||
{
|
||||
path: "Header.Subtitle",
|
||||
label: "Subtitle",
|
||||
type: "textarea",
|
||||
description:
|
||||
"Placeholders: {{ticketName}} {{ticketId}} {{messageCount}} {{reason}}. Use **text** for bold.",
|
||||
},
|
||||
{ path: "Header.Badge", label: "Badge label", type: "text" },
|
||||
{
|
||||
path: "Header.ShowMetaCards",
|
||||
label: "Show info cards",
|
||||
type: "boolean",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Info card labels",
|
||||
fields: [
|
||||
{ path: "Meta.ChannelLabel", label: "Channel label", type: "text" },
|
||||
{ path: "Meta.TicketIdLabel", label: "Ticket ID label", type: "text" },
|
||||
{
|
||||
path: "Meta.MessageCountLabel",
|
||||
label: "Message count label",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Meta.CloseReasonLabel",
|
||||
label: "Close reason label",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Meta.DefaultCloseReason",
|
||||
label: "Default close reason",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Messages section",
|
||||
fields: [
|
||||
{
|
||||
path: "Messages.SectionTitle",
|
||||
label: "Section heading",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
path: "Messages.EmptyState",
|
||||
label: "Empty state text",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Advanced CSS",
|
||||
description: "Optional extra CSS appended to the transcript stylesheet.",
|
||||
fields: [
|
||||
{
|
||||
path: "Advanced.CustomCss",
|
||||
label: "Custom CSS",
|
||||
type: "textarea",
|
||||
description: "Example: .badge { font-size: 1rem; }",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,41 @@
|
||||
export interface TranscriptTemplate {
|
||||
Theme: {
|
||||
Background: string;
|
||||
Panel: string;
|
||||
PanelSecondary: string;
|
||||
PanelTertiary: string;
|
||||
Border: string;
|
||||
Text: string;
|
||||
Muted: string;
|
||||
Accent: string;
|
||||
AccentSoft: string;
|
||||
AccentBorder: string;
|
||||
AccentText: string;
|
||||
Link: string;
|
||||
AttachmentLink: string;
|
||||
CodeBackground: string;
|
||||
};
|
||||
Typography: {
|
||||
FontFamily: string;
|
||||
};
|
||||
Header: {
|
||||
Title: string;
|
||||
Subtitle: string;
|
||||
Badge: string;
|
||||
ShowMetaCards: boolean;
|
||||
};
|
||||
Meta: {
|
||||
ChannelLabel: string;
|
||||
TicketIdLabel: string;
|
||||
MessageCountLabel: string;
|
||||
CloseReasonLabel: string;
|
||||
DefaultCloseReason: string;
|
||||
};
|
||||
Messages: {
|
||||
SectionTitle: string;
|
||||
EmptyState: string;
|
||||
};
|
||||
Advanced: {
|
||||
CustomCss: string;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
Reference in new issue
Block a user