Add fxtwitter, ignore links, HTML tags
This commit is contained in:
@@ -39,6 +39,25 @@ class GenericmessageCommand extends SystemCommand
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
|
||||
// Handle Twitter link
|
||||
preg_match('/^https?:\/\/(?:mobile\.)?(?:x|twitter)\.com\/(\w+)\/status\/(\d+)(\S*)$/', $text, $matches);
|
||||
if (count($matches) >= 3) {
|
||||
$author = $matches[1];
|
||||
$tweetId = $matches[2];
|
||||
$photoNoText = '';
|
||||
if (!empty($matches[3])) {
|
||||
preg_match('/(\/\d)$/', $matches[3], $photoNoMatches);
|
||||
if (isset($photoNoMatches[1])) {
|
||||
$photoNoText = '/photo' . $photoNoMatches[1];
|
||||
}
|
||||
}
|
||||
return $this->replyToChat("https://fxtwitter.com/$author/status/$tweetId$photoNoText", ['disable_notification' => true]);
|
||||
}
|
||||
|
||||
if (preg_match('/^https?:\/\/\S+$/', $text)) { // Just URL and nothing else
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
|
||||
$text_chara_count = count(preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY));
|
||||
$text_english_count = count(preg_split('~[^a-z 0-9\'\",.]*~i', $text, 0, PREG_SPLIT_NO_EMPTY));
|
||||
if ($text_english_count >= ($text_chara_count * 2 / 3)) {
|
||||
@@ -53,6 +72,7 @@ class GenericmessageCommand extends SystemCommand
|
||||
TranslateTextOptions::FORMALITY => 'prefer_less',
|
||||
TranslateTextOptions::MODEL_TYPE => 'prefer_quality_optimized',
|
||||
TranslateTextOptions::SPLIT_SENTENCES => 'on',
|
||||
TranslateTextOptions::TAG_HANDLING => 'html', // Somehow make it preserve new line
|
||||
];
|
||||
if ($htmlMode) {
|
||||
$deeplOptions[TranslateTextOptions::TAG_HANDLING] = 'html';
|
||||
|
||||
Reference in New Issue
Block a user