X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftwitch-bot%2FControls.js;h=51f0633a226bdc1f5626a47ee9778ba77d160ac2;hb=147c5f43c5d41fa18e82edb6651fe5a37c789353;hp=bdc89380fe75c07a4a1ad22e8dd2587661d1ac1b;hpb=e49b130505f5712075dca2ff990e5a63fc90ce3c;p=alttp.git diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index bdc8938..51f0633 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -5,12 +5,22 @@ 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', 'lol', 'pog', 'hype', 'o7']; + 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(); @@ -26,6 +36,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 }); @@ -56,12 +78,66 @@ const Controls = () => { } }, [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); }} @@ -105,41 +181,120 @@ 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.chatSettings')}

- + + +
+

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

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