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',
->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();
}
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;
}
$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) {
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 = [];
</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">
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,
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,
});
},
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
? 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(),
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',
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',
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.',
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',
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',
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.',