feat: Add BetterChat + TimedExecute plugin config modules
All checks were successful
Test Asgard Runner / test (push) Successful in 2s

- DB migrations 017 (betterchat_configs) and 020 (timedexecute_configs) applied
- TypeORM entities matching production schema exactly
- NestJS modules with full CRUD + apply-to-server + import-from-server
- Pinia stores following teleport config pattern
- BetterChatView: Chat Groups editor with color pickers, font sizes, format strings; Settings tab with word filter, anti-flood, player tagging
- TimedExecuteView: TimerRepeat with presets, RealTime-Timer, OnConnect/OnDisconnect command lists
- Wired into app.module.ts, router, DashboardLayout nav

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell
2026-02-22 02:19:29 -05:00
parent 39622de8dc
commit bb381569e3
21 changed files with 2492 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useApi } from '@/composables/useApi'
import { useToastStore } from '@/stores/toast'
import type { BetterChatConfigSummary, BetterChatConfigFull, BetterChatApplyResult } from '@/types'
export const useBetterChatStore = defineStore('betterchat', () => {
const configs = ref<BetterChatConfigSummary[]>([])
const currentConfig = ref<BetterChatConfigFull | null>(null)
const isLoading = ref(false)
const isSaving = ref(false)
const isApplying = ref(false)
const isDirty = ref(false)
const api = useApi()
const toast = useToastStore()
async function fetchConfigs() {
isLoading.value = true
try {
const res = await api.get<{ configs: BetterChatConfigSummary[] }>('/betterchat/configs')
configs.value = res.configs
} catch (err) {
toast.error((err as Error).message)
} finally {
isLoading.value = false
}
}
async function loadConfig(id: string) {
isLoading.value = true
try {
const res = await api.get<{ config: BetterChatConfigFull }>(`/betterchat/configs/${id}`)
currentConfig.value = res.config
isDirty.value = false
} catch (err) {
toast.error((err as Error).message)
} finally {
isLoading.value = false
}
}
async function createConfig(name: string, description?: string) {
try {
const res = await api.post<{ config: BetterChatConfigFull }>('/betterchat/configs', {
config_name: name,
description,
})
await fetchConfigs()
currentConfig.value = res.config
isDirty.value = false
toast.success(`Config "${name}" created`)
return res.config
} catch (err) {
toast.error((err as Error).message)
return null
}
}
async function saveCurrentConfig() {
if (!currentConfig.value) return
isSaving.value = true
try {
await api.put(`/betterchat/configs/${currentConfig.value.id}`, {
config_name: currentConfig.value.config_name,
description: currentConfig.value.description,
config_data: currentConfig.value.config_data,
})
isDirty.value = false
await fetchConfigs()
toast.success('Config saved')
} catch (err) {
toast.error((err as Error).message)
} finally {
isSaving.value = false
}
}
async function deleteConfig(id: string) {
try {
await api.del(`/betterchat/configs/${id}`)
if (currentConfig.value?.id === id) {
currentConfig.value = null
}
await fetchConfigs()
toast.success('Config deleted')
} catch (err) {
toast.error((err as Error).message)
}
}
async function applyToServer(id: string) {
isApplying.value = true
try {
const res = await api.post<BetterChatApplyResult>(`/betterchat/configs/${id}/apply`)
await fetchConfigs()
toast.success(res.message)
return res
} catch (err) {
toast.error((err as Error).message)
return null
} finally {
isApplying.value = false
}
}
async function importFromServer(configName: string) {
isLoading.value = true
try {
const res = await api.post<{ config: BetterChatConfigFull }>('/betterchat/import-from-server', {
config_name: configName,
})
await fetchConfigs()
currentConfig.value = res.config
isDirty.value = false
toast.success(`Config imported from server as "${configName}"`)
return res.config
} catch (err) {
toast.error((err as Error).message)
return null
} finally {
isLoading.value = false
}
}
function markDirty() {
isDirty.value = true
}
return {
configs,
currentConfig,
isLoading,
isSaving,
isApplying,
isDirty,
fetchConfigs,
loadConfig,
createConfig,
saveCurrentConfig,
deleteConfig,
applyToServer,
importFromServer,
markDirty,
}
})

View File

@@ -0,0 +1,145 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useApi } from '@/composables/useApi'
import { useToastStore } from '@/stores/toast'
import type { TimedExecuteConfigSummary, TimedExecuteConfigFull, TimedExecuteApplyResult } from '@/types'
export const useTimedExecuteStore = defineStore('timedexecute', () => {
const configs = ref<TimedExecuteConfigSummary[]>([])
const currentConfig = ref<TimedExecuteConfigFull | null>(null)
const isLoading = ref(false)
const isSaving = ref(false)
const isApplying = ref(false)
const isDirty = ref(false)
const api = useApi()
const toast = useToastStore()
async function fetchConfigs() {
isLoading.value = true
try {
const res = await api.get<{ configs: TimedExecuteConfigSummary[] }>('/timedexecute/configs')
configs.value = res.configs
} catch (err) {
toast.error((err as Error).message)
} finally {
isLoading.value = false
}
}
async function loadConfig(id: string) {
isLoading.value = true
try {
const res = await api.get<{ config: TimedExecuteConfigFull }>(`/timedexecute/configs/${id}`)
currentConfig.value = res.config
isDirty.value = false
} catch (err) {
toast.error((err as Error).message)
} finally {
isLoading.value = false
}
}
async function createConfig(name: string, description?: string) {
try {
const res = await api.post<{ config: TimedExecuteConfigFull }>('/timedexecute/configs', {
config_name: name,
description,
})
await fetchConfigs()
currentConfig.value = res.config
isDirty.value = false
toast.success(`Config "${name}" created`)
return res.config
} catch (err) {
toast.error((err as Error).message)
return null
}
}
async function saveCurrentConfig() {
if (!currentConfig.value) return
isSaving.value = true
try {
await api.put(`/timedexecute/configs/${currentConfig.value.id}`, {
config_name: currentConfig.value.config_name,
description: currentConfig.value.description,
config_data: currentConfig.value.config_data,
})
isDirty.value = false
await fetchConfigs()
toast.success('Config saved')
} catch (err) {
toast.error((err as Error).message)
} finally {
isSaving.value = false
}
}
async function deleteConfig(id: string) {
try {
await api.del(`/timedexecute/configs/${id}`)
if (currentConfig.value?.id === id) {
currentConfig.value = null
}
await fetchConfigs()
toast.success('Config deleted')
} catch (err) {
toast.error((err as Error).message)
}
}
async function applyToServer(id: string) {
isApplying.value = true
try {
const res = await api.post<TimedExecuteApplyResult>(`/timedexecute/configs/${id}/apply`)
await fetchConfigs()
toast.success(res.message)
return res
} catch (err) {
toast.error((err as Error).message)
return null
} finally {
isApplying.value = false
}
}
async function importFromServer(configName: string) {
isLoading.value = true
try {
const res = await api.post<{ config: TimedExecuteConfigFull }>('/timedexecute/import-from-server', {
config_name: configName,
})
await fetchConfigs()
currentConfig.value = res.config
isDirty.value = false
toast.success(`Config imported from server as "${configName}"`)
return res.config
} catch (err) {
toast.error((err as Error).message)
return null
} finally {
isLoading.value = false
}
}
function markDirty() {
isDirty.value = true
}
return {
configs,
currentConfig,
isLoading,
isSaving,
isApplying,
isDirty,
fetchConfigs,
loadConfig,
createConfig,
saveCurrentConfig,
deleteConfig,
applyToServer,
importFromServer,
markDirty,
}
})

