X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftwitch-bot%2FControls.js;h=f64ee62712a658da228c4ebacbc895d55931bf35;hb=1b9629ce7f600b4aa9c9d51a281e514031871828;hp=cc062e8aff53805bf4a78cfa6499c4ab81915cf0;hpb=06fbdc15c8db57590c9b6a38ee1f00d5f349cff9;p=alttp.git diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index cc062e8..f64ee62 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -4,12 +4,43 @@ import { Alert, Button, Col, Form, Row } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; import toastr from 'toastr'; +import ChatSettingsForm from './ChatSettingsForm'; +import CommandDialog from './CommandDialog'; +import Commands from './Commands'; +import GuessingSettingsForm from './GuessingSettingsForm'; +import ChatBotLog from '../chat-bot-logs/ChatBotLog'; import ChannelSelect from '../common/ChannelSelect'; +import Icon from '../common/Icon'; import ToggleSwitch from '../common/ToggleSwitch'; +const CHAT_CATEGORIES = [ + 'unclassified', + 'hi', + 'gl', + 'gg', + 'eyes', + 'love', + 'lol', + 'yes', + 'no', + 'rage', + 'sad', + 'sweat', + 'wtf', + 'pog', + 'hype', + 'kappa', + 'o7', + 'question', + 'thx', +]; + const Controls = () => { const [channel, setChannel] = React.useState(null); const [chatText, setChatText] = React.useState(''); + const [editCommand, setEditCommand] = React.useState(''); + const [editCommandSettings, setEditCommandSettings] = React.useState({}); + const [showCommandDialog, setShowCommandDialog] = React.useState(false); const { t } = useTranslation(); @@ -25,6 +56,18 @@ const Controls = () => { } }, [channel, chatText, t]); + const randomChat = React.useCallback(async (category) => { + try { + await axios.post(`/api/channels/${channel.id}/chat`, { + bot_nick: 'horstiebot', + category, + }); + toastr.success(t('twitchBot.chatSuccess')); + } catch (e) { + toastr.error(t('twitchBot.chatError')); + } + }, [channel, chatText, t]); + const join = React.useCallback(async (bot_nick) => { try { const rsp = await axios.post(`/api/channels/${channel.id}/join`, { bot_nick }); @@ -45,12 +88,76 @@ 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]); + + const onAddCommand = React.useCallback(() => { + setEditCommand(''); + setEditCommandSettings({}); + setShowCommandDialog(true); + }, [channel]); + + const onEditCommand = React.useCallback((name, settings) => { + setEditCommand(name); + setEditCommandSettings(settings); + setShowCommandDialog(true); + }, [channel]); + + const onRemoveCommand = React.useCallback(async (name) => { + try { + const rsp = await axios.delete(`/api/channels/${channel.id}/commands/${name}`); + setChannel(rsp.data); + toastr.success(t('twitchBot.saveSuccess')); + } catch (e) { + toastr.error(t('twitchBot.saveError')); + } + }, [channel]); + + const saveCommand = React.useCallback(async (values) => { + try { + const rsp = await axios.put( + `/api/channels/${channel.id}/commands/${values.name}`, + values, + ); + setChannel(rsp.data); + setShowCommandDialog(false); + setEditCommand(''); + setEditCommandSettings({}); + toastr.success(t('twitchBot.saveSuccess')); + } catch (e) { + toastr.error(t('twitchBot.saveError')); + throw e; + } + }, [channel]); + + const saveGuessingGame = React.useCallback(async (values) => { + try { + const rsp = await axios.put( + `/api/channels/${channel.id}/guessing-game/${values.name}`, + values, + ); + setChannel(rsp.data); + toastr.success(t('twitchBot.saveSuccess')); + } catch (e) { + toastr.error(t('twitchBot.saveError')); + throw e; + } + }, [channel]); + return <> {t('twitchBot.channel')} { setChannel(channel); }} @@ -94,38 +201,121 @@ const Controls = () => { {channel ? - - {t('twitchBot.chat')} - { - setChatText(value); + +

{t('twitchBot.chat')}

+ + {t('twitchBot.chat')} + { + setChatText(value); + }} + value={chatText} + /> +
+ + +
+
+

{t('twitchBot.randomChat')}

+
+ {CHAT_CATEGORIES.map(category => + + )} +
+ + +
+

{t('twitchBot.chatSettings')}

+
+ +
+
+ + + +

{t('twitchBot.commands')}

+ + { + setShowCommandDialog(false); + setEditCommand(''); + setEditCommandSettings({}); }} - value={chatText} + onSubmit={saveCommand} + settings={editCommandSettings} + show={showCommandDialog} /> -
- -
-
+ + +
+

{t('twitchBot.guessingGame.settings')}

+
+ {channel.access_key ? + + : null} + +
+
+ +
: