->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 = [];