View File

@@ -0,0 +1,790 @@
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { useBetterChatStore } from '@/stores/betterchat'
import {
Save,
Play,
Download,
Plus,
Trash2,
MessageSquare,
Settings as SettingsIcon,
Edit,
X,
} from 'lucide-vue-next'
const store = useBetterChatStore()
const activeTab = ref<'groups' | 'settings'>('groups')
const showCreateModal = ref(false)
const showImportModal = ref(false)
const showGroupModal = ref(false)
const newConfigName = ref('')
const newConfigDesc = ref('')
const importConfigName = ref('')
const editingGroupIndex = ref<number | null>(null)
const tabs = [
{ key: 'groups', label: 'Chat Groups', icon: MessageSquare },
{ key: 'settings', label: 'Settings', icon: SettingsIcon },
]
// Default group template matching BetterChat actual format
const defaultGroup = {
GroupName: 'newgroup',
Priority: 0,
Title: {
Text: '[Player]',
Color: '#55aaff',
Size: 15,
Hidden: false,
HiddenIfNotPrimary: false,
},
Username: {
Color: '#55aaff',
Size: 15,
},
Message: {
Color: '#ffffff',
Size: 15,
},
Format: {
Chat: '{Title} {Username}: {Message}',
Console: '{Title} {Username}: {Message}',
},
}
// Editing group state
const editGroup = ref<Record<string, any>>({ ...JSON.parse(JSON.stringify(defaultGroup)) })
onMounted(async () => {
await store.fetchConfigs()
if (store.configs.length > 0 && store.configs[0]) {
await store.loadConfig(store.configs[0].id)
}
})
// --- Config data helpers ---
function getConfigValue(path: string, defaultValue: any = false): any {
if (!store.currentConfig?.config_data) return defaultValue
const parts = path.split('.')
let current: any = store.currentConfig.config_data
for (const part of parts) {
if (current == null || typeof current !== 'object') return defaultValue
current = current[part]
}
return current ?? defaultValue
}
function setConfigValue(path: string, value: any) {
if (!store.currentConfig) return
if (!store.currentConfig.config_data) store.currentConfig.config_data = {}
const parts = path.split('.')
let current: any = store.currentConfig.config_data
for (let i = 0; i < parts.length - 1; i++) {
const part = parts[i]!
if (current[part] == null || typeof current[part] !== 'object') {
current[part] = {}
}
current = current[part]
}
current[parts[parts.length - 1]!] = value
store.markDirty()
}
// --- Chat Groups helpers ---
const chatGroups = computed<Record<string, any>[]>(() => {
if (!store.currentConfig?.config_data) return []
// BetterChat stores groups in oxide/data, but config has a ChatGroup array
// The actual config format uses a top-level array for groups in the data file
// We support both: config_data as array or config_data.ChatGroups as array
if (Array.isArray(store.currentConfig.config_data)) {
return store.currentConfig.config_data
}
return getConfigValue('ChatGroups', []) as Record<string, any>[]
})
function addGroup() {
editingGroupIndex.value = null
editGroup.value = JSON.parse(JSON.stringify(defaultGroup))
showGroupModal.value = true
}
function editGroupAt(index: number) {
editingGroupIndex.value = index
editGroup.value = JSON.parse(JSON.stringify(chatGroups.value[index]))
showGroupModal.value = true
}
function saveGroup() {
if (!store.currentConfig) return
if (!store.currentConfig.config_data) store.currentConfig.config_data = {}
const groups = [...chatGroups.value]
if (editingGroupIndex.value !== null) {
groups[editingGroupIndex.value] = JSON.parse(JSON.stringify(editGroup.value))
} else {
groups.push(JSON.parse(JSON.stringify(editGroup.value)))
}
if (Array.isArray(store.currentConfig.config_data)) {
store.currentConfig.config_data = groups as any
} else {
store.currentConfig.config_data.ChatGroups = groups
}
store.markDirty()
showGroupModal.value = false
}
function deleteGroup(index: number) {
if (!store.currentConfig) return
if (!confirm('Remove this chat group?')) return
const groups = [...chatGroups.value]
groups.splice(index, 1)
if (Array.isArray(store.currentConfig.config_data)) {
store.currentConfig.config_data = groups as any
} else {
store.currentConfig.config_data.ChatGroups = groups
}
store.markDirty()
}
// --- Action handlers ---
async function handleConfigChange(id: string) {
if (store.isDirty) {
if (!confirm('Unsaved changes will be lost. Continue?')) return
}
await store.loadConfig(id)
}
async function handleCreateConfig() {
if (!newConfigName.value.trim()) return
const config = await store.createConfig(
newConfigName.value.trim(),
newConfigDesc.value.trim() || undefined,
)
if (config) {
showCreateModal.value = false
newConfigName.value = ''
newConfigDesc.value = ''
}
}
async function handleDeleteConfig() {
if (!store.currentConfig) return
if (!confirm(`Delete "${store.currentConfig.config_name}"? This cannot be undone.`)) return
await store.deleteConfig(store.currentConfig.id)
}
async function handleApply() {
if (!store.currentConfig) return
if (!confirm('Apply this BetterChat config to the server? This will overwrite the current config.')) return
if (store.isDirty) {
await store.saveCurrentConfig()
}
await store.applyToServer(store.currentConfig.id)
}
async function handleImport() {
if (!importConfigName.value.trim()) return
const config = await store.importFromServer(importConfigName.value.trim())
if (config) {
showImportModal.value = false
importConfigName.value = ''
}
}
</script>
<template>
<div class="p-6 space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<h1 class="text-2xl font-bold text-white">Better Chat</h1>
<div class="flex items-center gap-3">
<button
@click="showCreateModal = true"
class="flex items-center gap-2 px-3 py-2 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
New Config
</button>
</div>
</div>
<!-- Config Selector + Action Bar -->
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-4">
<div class="flex items-center gap-3 flex-wrap">
<!-- Config Selector -->
<select
v-if="store.configs.length > 0"
:value="store.currentConfig?.id || ''"
@change="handleConfigChange(($event.target as HTMLSelectElement).value)"
class="bg-neutral-800 border border-neutral-700 text-neutral-200 rounded-lg px-3 py-2 text-sm min-w-[200px]"
>
<option v-for="c in store.configs" :key="c.id" :value="c.id">
{{ c.config_name }}
<template v-if="c.is_active"> (Active)</template>
</option>
</select>
<span v-else class="text-neutral-500 text-sm">No configs yet</span>
<!-- Save -->
<button
@click="store.saveCurrentConfig()"
:disabled="!store.currentConfig || !store.isDirty || store.isSaving"
class="flex items-center gap-2 px-3 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
>
<Save class="w-4 h-4" />
{{ store.isSaving ? 'Saving...' : 'Save' }}
</button>
<!-- Apply to Server -->
<button
@click="handleApply"
:disabled="!store.currentConfig || store.isApplying"
class="flex items-center gap-2 px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
>
<Play class="w-4 h-4" />
{{ store.isApplying ? 'Applying...' : 'Apply to Server' }}
</button>
<!-- Import from Server -->
<button
@click="showImportModal = true"
class="flex items-center gap-2 px-3 py-2 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Download class="w-4 h-4" />
Import from Server
</button>
<!-- Delete -->
<button
@click="handleDeleteConfig"
:disabled="!store.currentConfig"
class="flex items-center gap-2 px-3 py-2 bg-red-500/10 text-red-400 rounded-lg hover:bg-red-500/20 disabled:opacity-50 text-sm ml-auto"
>
<Trash2 class="w-4 h-4" />
Delete
</button>
</div>
</div>
<!-- Loading State -->
<div v-if="store.isLoading" class="flex items-center justify-center py-20">
<div class="animate-spin w-8 h-8 border-2 border-oxide-500 border-t-transparent rounded-full" />
</div>
<!-- No Config Selected -->
<div v-else-if="!store.currentConfig" class="bg-neutral-900 border border-neutral-800 rounded-xl p-12 text-center">
<MessageSquare class="w-12 h-12 text-neutral-600 mx-auto mb-4" />
<h2 class="text-lg font-semibold text-neutral-300 mb-2">No BetterChat Config Selected</h2>
<p class="text-neutral-500 mb-4">Create a new config, import from server, or select one from the dropdown above.</p>
<button
@click="showCreateModal = true"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600"
>
Create First Config
</button>
</div>
<!-- Config Editor -->
<div v-else class="space-y-6">
<!-- Tab Bar -->
<div class="flex border-b border-neutral-800">
<button
v-for="tab in tabs"
:key="tab.key"
@click="activeTab = tab.key as typeof activeTab"
class="flex items-center gap-2 px-4 py-2 text-sm font-medium border-b-2 transition-colors"
:class="activeTab === tab.key
? 'border-oxide-500 text-oxide-400'
: 'border-transparent text-neutral-500 hover:text-neutral-300'"
>
<component :is="tab.icon" class="w-4 h-4" />
{{ tab.label }}
</button>
</div>
<!-- Chat Groups Tab -->
<div v-if="activeTab === 'groups'" class="space-y-4">
<div class="flex items-center justify-between">
<h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Chat Groups</h3>
<button
@click="addGroup"
class="flex items-center gap-2 px-3 py-1.5 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
Add Group
</button>
</div>
<div v-if="chatGroups.length === 0" class="bg-neutral-900 border border-neutral-800 rounded-xl p-8 text-center">
<p class="text-neutral-500">No chat groups configured. Add a group to get started.</p>
</div>
<div v-else class="space-y-3">
<div
v-for="(group, index) in chatGroups"
:key="index"
class="bg-neutral-900 border border-neutral-800 rounded-xl p-4"
>
<div class="flex items-start justify-between gap-4">
<div class="flex-1 min-w-0">
<div class="flex items-center gap-3 mb-2">
<span class="text-sm font-semibold text-neutral-200">{{ group.GroupName || group.groupName || 'Unnamed' }}</span>
<span class="text-xs px-2 py-0.5 bg-neutral-800 text-neutral-400 rounded">Priority: {{ group.Priority ?? 0 }}</span>
</div>
<div class="grid grid-cols-2 md:grid-cols-4 gap-3 text-xs">
<!-- Title -->
<div>
<span class="text-neutral-500">Title:</span>
<div class="flex items-center gap-1 mt-0.5">
<span
class="inline-block w-3 h-3 rounded border border-neutral-600"
:style="{ backgroundColor: group.Title?.Color || group.TitleColor || '#55aaff' }"
/>
<span class="text-neutral-300">{{ group.Title?.Text || group.Title || '[Player]' }}</span>
</div>
</div>
<!-- Name Color -->
<div>
<span class="text-neutral-500">Name Color:</span>
<div class="flex items-center gap-1 mt-0.5">
<span
class="inline-block w-3 h-3 rounded border border-neutral-600"
:style="{ backgroundColor: group.Username?.Color || group.NameColor || '#55aaff' }"
/>
<span class="text-neutral-300">{{ group.Username?.Color || group.NameColor || '#55aaff' }}</span>
</div>
</div>
<!-- Message Color -->
<div>
<span class="text-neutral-500">Message Color:</span>
<div class="flex items-center gap-1 mt-0.5">
<span
class="inline-block w-3 h-3 rounded border border-neutral-600"
:style="{ backgroundColor: group.Message?.Color || group.MessageColor || '#ffffff' }"
/>
<span class="text-neutral-300">{{ group.Message?.Color || group.MessageColor || '#ffffff' }}</span>
</div>
</div>
<!-- Format -->
<div>
<span class="text-neutral-500">Format:</span>
<p class="text-neutral-300 mt-0.5 truncate">{{ group.Format?.Chat || group.Format || '{Title} {Username}: {Message}' }}</p>
</div>
</div>
</div>
<div class="flex items-center gap-2 shrink-0">
<button
@click="editGroupAt(index)"
class="p-1.5 text-neutral-400 hover:text-neutral-200 hover:bg-neutral-800 rounded"
>
<Edit class="w-4 h-4" />
</button>
<button
@click="deleteGroup(index)"
class="p-1.5 text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded"
>
<Trash2 class="w-4 h-4" />
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Settings Tab -->
<div v-else-if="activeTab === 'settings'" class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-6">
<h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">General Settings</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<!-- Word Filter Enabled -->
<div class="flex items-center justify-between">
<div>
<label class="text-sm text-neutral-200">Word Filter</label>
<p class="text-xs text-neutral-500">Enable profanity/word filtering in chat</p>
</div>
<button
@click="setConfigValue('Word Filter.Enabled', !getConfigValue('Word Filter.Enabled', false))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('Word Filter.Enabled', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('Word Filter.Enabled', false) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
<!-- Anti Flood Enabled -->
<div class="flex items-center justify-between">
<div>
<label class="text-sm text-neutral-200">Anti Flood</label>
<p class="text-xs text-neutral-500">Prevent message spamming</p>
</div>
<button
@click="setConfigValue('Anti Flood.Enabled', !getConfigValue('Anti Flood.Enabled', true))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('Anti Flood.Enabled', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('Anti Flood.Enabled', true) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
<!-- Reverse Title Order -->
<div class="flex items-center justify-between">
<div>
<label class="text-sm text-neutral-200">Reverse Title Order</label>
<p class="text-xs text-neutral-500">Reverse the display order of chat titles</p>
</div>
<button
@click="setConfigValue('General.Reverse Title Order', !getConfigValue('General.Reverse Title Order', false))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('General.Reverse Title Order', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('General.Reverse Title Order', false) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
<!-- Use Custom Replacement -->
<div class="flex items-center justify-between">
<div>
<label class="text-sm text-neutral-200">Use Custom Replacement</label>
<p class="text-xs text-neutral-500">Use a custom word instead of * for filtered words</p>
</div>
<button
@click="setConfigValue('Word Filter.Use Custom Replacement', !getConfigValue('Word Filter.Use Custom Replacement', false))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('Word Filter.Use Custom Replacement', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('Word Filter.Use Custom Replacement', false) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
<!-- Enable Player Tagging -->
<div class="flex items-center justify-between">
<div>
<label class="text-sm text-neutral-200">Enable Player Tagging</label>
<p class="text-xs text-neutral-500">Allow @mentions to highlight players in chat</p>
</div>
<button
@click="setConfigValue('General.Enable Player Tagging', !getConfigValue('General.Enable Player Tagging', false))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('General.Enable Player Tagging', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('General.Enable Player Tagging', false) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
</div>
<!-- Number / Text Inputs -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<div>
<label class="block text-sm text-neutral-200 mb-1">Anti Flood Seconds</label>
<p class="text-xs text-neutral-500 mb-2">Minimum seconds between messages</p>
<input
type="number"
step="0.1"
:value="getConfigValue('Anti Flood.Seconds', 1.5)"
@input="setConfigValue('Anti Flood.Seconds', Number(($event.target as HTMLInputElement).value))"
min="0"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<div>
<label class="block text-sm text-neutral-200 mb-1">Minimal Tag Characters</label>
<p class="text-xs text-neutral-500 mb-2">Minimum characters for player tag matching</p>
<input
type="number"
:value="getConfigValue('General.Minimal Characters', 2)"
@input="setConfigValue('General.Minimal Characters', Number(($event.target as HTMLInputElement).value))"
min="1"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<div>
<label class="block text-sm text-neutral-200 mb-1">Filter Replacement</label>
<p class="text-xs text-neutral-500 mb-2">Character used to replace filtered words</p>
<input
type="text"
:value="getConfigValue('Word Filter.Replacement', '*')"
@input="setConfigValue('Word Filter.Replacement', ($event.target as HTMLInputElement).value)"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<div>
<label class="block text-sm text-neutral-200 mb-1">Custom Replacement Word</label>
<p class="text-xs text-neutral-500 mb-2">Custom word to replace filtered content</p>
<input
type="text"
:value="getConfigValue('Word Filter.Custom Replacement', 'Unicorn')"
@input="setConfigValue('Word Filter.Custom Replacement', ($event.target as HTMLInputElement).value)"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
</div>
</div>
</div>
<!-- Create Config Modal -->
<div v-if="showCreateModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showCreateModal = false">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-md">
<h2 class="text-lg font-semibold text-neutral-100 mb-4">New BetterChat Config</h2>
<div class="space-y-4">
<div>
<label class="block text-sm text-neutral-400 mb-1">Config Name</label>
<input
v-model="newConfigName"
placeholder="e.g. Default Chat Settings"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
@keydown.enter="handleCreateConfig"
/>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Description (optional)</label>
<textarea
v-model="newConfigDesc"
rows="2"
placeholder="What is this config for?"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm resize-none"
/>
</div>
<div class="flex justify-end gap-2">
<button @click="showCreateModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
<button
@click="handleCreateConfig"
:disabled="!newConfigName.trim()"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 text-sm"
>
Create
</button>
</div>
</div>
</div>
</div>
<!-- Import from Server Modal -->
<div v-if="showImportModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showImportModal = false">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-md">
<h2 class="text-lg font-semibold text-neutral-100 mb-4">Import from Server</h2>
<p class="text-sm text-neutral-400 mb-4">
Import the current BetterChat config from your live server. This will create a new config profile.
</p>
<div class="space-y-4">
<div>
<label class="block text-sm text-neutral-400 mb-1">Config Name</label>
<input
v-model="importConfigName"
placeholder="e.g. Imported Server Config"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
@keydown.enter="handleImport"
/>
</div>
<div class="flex justify-end gap-2">
<button @click="showImportModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
<button
@click="handleImport"
:disabled="!importConfigName.trim()"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 text-sm"
>
Import
</button>
</div>
</div>
</div>
</div>
<!-- Group Edit Modal -->
<div v-if="showGroupModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showGroupModal = false">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-lg max-h-[80vh] overflow-y-auto">
<div class="flex items-center justify-between mb-4">
<h2 class="text-lg font-semibold text-neutral-100">
{{ editingGroupIndex !== null ? 'Edit Group' : 'Add Group' }}
</h2>
<button @click="showGroupModal = false" class="text-neutral-400 hover:text-neutral-200">
<X class="w-5 h-5" />
</button>
</div>
<div class="space-y-4">
<!-- Group Name -->
<div>
<label class="block text-sm text-neutral-400 mb-1">Group Name</label>
<input
v-model="editGroup.GroupName"
placeholder="e.g. default, admin, vip"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<!-- Priority -->
<div>
<label class="block text-sm text-neutral-400 mb-1">Priority</label>
<p class="text-xs text-neutral-500 mb-1">Higher priority groups display first (0 = highest)</p>
<input
v-model.number="editGroup.Priority"
type="number"
min="0"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<!-- Title -->
<div>
<label class="block text-sm text-neutral-400 mb-1">Title Text</label>
<input
v-model="editGroup.Title.Text"
placeholder="e.g. [Admin]"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<!-- Colors Row -->
<div class="grid grid-cols-3 gap-4">
<div>
<label class="block text-sm text-neutral-400 mb-1">Title Color</label>
<div class="flex items-center gap-2">
<input
type="color"
v-model="editGroup.Title.Color"
class="w-8 h-8 rounded border border-neutral-700 bg-transparent cursor-pointer"
/>
<input
v-model="editGroup.Title.Color"
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-2 py-1 text-neutral-200 text-xs"
/>
</div>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Name Color</label>
<div class="flex items-center gap-2">
<input
type="color"
v-model="editGroup.Username.Color"
class="w-8 h-8 rounded border border-neutral-700 bg-transparent cursor-pointer"
/>
<input
v-model="editGroup.Username.Color"
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-2 py-1 text-neutral-200 text-xs"
/>
</div>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Message Color</label>
<div class="flex items-center gap-2">
<input
type="color"
v-model="editGroup.Message.Color"
class="w-8 h-8 rounded border border-neutral-700 bg-transparent cursor-pointer"
/>
<input
v-model="editGroup.Message.Color"
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-2 py-1 text-neutral-200 text-xs"
/>
</div>
</div>
</div>
<!-- Font Sizes -->
<div class="grid grid-cols-3 gap-4">
<div>
<label class="block text-sm text-neutral-400 mb-1">Title Size</label>
<input
v-model.number="editGroup.Title.Size"
type="number"
min="8"
max="30"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Name Size</label>
<input
v-model.number="editGroup.Username.Size"
type="number"
min="8"
max="30"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Message Size</label>
<input
v-model.number="editGroup.Message.Size"
type="number"
min="8"
max="30"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
</div>
<!-- Format Strings -->
<div>
<label class="block text-sm text-neutral-400 mb-1">Chat Format</label>
<p class="text-xs text-neutral-500 mb-1">Variables: {Title} {Username} {Message}</p>
<input
v-model="editGroup.Format.Chat"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Console Format</label>
<input
v-model="editGroup.Format.Console"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
/>
</div>
<!-- Hidden toggles -->
<div class="flex items-center gap-6">
<label class="flex items-center gap-2 text-sm text-neutral-300 cursor-pointer">
<input type="checkbox" v-model="editGroup.Title.Hidden" class="rounded bg-neutral-800 border-neutral-600" />
Hidden
</label>
<label class="flex items-center gap-2 text-sm text-neutral-300 cursor-pointer">
<input type="checkbox" v-model="editGroup.Title.HiddenIfNotPrimary" class="rounded bg-neutral-800 border-neutral-600" />
Hidden if not primary
</label>
</div>
<div class="flex justify-end gap-2 pt-2">
<button @click="showGroupModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
<button
@click="saveGroup"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 text-sm"
>
{{ editingGroupIndex !== null ? 'Update' : 'Add' }}
</button>
</div>
</div>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,656 @@
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { useTimedExecuteStore } from '@/stores/timedexecute'
import {
Save,
Play,
Download,
Plus,
Trash2,
Clock,
Settings as SettingsIcon,
X,
UserPlus,
UserMinus,
} from 'lucide-vue-next'
const store = useTimedExecuteStore()
const activeTab = ref<'timed' | 'realtime' | 'connect' | 'disconnect'>('timed')
const showCreateModal = ref(false)
const showImportModal = ref(false)
const newConfigName = ref('')
const newConfigDesc = ref('')
const importConfigName = ref('')
const tabs = [
{ key: 'timed', label: 'Timed Commands', icon: Clock },
{ key: 'realtime', label: 'Real-Time', icon: SettingsIcon },
{ key: 'connect', label: 'On Connect', icon: UserPlus },
{ key: 'disconnect', label: 'On Disconnect', icon: UserMinus },
]
onMounted(async () => {
await store.fetchConfigs()
if (store.configs.length > 0 && store.configs[0]) {
await store.loadConfig(store.configs[0].id)
}
})
// --- Config data helpers ---
function getConfigValue(path: string, defaultValue: any = false): any {
if (!store.currentConfig?.config_data) return defaultValue
const parts = path.split('.')
let current: any = store.currentConfig.config_data
for (const part of parts) {
if (current == null || typeof current !== 'object') return defaultValue
current = current[part]
}
return current ?? defaultValue
}
function setConfigValue(path: string, value: any) {
if (!store.currentConfig) return
if (!store.currentConfig.config_data) store.currentConfig.config_data = {}
const parts = path.split('.')
let current: any = store.currentConfig.config_data
for (let i = 0; i < parts.length - 1; i++) {
const part = parts[i]!
if (current[part] == null || typeof current[part] !== 'object') {
current[part] = {}
}
current = current[part]
}
current[parts[parts.length - 1]!] = value
store.markDirty()
}
// --- TimerRepeat helpers ---
const timerRepeatEntries = computed(() => {
const obj = getConfigValue('TimerRepeat', {}) as Record<string, number>
return Object.entries(obj).map(([command, interval]) => ({ command, interval }))
})
function addTimerRepeat() {
const obj = { ...getConfigValue('TimerRepeat', {}) as Record<string, number> }
obj['new.command'] = 300
setConfigValue('TimerRepeat', obj)
}
function updateTimerRepeatCommand(oldCmd: string, newCmd: string) {
const obj = { ...getConfigValue('TimerRepeat', {}) as Record<string, number> }
const interval = obj[oldCmd] ?? 300
delete obj[oldCmd]
obj[newCmd] = interval
setConfigValue('TimerRepeat', obj)
}
function updateTimerRepeatInterval(cmd: string, interval: number) {
const obj = { ...getConfigValue('TimerRepeat', {}) as Record<string, number> }
obj[cmd] = interval
setConfigValue('TimerRepeat', obj)
}
function removeTimerRepeat(cmd: string) {
const obj = { ...getConfigValue('TimerRepeat', {}) as Record<string, number> }
delete obj[cmd]
setConfigValue('TimerRepeat', obj)
}
function addPresetTimer(command: string, interval: number) {
const obj = { ...getConfigValue('TimerRepeat', {}) as Record<string, number> }
obj[command] = interval
setConfigValue('TimerRepeat', obj)
}
// --- RealTime-Timer helpers ---
const realTimeEntries = computed(() => {
const obj = getConfigValue('RealTime-Timer', {}) as Record<string, string>
return Object.entries(obj).map(([time, command]) => ({ time, command }))
})
function addRealTimeEntry() {
const obj = { ...getConfigValue('RealTime-Timer', {}) as Record<string, string> }
obj['12:00:00'] = 'say Scheduled message'
setConfigValue('RealTime-Timer', obj)
}
function updateRealTimeTime(oldTime: string, newTime: string) {
const obj = { ...getConfigValue('RealTime-Timer', {}) as Record<string, string> }
const command = obj[oldTime] ?? ''
delete obj[oldTime]
obj[newTime] = command
setConfigValue('RealTime-Timer', obj)
}
function updateRealTimeCommand(time: string, command: string) {
const obj = { ...getConfigValue('RealTime-Timer', {}) as Record<string, string> }
obj[time] = command
setConfigValue('RealTime-Timer', obj)
}
function removeRealTimeEntry(time: string) {
const obj = { ...getConfigValue('RealTime-Timer', {}) as Record<string, string> }
delete obj[time]
setConfigValue('RealTime-Timer', obj)
}
// --- OnPlayerConnected helpers ---
const connectCommands = computed(() => {
return (getConfigValue('OnPlayerConnectCommands', []) as string[])
})
function addConnectCommand() {
const cmds = [...connectCommands.value, '']
setConfigValue('OnPlayerConnectCommands', cmds)
}
function updateConnectCommand(index: number, value: string) {
const cmds = [...connectCommands.value]
cmds[index] = value
setConfigValue('OnPlayerConnectCommands', cmds)
}
function removeConnectCommand(index: number) {
const cmds = [...connectCommands.value]
cmds.splice(index, 1)
setConfigValue('OnPlayerConnectCommands', cmds)
}
// --- OnPlayerDisconnected helpers ---
const disconnectCommands = computed(() => {
return (getConfigValue('OnPlayerDisconnectCommands', []) as string[])
})
function addDisconnectCommand() {
const cmds = [...disconnectCommands.value, '']
setConfigValue('OnPlayerDisconnectCommands', cmds)
}
function updateDisconnectCommand(index: number, value: string) {
const cmds = [...disconnectCommands.value]
cmds[index] = value
setConfigValue('OnPlayerDisconnectCommands', cmds)
}
function removeDisconnectCommand(index: number) {
const cmds = [...disconnectCommands.value]
cmds.splice(index, 1)
setConfigValue('OnPlayerDisconnectCommands', cmds)
}
// --- Action handlers ---
async function handleConfigChange(id: string) {
if (store.isDirty) {
if (!confirm('Unsaved changes will be lost. Continue?')) return
}
await store.loadConfig(id)
}
async function handleCreateConfig() {
if (!newConfigName.value.trim()) return
const config = await store.createConfig(
newConfigName.value.trim(),
newConfigDesc.value.trim() || undefined,
)
if (config) {
showCreateModal.value = false
newConfigName.value = ''
newConfigDesc.value = ''
}
}
async function handleDeleteConfig() {
if (!store.currentConfig) return
if (!confirm(`Delete "${store.currentConfig.config_name}"? This cannot be undone.`)) return
await store.deleteConfig(store.currentConfig.id)
}
async function handleApply() {
if (!store.currentConfig) return
if (!confirm('Apply this TimedExecute config to the server? This will overwrite the current config.')) return
if (store.isDirty) {
await store.saveCurrentConfig()
}
await store.applyToServer(store.currentConfig.id)
}
async function handleImport() {
if (!importConfigName.value.trim()) return
const config = await store.importFromServer(importConfigName.value.trim())
if (config) {
showImportModal.value = false
importConfigName.value = ''
}
}
</script>
<template>
<div class="p-6 space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<h1 class="text-2xl font-bold text-white">Timed Execute</h1>
<div class="flex items-center gap-3">
<button
@click="showCreateModal = true"
class="flex items-center gap-2 px-3 py-2 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
New Config
</button>
</div>
</div>
<!-- Config Selector + Action Bar -->
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-4">
<div class="flex items-center gap-3 flex-wrap">
<!-- Config Selector -->
<select
v-if="store.configs.length > 0"
:value="store.currentConfig?.id || ''"
@change="handleConfigChange(($event.target as HTMLSelectElement).value)"
class="bg-neutral-800 border border-neutral-700 text-neutral-200 rounded-lg px-3 py-2 text-sm min-w-[200px]"
>
<option v-for="c in store.configs" :key="c.id" :value="c.id">
{{ c.config_name }}
<template v-if="c.is_active"> (Active)</template>
</option>
</select>
<span v-else class="text-neutral-500 text-sm">No configs yet</span>
<!-- Save -->
<button
@click="store.saveCurrentConfig()"
:disabled="!store.currentConfig || !store.isDirty || store.isSaving"
class="flex items-center gap-2 px-3 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
>
<Save class="w-4 h-4" />
{{ store.isSaving ? 'Saving...' : 'Save' }}
</button>
<!-- Apply to Server -->
<button
@click="handleApply"
:disabled="!store.currentConfig || store.isApplying"
class="flex items-center gap-2 px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
>
<Play class="w-4 h-4" />
{{ store.isApplying ? 'Applying...' : 'Apply to Server' }}
</button>
<!-- Import from Server -->
<button
@click="showImportModal = true"
class="flex items-center gap-2 px-3 py-2 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Download class="w-4 h-4" />
Import from Server
</button>
<!-- Delete -->
<button
@click="handleDeleteConfig"
:disabled="!store.currentConfig"
class="flex items-center gap-2 px-3 py-2 bg-red-500/10 text-red-400 rounded-lg hover:bg-red-500/20 disabled:opacity-50 text-sm ml-auto"
>
<Trash2 class="w-4 h-4" />
Delete
</button>
</div>
</div>
<!-- Loading State -->
<div v-if="store.isLoading" class="flex items-center justify-center py-20">
<div class="animate-spin w-8 h-8 border-2 border-oxide-500 border-t-transparent rounded-full" />
</div>
<!-- No Config Selected -->
<div v-else-if="!store.currentConfig" class="bg-neutral-900 border border-neutral-800 rounded-xl p-12 text-center">
<Clock class="w-12 h-12 text-neutral-600 mx-auto mb-4" />
<h2 class="text-lg font-semibold text-neutral-300 mb-2">No TimedExecute Config Selected</h2>
<p class="text-neutral-500 mb-4">Create a new config, import from server, or select one from the dropdown above.</p>
<button
@click="showCreateModal = true"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600"
>
Create First Config
</button>
</div>
<!-- Config Editor -->
<div v-else class="space-y-6">
<!-- Tab Bar -->
<div class="flex border-b border-neutral-800">
<button
v-for="tab in tabs"
:key="tab.key"
@click="activeTab = tab.key as typeof activeTab"
class="flex items-center gap-2 px-4 py-2 text-sm font-medium border-b-2 transition-colors"
:class="activeTab === tab.key
? 'border-oxide-500 text-oxide-400'
: 'border-transparent text-neutral-500 hover:text-neutral-300'"
>
<component :is="tab.icon" class="w-4 h-4" />
{{ tab.label }}
</button>
</div>
<!-- Timed Commands Tab -->
<div v-if="activeTab === 'timed'" class="space-y-4">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-4">
<div class="flex items-center justify-between">
<div>
<h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Timer Repeat</h3>
<p class="text-xs text-neutral-500 mt-1">Commands executed repeatedly at set intervals (seconds)</p>
</div>
<div class="flex items-center gap-2">
<!-- Enable toggle -->
<span class="text-xs text-neutral-400 mr-2">Enabled</span>
<button
@click="setConfigValue('EnableTimerRepeat', !getConfigValue('EnableTimerRepeat', true))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('EnableTimerRepeat', true) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('EnableTimerRepeat', true) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
</div>
<!-- Preset Buttons -->
<div class="flex items-center gap-2 flex-wrap">
<span class="text-xs text-neutral-500">Quick add:</span>
<button
@click="addPresetTimer('server.save', 300)"
class="px-2 py-1 text-xs bg-neutral-800 text-neutral-300 rounded hover:bg-neutral-700"
>
server.save (5m)
</button>
<button
@click="addPresetTimer('say Server restart warning!', 3600)"
class="px-2 py-1 text-xs bg-neutral-800 text-neutral-300 rounded hover:bg-neutral-700"
>
Restart warning (1h)
</button>
<button
@click="addPresetTimer('oxide.reload *', 7200)"
class="px-2 py-1 text-xs bg-neutral-800 text-neutral-300 rounded hover:bg-neutral-700"
>
Reload plugins (2h)
</button>
</div>
<!-- Entries -->
<div v-if="timerRepeatEntries.length === 0" class="py-4 text-center text-neutral-500 text-sm">
No timed commands configured. Add a command or use a preset above.
</div>
<div v-else class="space-y-2">
<div
v-for="(entry, index) in timerRepeatEntries"
:key="index"
class="flex items-center gap-3 bg-neutral-800/50 rounded-lg p-3"
>
<input
:value="entry.command"
@change="updateTimerRepeatCommand(entry.command, ($event.target as HTMLInputElement).value)"
placeholder="console command"
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-1.5 text-neutral-200 text-sm"
/>
<div class="flex items-center gap-1">
<input
:value="entry.interval"
@input="updateTimerRepeatInterval(entry.command, Number(($event.target as HTMLInputElement).value))"
type="number"
min="1"
class="w-24 bg-neutral-800 border border-neutral-700 rounded-lg px-2 py-1.5 text-neutral-200 text-sm text-right"
/>
<span class="text-xs text-neutral-500">sec</span>
</div>
<button
@click="removeTimerRepeat(entry.command)"
class="p-1.5 text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded"
>
<Trash2 class="w-4 h-4" />
</button>
</div>
</div>
<button
@click="addTimerRepeat"
class="flex items-center gap-2 px-3 py-1.5 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
Add Command
</button>
</div>
</div>
<!-- Real-Time Tab -->
<div v-else-if="activeTab === 'realtime'" class="space-y-4">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-4">
<div class="flex items-center justify-between">
<div>
<h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">Real-Time Timer</h3>
<p class="text-xs text-neutral-500 mt-1">Commands executed at specific times of day (HH:MM:SS)</p>
</div>
<div class="flex items-center gap-2">
<span class="text-xs text-neutral-400 mr-2">Enabled</span>
<button
@click="setConfigValue('EnableRealTime-Timer', !getConfigValue('EnableRealTime-Timer', false))"
class="relative w-11 h-6 rounded-full transition-colors"
:class="getConfigValue('EnableRealTime-Timer', false) ? 'bg-oxide-500' : 'bg-neutral-700'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform"
:class="getConfigValue('EnableRealTime-Timer', false) ? 'translate-x-5' : 'translate-x-0'"
/>
</button>
</div>
</div>
<div v-if="realTimeEntries.length === 0" class="py-4 text-center text-neutral-500 text-sm">
No real-time commands configured. Add a time-based command below.
</div>
<div v-else class="space-y-2">
<div
v-for="(entry, index) in realTimeEntries"
:key="index"
class="flex items-center gap-3 bg-neutral-800/50 rounded-lg p-3"
>
<input
:value="entry.time"
@change="updateRealTimeTime(entry.time, ($event.target as HTMLInputElement).value)"
placeholder="HH:MM:SS"
class="w-32 bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-1.5 text-neutral-200 text-sm"
/>
<input
:value="entry.command"
@change="updateRealTimeCommand(entry.time, ($event.target as HTMLInputElement).value)"
placeholder="console command"
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-1.5 text-neutral-200 text-sm"
/>
<button
@click="removeRealTimeEntry(entry.time)"
class="p-1.5 text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded"
>
<Trash2 class="w-4 h-4" />
</button>
</div>
</div>
<button
@click="addRealTimeEntry"
class="flex items-center gap-2 px-3 py-1.5 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
Add Time Entry
</button>
</div>
</div>
<!-- On Connect Tab -->
<div v-else-if="activeTab === 'connect'" class="space-y-4">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-4">
<div>
<h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">On Player Connect</h3>
<p class="text-xs text-neutral-500 mt-1">Commands executed when a player joins the server</p>
</div>
<div v-if="connectCommands.length === 0" class="py-4 text-center text-neutral-500 text-sm">
No connect commands configured. Add a command below.
</div>
<div v-else class="space-y-2">
<div
v-for="(cmd, index) in connectCommands"
:key="index"
class="flex items-center gap-3 bg-neutral-800/50 rounded-lg p-3"
>
<input
:value="cmd"
@change="updateConnectCommand(index, ($event.target as HTMLInputElement).value)"
placeholder='e.g. say Welcome {player.name}!'
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-1.5 text-neutral-200 text-sm"
/>
<button
@click="removeConnectCommand(index)"
class="p-1.5 text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded"
>
<Trash2 class="w-4 h-4" />
</button>
</div>
</div>
<button
@click="addConnectCommand"
class="flex items-center gap-2 px-3 py-1.5 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
Add Command
</button>
</div>
</div>
<!-- On Disconnect Tab -->
<div v-else-if="activeTab === 'disconnect'" class="space-y-4">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 space-y-4">
<div>
<h3 class="text-sm font-semibold text-neutral-300 uppercase tracking-wider">On Player Disconnect</h3>
<p class="text-xs text-neutral-500 mt-1">Commands executed when a player leaves the server</p>
</div>
<div v-if="disconnectCommands.length === 0" class="py-4 text-center text-neutral-500 text-sm">
No disconnect commands configured. Add a command below.
</div>
<div v-else class="space-y-2">
<div
v-for="(cmd, index) in disconnectCommands"
:key="index"
class="flex items-center gap-3 bg-neutral-800/50 rounded-lg p-3"
>
<input
:value="cmd"
@change="updateDisconnectCommand(index, ($event.target as HTMLInputElement).value)"
placeholder='e.g. say {player.name} has left'
class="flex-1 bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-1.5 text-neutral-200 text-sm"
/>
<button
@click="removeDisconnectCommand(index)"
class="p-1.5 text-red-400 hover:text-red-300 hover:bg-red-500/10 rounded"
>
<Trash2 class="w-4 h-4" />
</button>
</div>
</div>
<button
@click="addDisconnectCommand"
class="flex items-center gap-2 px-3 py-1.5 bg-neutral-800 text-neutral-300 rounded-lg hover:bg-neutral-700 text-sm"
>
<Plus class="w-4 h-4" />
Add Command
</button>
</div>
</div>
</div>
<!-- Create Config Modal -->
<div v-if="showCreateModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showCreateModal = false">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-md">
<h2 class="text-lg font-semibold text-neutral-100 mb-4">New TimedExecute Config</h2>
<div class="space-y-4">
<div>
<label class="block text-sm text-neutral-400 mb-1">Config Name</label>
<input
v-model="newConfigName"
placeholder="e.g. Default Timer Settings"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
@keydown.enter="handleCreateConfig"
/>
</div>
<div>
<label class="block text-sm text-neutral-400 mb-1">Description (optional)</label>
<textarea
v-model="newConfigDesc"
rows="2"
placeholder="What is this config for?"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm resize-none"
/>
</div>
<div class="flex justify-end gap-2">
<button @click="showCreateModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
<button
@click="handleCreateConfig"
:disabled="!newConfigName.trim()"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 text-sm"
>
Create
</button>
</div>
</div>
</div>
</div>
<!-- Import from Server Modal -->
<div v-if="showImportModal" class="fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4" @click.self="showImportModal = false">
<div class="bg-neutral-900 border border-neutral-800 rounded-xl p-6 w-full max-w-md">
<h2 class="text-lg font-semibold text-neutral-100 mb-4">Import from Server</h2>
<p class="text-sm text-neutral-400 mb-4">
Import the current TimedExecute config from your live server. This will create a new config profile.
</p>
<div class="space-y-4">
<div>
<label class="block text-sm text-neutral-400 mb-1">Config Name</label>
<input
v-model="importConfigName"
placeholder="e.g. Imported Server Config"
class="w-full bg-neutral-800 border border-neutral-700 rounded-lg px-3 py-2 text-neutral-200 text-sm"
@keydown.enter="handleImport"
/>
</div>
<div class="flex justify-end gap-2">
<button @click="showImportModal = false" class="px-4 py-2 text-sm text-neutral-400 hover:text-neutral-200">Cancel</button>
<button
@click="handleImport"
:disabled="!importConfigName.trim()"
class="px-4 py-2 bg-oxide-500 text-white rounded-lg hover:bg-oxide-600 disabled:opacity-50 text-sm"
>
Import
</button>
</div>
</div>
</div>
</div>
</div>
</template>