diff --git a/src/App.svelte b/src/App.svelte index 1f4d618..b51a9a0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -165,6 +165,7 @@ let commandFormErrorResponse = ''; let commandFormEnabled = true; let commandFormBusy = false; + let commandVariableSuggestions: string[] = []; let botSecrets: Array<{ id: string; name: string; description: string; used_by: string[] }> = []; let secretName = ''; let secretDescription = ''; @@ -794,9 +795,23 @@ commandFormCooldownScope = 'global'; commandFormResponse = ''; commandFormErrorResponse = ''; + commandVariableSuggestions = []; commandFormEnabled = true; } + const commandVariables = ['user_id', 'user_name', 'message', 'args', ...Array.from({ length: 16 }, (_, index) => `arg_${index + 1}`)]; + + function updateCommandVariableSuggestions(value: string) { + const match = value.match(/\$\{([A-Za-z0-9_]*)$/); + commandVariableSuggestions = match ? commandVariables.filter((variable) => variable.startsWith(match[1])) : []; + } + + function insertCommandVariable(variable: string) { + const match = commandFormResponse.match(/\$\{[A-Za-z0-9_]*$/); + commandFormResponse = match ? `${commandFormResponse.slice(0, -match[0].length)}\${${variable}} ` : `${commandFormResponse}\${${variable}} `; + commandVariableSuggestions = []; + } + function editCommand(command: (typeof botCommands)[number]) { commandFormId = command.id; commandFormName = command.name; @@ -1195,7 +1210,7 @@ {:else if activeView === 'Bot'} -
{commandFormId ? 'EDIT COMMAND' : 'NEW COMMAND'}
+
{commandFormId ? 'EDIT COMMAND' : 'NEW COMMAND'}
{#if commandVariableSuggestions.length}
{#each commandVariableSuggestions as variable}{/each}
{/if}
BOT COMMANDS
PUBLIC COMMAND CATALOG
{#if botCommandError}
{botCommandError}
{:else if botCommands.length}
{#each botCommands as command}
!{command.name}{command.description}{#if command.tags.length}
{command.tags.join(' · ')}
{/if}
{command.permission_level.toUpperCase()}{#if command.cooldown_seconds}{command.cooldown_seconds}s / {command.cooldown_scope}{/if}
{/each}
{:else}
No enabled commandsCreate commands on the server to make them available here.
{/if}
SECRETS MANAGEMENT
Values are encrypted and cannot be read after saving.
{#if botSecrets.length}
{#each botSecrets as secret}
{secret.name}{secret.description || 'No description'}{#if secret.used_by.length}
USED BY: {secret.used_by.join(', ')}
{/if}
{/each}
{:else}
There are no secrets yet.
{/if}{#if secretError}
{secretError}
{/if}
COMMAND MANAGEMENT
{#each botCommands as command}
!{command.name}{command.enabled ? 'ENABLED' : 'DISABLED'} · {command.permission_level.toUpperCase()}
{/each}{#if !botCommands.length}
No commands are configured yet.
{/if}
{:else if activeView === 'Collaboration'} diff --git a/src/styles.css b/src/styles.css index bb42a5c..79a3181 100644 --- a/src/styles.css +++ b/src/styles.css @@ -998,6 +998,17 @@ label { .collaboration-subheading { margin-top: 18px; } +.command-variable-picker { + display: flex; + flex-wrap: wrap; + gap: 4px; + padding: 6px; + border: 1px solid var(--ui-line-focus); + background: var(--ui-surface-hi); +} +.command-variable-picker .secondary-action { + font-family: var(--font-mono); +} .collaboration-state-panel .danger { margin-top: auto; }