]> git.localhorst.tv Git - alttp.git/commitdiff
chat bot config
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 5 Apr 2024 19:45:47 +0000 (21:45 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 5 Apr 2024 19:45:47 +0000 (21:45 +0200)
app/Http/Controllers/ChannelController.php
app/TwitchBot/TwitchChatBot.php
resources/js/components/twitch-bot/ChatSettingsForm.js
resources/js/i18n/de.js
resources/js/i18n/en.js

index c47a4066a20a2d80112558498c1f198c9538786b..b72742f2d835d664ed7c55e30d8b3cf6e1aa6e14 100644 (file)
@@ -68,6 +68,8 @@ class ChannelController extends Controller {
                        throw new \Exception('channel has no twitch chat set');
                }
                $validatedData = $request->validate([
+                       'language' => 'string|in:de,en,es,fr',
+                       'respond' => 'string|in:50,no,yes',
                        'wait_msgs_min' => 'integer|min:1',
                        'wait_msgs_max' => 'integer',
                        'wait_time_min' => 'integer',
index da4cc041aff1314e7f2f3ca75226ea686cca50e6..03d9a38c88b402b327532e290249bb8d986f8990 100644 (file)
@@ -244,7 +244,7 @@ class TwitchChatBot extends TwitchBot {
                        ->where('created_at', '<', now()->sub(1, 'day'))
                        ->where(function ($query) use ($channel) {
                                $query->whereNull('detected_language');
-                               $query->orWhereIn('detected_language', $channel->languages);
+                               $query->orWhereIn('detected_language', $this->getPreferredLanguages($channel));
                        })
                        ->inRandomOrder();
        }
@@ -338,7 +338,7 @@ class TwitchChatBot extends TwitchBot {
                                array_shift($this->notes[$channel->id]['latest_msgs']);
                        }
                }
-               if ($this->isDirectedAtMe($msg->getText())) {
+               if ($this->isDirectedAtMe($msg->getText()) && $this->shouldRespond($channel)) {
                        $this->notes[$channel->id]['wait_msgs'] = 0;
                        $this->notes[$channel->id]['wait_time'] = 0;
                }
@@ -352,6 +352,17 @@ class TwitchChatBot extends TwitchBot {
                $this->notes[$channel->id]['wait_time'] = $this->randomWaitTime($channel);
        }
 
+       private function getPreferredLanguages(Channel $channel) {
+               $setting = $this->getChatSetting($channel, 'language');
+               if ($setting) {
+                       return [$setting];
+               }
+               if (!empty($channel->languages)) {
+                       return $channel->languages;
+               }
+               return ['de'];
+       }
+
        private function isDirectedAtMe($raw_text) {
                $text = strtolower($raw_text);
                if (strpos($text, 'horstie') !== false) {
@@ -360,6 +371,17 @@ class TwitchChatBot extends TwitchBot {
                return false;
        }
 
+       private function shouldRespond(Channel $channel) {
+               $setting = $this->getChatSetting($channel, 'respond', 'yes');
+               if ($setting == 'yes') {
+                       return true;
+               }
+               if ($setting == '50') {
+                       return random_int(0, 1);
+               }
+               return false;
+       }
+
        private $channels;
        private $notes = [];
 
index d9c03d7f3b04025128cb56c48b189b79f05cfe42..4d36a31601ee3d19e55be0ce8c0e8c8b68a42daa 100644 (file)
@@ -85,6 +85,48 @@ const ChatSettingsForm = ({
                                        </Form.Text>
                                }
                        </Form.Group>
+                       <Form.Group as={Col} md={6} controlId="chatSettings.language">
+                               <Form.Label>{t('twitchBot.language')}</Form.Label>
+                               <Form.Select
+                                       isInvalid={!!(touched.language && errors.language)}
+                                       name="language"
+                                       onBlur={handleBlur}
+                                       onChange={handleChange}
+                                       value={values.language || 'de'}
+                               >
+                                       {['de', 'en', 'es', 'fr'].map(lang =>
+                                               <option key={lang} value={lang}>
+                                                       {t(`general.languages.${lang}`)}
+                                               </option>
+                                       )}
+                               </Form.Select>
+                               {touched.language && errors.language ?
+                                       <Form.Control.Feedback type="invalid">
+                                               {t(errors.language)}
+                                       </Form.Control.Feedback>
+                               : null}
+                       </Form.Group>
+                       <Form.Group as={Col} md={6} controlId="chatSettings.respond">
+                               <Form.Label>{t('twitchBot.respond')}</Form.Label>
+                               <Form.Select
+                                       isInvalid={!!(touched.respond && errors.respond)}
+                                       name="respond"
+                                       onBlur={handleBlur}
+                                       onChange={handleChange}
+                                       value={values.respond || 'yes'}
+                               >
+                                       {['yes', '50', 'no'].map(value =>
+                                               <option key={value} value={value}>
+                                                       {t(`twitchBot.respondOptions.${value}`)}
+                                               </option>
+                                       )}
+                               </Form.Select>
+                               {touched.respond && errors.respond ?
+                                       <Form.Control.Feedback type="invalid">
+                                               {t(errors.respond)}
+                                       </Form.Control.Feedback>
+                               : null}
+                       </Form.Group>
                </Row>
                <div className="button-bar mt-3">
                        <Button disabled={!dirty || isSubmitting} type="submit" variant="primary">
@@ -97,6 +139,8 @@ const ChatSettingsForm = ({
 ChatSettingsForm.propTypes = {
        dirty: PropTypes.bool,
        errors: PropTypes.shape({
+               language: PropTypes.string,
+               respond: PropTypes.string,
                wait_msgs_max: PropTypes.string,
                wait_msgs_min: PropTypes.string,
                wait_time_min: PropTypes.string,
@@ -107,12 +151,16 @@ ChatSettingsForm.propTypes = {
        handleSubmit: PropTypes.func,
        isSubmitting: PropTypes.bool,
        touched: PropTypes.shape({
+               language: PropTypes.bool,
+               respond: PropTypes.bool,
                wait_msgs_max: PropTypes.bool,
                wait_msgs_min: PropTypes.bool,
                wait_time_min: PropTypes.bool,
                wait_time_max: PropTypes.bool,
        }),
        values: PropTypes.shape({
+               language: PropTypes.string,
+               respond: PropTypes.string,
                wait_msgs_max: PropTypes.number,
                wait_msgs_min: PropTypes.number,
                wait_time_min: PropTypes.string,
@@ -132,6 +180,8 @@ export default withFormik({
                });
        },
        mapPropsToValues: ({ channel }) => ({
+               language: channel.chat_settings.language || channel.languages[0] || 'de',
+               respond: channel.chat_settings.respond || 'yes',
                wait_msgs_min: channel.chat_settings.wait_msgs_min || 1,
                wait_msgs_max: channel.chat_settings.wait_msgs_max || 10,
                wait_time_min: channel.chat_settings.wait_time_min
@@ -140,6 +190,8 @@ export default withFormik({
                        ? formatTime({ time: channel.chat_settings.wait_time_max }) : '15:00',
        }),
        validationSchema: yup.object().shape({
+               language: yup.string(),
+               respond: yup.string(),
                wait_msgs_min: yup.number().min(1),
                wait_msgs_max: yup.number().min(1),
                wait_time_min: yup.string().time(),
index 5bba519c84e001835e4bb6d51c6b8a8e30c491f7..2301b077c10cb9ea47a579029c3aee7c36ac661a 100644 (file)
@@ -201,6 +201,12 @@ export default {
                        appDescription: 'Turniere und Tutorials für The Legend of Zelda: A Link to the Past Randomizer',
                        appName: 'ALttP',
                        pleaseSelect: 'Bitte wählen',
+                       languages: {
+                               de: 'Deutsch',
+                               en: 'Englisch',
+                               es: 'Spanisch',
+                               fr: 'Französisch',
+                       },
                },
                icon: {
                        AddIcon: 'Hinzufügen',
@@ -745,6 +751,7 @@ export default {
                                winnersMessageHint: '{names} wird durch die Namen der Gewinner ersetzt',
                        },
                        heading: 'Twitch Bot',
+                       language: 'Bevorzugte Sprache',
                        joinApp: 'Join als App Bot',
                        joinChat: 'Join als Chat Bot',
                        joinError: 'Fehler beim Betreten',
@@ -752,6 +759,12 @@ export default {
                        noManagePermission: 'Du verfügst nicht über die notwendigen Berechtigungen, um den Twitch Bot zu administrieren.',
                        partError: 'Fehler beim Verlassen',
                        partSuccess: 'Verlassen',
+                       respond: 'Antworten',
+                       respondOptions: {
+                               50: '50:50',
+                               no: 'Nein',
+                               yes: 'Ja',
+                       },
                        saveError: 'Fehler beim Speichern',
                        saveSuccess: 'Gespeichert',
                        selectChannel: 'Bitte wählen einen Channel, den du verändern möchtest.',
index b14fa9449001ba6a06215ee46c95c5b42b8a49c9..d76ce1bf0af0d1a0e6c9a9471892266b408697b4 100644 (file)
@@ -201,6 +201,12 @@ export default {
                        appDescription: 'Tournaments and tutorials for The Legend of Zelda: A Link to the Past Randomizer',
                        appName: 'ALttP',
                        pleaseSelect: 'Please select',
+                       languages: {
+                               de: 'German',
+                               en: 'English',
+                               es: 'Spanish',
+                               fr: 'French',
+                       },
                },
                icon: {
                        AddIcon: 'Add',
@@ -745,6 +751,7 @@ export default {
                                winnersMessageHint: '{names} will be replaced with a list of winners\' names',
                        },
                        heading: 'Twitch Bot',
+                       language: 'Preferred Language',
                        joinApp: 'Join as App Bot',
                        joinChat: 'Join as Chat Bot',
                        joinError: 'Error joining channel',
@@ -752,6 +759,12 @@ export default {
                        noManagePermission: 'You lack the required privileges to manage the twitch bot.',
                        partError: 'Error parting channel',
                        partSuccess: 'Parted',
+                       respond: 'Respond',
+                       respondOptions: {
+                               50: '50:50',
+                               no: 'No',
+                               yes: 'Yes',
+                       },
                        saveError: 'Error saving',
                        saveSuccess: 'Saved',
                        selectChannel: 'Please select a channel to manage.',