1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-18 01:50:50 +00:00

fix: disallow creation of commands/timers already in use

fixes #28
This commit is contained in:
Ash Keel 2022-12-01 16:40:04 +01:00
parent d4e99bfe10
commit fd9dbedfdb
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
3 changed files with 31 additions and 4 deletions

View file

@ -109,7 +109,8 @@
"streamer": "Streamer only"
},
"remove-command-title": "Remove command {{name}}?",
"no-commands": "Chatbot has no commands configured"
"no-commands": "Chatbot has no commands configured",
"command-already-in-use": "Command name already in use"
},
"bottimers": {
"title": "Bot timers",
@ -126,7 +127,8 @@
"timer-activity": "Minimul chat activity (0 to disable)",
"timer-activity-desc": "messages in the last 5 minutes",
"timer-messages": "Messages",
"no-timers": "There are no timers configured"
"no-timers": "There are no timers configured",
"name-already-in-use": "Timer name already in use"
},
"auth": {
"title": "Authentication required",

View file

@ -189,6 +189,7 @@ function CommandDialog({
item?: TwitchBotCustomCommand;
onSubmit?: (name: string, item: TwitchBotCustomCommand) => void;
}) {
const [commands] = useModule(modules.twitchBotCommands);
const [commandName, setCommandName] = useState(name ?? '');
const [description, setDescription] = useState(item?.description ?? '');
const [response, setResponse] = useState(item?.response ?? '');
@ -226,7 +227,17 @@ function CommandDialog({
id="command-name"
value={commandName}
required={true}
onChange={(e) => setCommandName(e.target.value)}
onChange={(e) => {
setCommandName(e.target.value);
// If command name is different but matches another defined command, set as invalid
if (e.target.value !== name && e.target.value in commands) {
(e.target as HTMLInputElement).setCustomValidity(
t('pages.botcommands.command-already-in-use'),
);
} else {
(e.target as HTMLInputElement).setCustomValidity('');
}
}}
placeholder={t('pages.botcommands.command-name-placeholder')}
/>
</Field>

View file

@ -200,6 +200,7 @@ function TimerDialog({
item?: TwitchBotTimer;
onSubmit?: (name: string, item: TwitchBotTimer) => void;
}) {
const [timerConfig] = useModule(modules.twitchBotTimers);
const [timerName, setName] = useState(name ?? '');
const [messages, setMessages] = useState(item?.messages ?? ['']);
const [minDelay, setMinDelay] = useState(item?.minimum_delay ?? 300);
@ -234,7 +235,20 @@ function TimerDialog({
<InputBox
id="timer-name"
value={timerName}
onChange={(e) => setName(e.target.value)}
onChange={(e) => {
setName(e.target.value);
// If timer name is different but matches another defined timer, set as invalid
if (
e.target.value !== name &&
e.target.value in timerConfig.timers
) {
(e.target as HTMLInputElement).setCustomValidity(
t('pages.bottimers.name-already-in-use'),
);
} else {
(e.target as HTMLInputElement).setCustomValidity('');
}
}}
placeholder={t('pages.bottimers.timer-name-placeholder')}
required={true}
/>