Parse markdown

This commit is contained in:
2025-04-04 01:02:00 +00:00
parent eb8653696e
commit ec03f11b93
3 changed files with 146 additions and 141 deletions

View File

@@ -5,7 +5,7 @@
"php": ">=8.1", "php": ">=8.1",
"deeplcom/deepl-php": "^1.1.0", "deeplcom/deepl-php": "^1.1.0",
"longman/telegram-bot": "*", "longman/telegram-bot": "*",
"steelywing/chinese": "^0.5.3" "lucadevelop/telegram-entities-decoder": "^1.3"
}, },
"config": { "config": {
"allow-plugins": { "allow-plugins": {

262
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a0a65830cd3d7e541e4610730263798f", "content-hash": "be8152ca483086150648bd025aef879e",
"packages": [ "packages": [
{ {
"name": "deeplcom/deepl-php", "name": "deeplcom/deepl-php",
@@ -71,22 +71,22 @@
}, },
{ {
"name": "guzzlehttp/guzzle", "name": "guzzlehttp/guzzle",
"version": "7.5.0", "version": "7.9.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/guzzle/guzzle.git", "url": "https://github.com/guzzle/guzzle.git",
"reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba" "reference": "7b2f29fe81dc4da0ca0ea7d42107a0845946ea77"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/b50a2a1251152e43f6a37f0fa053e730a67d25ba", "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7b2f29fe81dc4da0ca0ea7d42107a0845946ea77",
"reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba", "reference": "7b2f29fe81dc4da0ca0ea7d42107a0845946ea77",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"guzzlehttp/promises": "^1.5", "guzzlehttp/promises": "^1.5.3 || ^2.0.3",
"guzzlehttp/psr7": "^1.9 || ^2.4", "guzzlehttp/psr7": "^2.7.0",
"php": "^7.2.5 || ^8.0", "php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0", "psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0" "symfony/deprecation-contracts": "^2.2 || ^3.0"
@@ -95,10 +95,11 @@
"psr/http-client-implementation": "1.0" "psr/http-client-implementation": "1.0"
}, },
"require-dev": { "require-dev": {
"bamarni/composer-bin-plugin": "^1.8.1", "bamarni/composer-bin-plugin": "^1.8.2",
"ext-curl": "*", "ext-curl": "*",
"php-http/client-integration-tests": "^3.0", "guzzle/client-integration-tests": "3.0.2",
"phpunit/phpunit": "^8.5.29 || ^9.5.23", "php-http/message-factory": "^1.1",
"phpunit/phpunit": "^8.5.39 || ^9.6.20",
"psr/log": "^1.1 || ^2.0 || ^3.0" "psr/log": "^1.1 || ^2.0 || ^3.0"
}, },
"suggest": { "suggest": {
@@ -111,9 +112,6 @@
"bamarni-bin": { "bamarni-bin": {
"bin-links": true, "bin-links": true,
"forward-command": false "forward-command": false
},
"branch-alias": {
"dev-master": "7.5-dev"
} }
}, },
"autoload": { "autoload": {
@@ -179,7 +177,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/guzzle/guzzle/issues", "issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.5.0" "source": "https://github.com/guzzle/guzzle/tree/7.9.3"
}, },
"funding": [ "funding": [
{ {
@@ -195,38 +193,37 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-08-28T15:39:27+00:00" "time": "2025-03-27T13:37:11+00:00"
}, },
{ {
"name": "guzzlehttp/promises", "name": "guzzlehttp/promises",
"version": "1.5.2", "version": "2.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/guzzle/promises.git", "url": "https://github.com/guzzle/promises.git",
"reference": "b94b2807d85443f9719887892882d0329d1e2598" "reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/b94b2807d85443f9719887892882d0329d1e2598", "url": "https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c",
"reference": "b94b2807d85443f9719887892882d0329d1e2598", "reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.5" "php": "^7.2.5 || ^8.0"
}, },
"require-dev": { "require-dev": {
"symfony/phpunit-bridge": "^4.4 || ^5.1" "bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "bamarni-bin": {
"dev-master": "1.5-dev" "bin-links": true,
"forward-command": false
} }
}, },
"autoload": { "autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": { "psr-4": {
"GuzzleHttp\\Promise\\": "src/" "GuzzleHttp\\Promise\\": "src/"
} }
@@ -263,7 +260,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/guzzle/promises/issues", "issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/1.5.2" "source": "https://github.com/guzzle/promises/tree/2.2.0"
}, },
"funding": [ "funding": [
{ {
@@ -279,26 +276,26 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-08-28T14:55:35+00:00" "time": "2025-03-27T13:27:01+00:00"
}, },
{ {
"name": "guzzlehttp/psr7", "name": "guzzlehttp/psr7",
"version": "2.4.1", "version": "2.7.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/guzzle/psr7.git", "url": "https://github.com/guzzle/psr7.git",
"reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379" "reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/69568e4293f4fa993f3b0e51c9723e1e17c41379", "url": "https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16",
"reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379", "reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.2.5 || ^8.0", "php": "^7.2.5 || ^8.0",
"psr/http-factory": "^1.0", "psr/http-factory": "^1.0",
"psr/http-message": "^1.0", "psr/http-message": "^1.1 || ^2.0",
"ralouphie/getallheaders": "^3.0" "ralouphie/getallheaders": "^3.0"
}, },
"provide": { "provide": {
@@ -306,9 +303,9 @@
"psr/http-message-implementation": "1.0" "psr/http-message-implementation": "1.0"
}, },
"require-dev": { "require-dev": {
"bamarni/composer-bin-plugin": "^1.8.1", "bamarni/composer-bin-plugin": "^1.8.2",
"http-interop/http-factory-tests": "^0.9", "http-interop/http-factory-tests": "0.9.0",
"phpunit/phpunit": "^8.5.29 || ^9.5.23" "phpunit/phpunit": "^8.5.39 || ^9.6.20"
}, },
"suggest": { "suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
@@ -318,9 +315,6 @@
"bamarni-bin": { "bamarni-bin": {
"bin-links": true, "bin-links": true,
"forward-command": false "forward-command": false
},
"branch-alias": {
"dev-master": "2.4-dev"
} }
}, },
"autoload": { "autoload": {
@@ -382,7 +376,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/guzzle/psr7/issues", "issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.4.1" "source": "https://github.com/guzzle/psr7/tree/2.7.1"
}, },
"funding": [ "funding": [
{ {
@@ -398,20 +392,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-08-28T14:45:39+00:00" "time": "2025-03-27T12:30:47+00:00"
}, },
{ {
"name": "longman/telegram-bot", "name": "longman/telegram-bot",
"version": "0.79.0", "version": "0.83.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-telegram-bot/core.git", "url": "https://github.com/php-telegram-bot/core.git",
"reference": "097177ca85627bfa5d0d9e679714a0b1353d49de" "reference": "ca9eeb1c9e51c39a33070efeba01aac105ed9aa7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-telegram-bot/core/zipball/097177ca85627bfa5d0d9e679714a0b1353d49de", "url": "https://api.github.com/repos/php-telegram-bot/core/zipball/ca9eeb1c9e51c39a33070efeba01aac105ed9aa7",
"reference": "097177ca85627bfa5d0d9e679714a0b1353d49de", "reference": "ca9eeb1c9e51c39a33070efeba01aac105ed9aa7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -420,7 +414,7 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-pdo": "*", "ext-pdo": "*",
"guzzlehttp/guzzle": "^6.0|^7.0", "guzzlehttp/guzzle": "^6.0|^7.0",
"php": "^7.3|^8.0", "php": "^8.1",
"psr/log": "^1.1|^2.0|^3.0" "psr/log": "^1.1|^2.0|^3.0"
}, },
"require-dev": { "require-dev": {
@@ -430,6 +424,11 @@
"squizlabs/php_codesniffer": "^3.6" "squizlabs/php_codesniffer": "^3.6"
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-develop": "0.83.x-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Longman\\TelegramBot\\": "src" "Longman\\TelegramBot\\": "src"
@@ -499,7 +498,48 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-09-04T13:22:41+00:00" "time": "2024-05-30T21:05:25+00:00"
},
{
"name": "lucadevelop/telegram-entities-decoder",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/LucaDevelop/telegram-entities-decoder.git",
"reference": "32cbdce21d02306c75708d6fbb1b3241069b018e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LucaDevelop/telegram-entities-decoder/zipball/32cbdce21d02306c75708d6fbb1b3241069b018e",
"reference": "32cbdce21d02306c75708d6fbb1b3241069b018e",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=7.0.0"
},
"type": "library",
"autoload": {
"psr-4": {
"lucadevelop\\TelegramEntitiesDecoder\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "LucaDevelop",
"email": "lsirri.gm@gmail.com"
}
],
"description": "Telegram entities decoder in PHP",
"support": {
"issues": "https://github.com/LucaDevelop/telegram-entities-decoder/issues",
"source": "https://github.com/LucaDevelop/telegram-entities-decoder/tree/v1.3.1"
},
"time": "2024-02-01T17:06:13+00:00"
}, },
{ {
"name": "php-http/discovery", "name": "php-http/discovery",
@@ -638,21 +678,21 @@
}, },
{ {
"name": "psr/http-client", "name": "psr/http-client",
"version": "1.0.1", "version": "1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-client.git", "url": "https://github.com/php-fig/http-client.git",
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.0 || ^8.0", "php": "^7.0 || ^8.0",
"psr/http-message": "^1.0" "psr/http-message": "^1.0 || ^2.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@@ -672,7 +712,7 @@
"authors": [ "authors": [
{ {
"name": "PHP-FIG", "name": "PHP-FIG",
"homepage": "http://www.php-fig.org/" "homepage": "https://www.php-fig.org/"
} }
], ],
"description": "Common interface for HTTP clients", "description": "Common interface for HTTP clients",
@@ -684,27 +724,27 @@
"psr-18" "psr-18"
], ],
"support": { "support": {
"source": "https://github.com/php-fig/http-client/tree/master" "source": "https://github.com/php-fig/http-client"
}, },
"time": "2020-06-29T06:28:15+00:00" "time": "2023-09-23T14:17:50+00:00"
}, },
{ {
"name": "psr/http-factory", "name": "psr/http-factory",
"version": "1.0.1", "version": "1.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-factory.git", "url": "https://github.com/php-fig/http-factory.git",
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=7.0.0", "php": ">=7.1",
"psr/http-message": "^1.0" "psr/http-message": "^1.0 || ^2.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@@ -724,10 +764,10 @@
"authors": [ "authors": [
{ {
"name": "PHP-FIG", "name": "PHP-FIG",
"homepage": "http://www.php-fig.org/" "homepage": "https://www.php-fig.org/"
} }
], ],
"description": "Common interfaces for PSR-7 HTTP message factories", "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories",
"keywords": [ "keywords": [
"factory", "factory",
"http", "http",
@@ -739,31 +779,31 @@
"response" "response"
], ],
"support": { "support": {
"source": "https://github.com/php-fig/http-factory/tree/master" "source": "https://github.com/php-fig/http-factory"
}, },
"time": "2019-04-30T12:38:16+00:00" "time": "2024-04-15T12:06:14+00:00"
}, },
{ {
"name": "psr/http-message", "name": "psr/http-message",
"version": "1.0.1", "version": "2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-message.git", "url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.0" "php": "^7.2 || ^8.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0.x-dev" "dev-master": "2.0.x-dev"
} }
}, },
"autoload": { "autoload": {
@@ -778,7 +818,7 @@
"authors": [ "authors": [
{ {
"name": "PHP-FIG", "name": "PHP-FIG",
"homepage": "http://www.php-fig.org/" "homepage": "https://www.php-fig.org/"
} }
], ],
"description": "Common interface for HTTP messages", "description": "Common interface for HTTP messages",
@@ -792,22 +832,22 @@
"response" "response"
], ],
"support": { "support": {
"source": "https://github.com/php-fig/http-message/tree/master" "source": "https://github.com/php-fig/http-message/tree/2.0"
}, },
"time": "2016-08-06T14:39:51+00:00" "time": "2023-04-04T09:54:51+00:00"
}, },
{ {
"name": "psr/log", "name": "psr/log",
"version": "3.0.0", "version": "3.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/log.git", "url": "https://github.com/php-fig/log.git",
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3",
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -842,9 +882,9 @@
"psr-3" "psr-3"
], ],
"support": { "support": {
"source": "https://github.com/php-fig/log/tree/3.0.0" "source": "https://github.com/php-fig/log/tree/3.0.2"
}, },
"time": "2021-07-14T16:46:02+00:00" "time": "2024-09-11T13:17:53+00:00"
}, },
{ {
"name": "ralouphie/getallheaders", "name": "ralouphie/getallheaders",
@@ -890,58 +930,18 @@
}, },
"time": "2019-03-08T08:55:37+00:00" "time": "2019-03-08T08:55:37+00:00"
}, },
{
"name": "steelywing/chinese",
"version": "0.5.3",
"source": {
"type": "git",
"url": "https://github.com/steelywing/PHP-Chinese.git",
"reference": "8ff0b4c1275718222f5ffd3991dddab1af06be1d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/steelywing/PHP-Chinese/zipball/8ff0b4c1275718222f5ffd3991dddab1af06be1d",
"reference": "8ff0b4c1275718222f5ffd3991dddab1af06be1d",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-4": {
"SteelyWing\\Chinese\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Steely Wing",
"email": "steely.wing@gmail.com"
}
],
"description": "中文繁簡轉換 Convert Traditional and Simplified Chinese",
"support": {
"issues": "https://github.com/steelywing/PHP-Chinese/issues",
"source": "https://github.com/steelywing/PHP-Chinese/tree/0.5.3"
},
"time": "2019-06-10T01:58:44+00:00"
},
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
"version": "v3.1.1", "version": "v3.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git", "url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918" "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
"reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -949,12 +949,12 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "3.1-dev"
},
"thanks": { "thanks": {
"name": "symfony/contracts", "url": "https://github.com/symfony/contracts",
"url": "https://github.com/symfony/contracts" "name": "symfony/contracts"
},
"branch-alias": {
"dev-main": "3.5-dev"
} }
}, },
"autoload": { "autoload": {
@@ -979,7 +979,7 @@
"description": "A generic function and convention to trigger deprecation notices", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.1.1" "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
}, },
"funding": [ "funding": [
{ {
@@ -995,7 +995,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-02-25T11:15:52+00:00" "time": "2024-09-25T14:20:29+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

View File

@@ -6,7 +6,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
use DeepL\Translator; use DeepL\Translator;
use SteelyWing\Chinese\Chinese; use DeepL\TranslateTextOptions;
use lucadevelop\TelegramEntitiesDecoder\EntityDecoder;
// This class name is magic // This class name is magic
class GenericmessageCommand extends SystemCommand class GenericmessageCommand extends SystemCommand
@@ -39,26 +40,30 @@ class GenericmessageCommand extends SystemCommand
$text_english_count = count(preg_split('~[^a-z 0-9\'\",.]*~i', $text, 0, 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)) { if ($text_english_count >= ($text_chara_count*2 /3)) {
$sourceLang = 'en'; $sourceLang = 'en';
$targetLang = 'zh'; $targetLang = 'zh-hans';
} else { } else {
$sourceLang = 'zh'; $sourceLang = 'zh';
$targetLang = 'en-US'; $targetLang = 'en-US';
$text = (new Chinese())->to(Chinese::ZH_HANS, $text);
} }
$deeplOptions = [ $deeplOptions = [
'formality' => 'prefer_less', TranslateTextOptions::FORMALITY => 'prefer_less',
'model_type' => 'prefer_quality_optimized', TranslateTextOptions::MODEL_TYPE => 'prefer_quality_optimized',
TranslateTextOptions::TAG_HANDLING => 'html',
]; ];
try { try {
$glosasaryConfig = json_decode(file_get_contents(__DIR__ . '/../../glossary.json'), true); $glosasaryConfig = json_decode(file_get_contents(__DIR__ . '/../../glossary.json'), true);
if (isset($glosasaryConfig[$sourceLang][$targetLang])) { $targetLangKey = explode('-', $targetLang)[0];
$deeplOptions['glossary'] = $glosasaryConfig[$sourceLang][$targetLang]; if (isset($glosasaryConfig[$sourceLang][$targetLangKey])) {
$deeplOptions[TranslateTextOptions::GLOSSARY] = $glosasaryConfig[$sourceLang][$targetLangKey];
} }
} catch(\Exception $e) {} } catch(\Exception $e) {}
$this->translator = new Translator($deepl_api_key); $this->translator = new Translator($deepl_api_key);
try { try {
$translated = $this->translator->translateText($text, $sourceLang, $targetLang, $deeplOptions); $decoded_text = (new EntityDecoder('HTML'))->decode(json_decode($message->toJson()));
$translated = $this->translator->translateText($decoded_text, $sourceLang, $targetLang, $deeplOptions);
$translated = $translated->text;
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->replyToChat(get_class($e) . ': ' . $e->getMessage()); // ?? var_export($e, true) return $this->replyToChat(get_class($e) . ': ' . $e->getMessage()); // ?? var_export($e, true)
} }
@@ -68,6 +73,6 @@ class GenericmessageCommand extends SystemCommand
$translated = $message_forwarded_from . ': ' . $translated; $translated = $message_forwarded_from . ': ' . $translated;
} }
return $this->replyToChat($translated, ['disable_notification' => true]); return $this->replyToChat($translated, ['disable_notification' => true, 'parse_mode' => 'HTML']);
} }
} }