X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftwitch-bot%2FControls.js;h=bdc89380fe75c07a4a1ad22e8dd2587661d1ac1b;hb=532dea7c62f3619a04cd8d7aa895f8db1f3f98d2;hp=1faa912fa0c95525dcc7bf1983fac4113f0243f1;hpb=51a752c7cce2465043dfb3d63a0152b64765b167;p=alttp.git diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index 1faa912..bdc8938 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -4,6 +4,7 @@ import { Alert, Button, Col, Form, Row } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; import toastr from 'toastr'; +import ChatSettingsForm from './ChatSettingsForm'; import ChannelSelect from '../common/ChannelSelect'; import ToggleSwitch from '../common/ToggleSwitch'; @@ -13,10 +14,11 @@ const Controls = () => { const { t } = useTranslation(); - const chat = React.useCallback(async text => { + const chat = React.useCallback(async (text, bot_nick) => { try { await axios.post(`/api/channels/${channel.id}/chat`, { text, + bot_nick, }); toastr.success(t('twitchBot.chatSuccess')); } catch (e) { @@ -24,9 +26,9 @@ const Controls = () => { } }, [channel, chatText, t]); - const join = React.useCallback(async () => { + const join = React.useCallback(async (bot_nick) => { try { - const rsp = await axios.post(`/api/channels/${channel.id}/join`); + const rsp = await axios.post(`/api/channels/${channel.id}/join`, { bot_nick }); setChannel(rsp.data); toastr.success(t('twitchBot.joinSuccess')); } catch (e) { @@ -34,9 +36,9 @@ const Controls = () => { } }, [channel, t]); - const part = React.useCallback(async () => { + const part = React.useCallback(async (bot_nick) => { try { - const rsp = await axios.post(`/api/channels/${channel.id}/part`); + const rsp = await axios.post(`/api/channels/${channel.id}/part`, { bot_nick }); setChannel(rsp.data); toastr.success(t('twitchBot.partSuccess')); } catch (e) { @@ -44,6 +46,16 @@ const Controls = () => { } }, [channel, t]); + const saveChatSettings = React.useCallback(async (values) => { + try { + const rsp = await axios.post(`/api/channels/${channel.id}/chat-settings`, values); + setChannel(rsp.data); + toastr.success(t('twitchBot.saveSuccess')); + } catch (e) { + toastr.error(t('twitchBot.saveError')); + } + }, [channel, t]); + return <> @@ -56,24 +68,40 @@ const Controls = () => { value={channel ? channel.id : ''} /> - {channel ? - - {t('twitchBot.join')} + {channel ? <> + + {t('twitchBot.joinApp')} { if (value) { - join(); + join('localhorsttv'); } else { - part(); + part('localhorsttv'); } }} value={channel.join} /> - : null} + + {t('twitchBot.joinChat')} + + { + if (value) { + join('horstiebot'); + } else { + part('horstiebot'); + } + }} + value={channel.chat} + /> + + + > : null} {channel ? @@ -86,17 +114,33 @@ const Controls = () => { }} value={chatText} /> - { - if (chatText) chat(chatText); - }} - variant="twitch" - > - {t('button.send')} - + + { + if (chatText) chat(chatText, 'localhorsttv'); + }} + variant="twitch" + > + {t('twitchBot.sendApp')} + + { + if (chatText) chat(chatText, 'horstiebot'); + }} + variant="twitch" + > + {t('twitchBot.sendChat')} + + + + {t('twitchBot.chatSettings')} + + :