mirror of
https://github.com/Syping/dtranslatebot.git
synced 2025-08-21 09:18:13 +02:00
Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
c76210a30c | ||
|
b2da36e576 | ||
|
13d384b14e | ||
|
2da43810a1 |
9 changed files with 21 additions and 13 deletions
cmake
src/translator
deepl
libretranslate
lingvatranslate
mozhi
|
@ -55,15 +55,14 @@ set(ZLIB_INSTALL_DIR "${INSTALL_DIR}")
|
|||
|
||||
set(OPENSSL_PLATFORM_ARG $<$<BOOL:$ENV{MSYSTEM}>:mingw64>)
|
||||
ExternalProject_Add(OpenSSL
|
||||
URL https://github.com/openssl/openssl/releases/download/openssl-3.0.15/openssl-3.0.15.tar.gz
|
||||
URL_HASH SHA256=23c666d0edf20f14249b3d8f0368acaee9ab585b09e1de82107c66e1f3ec9533
|
||||
URL https://github.com/openssl/openssl/releases/download/openssl-3.0.17/openssl-3.0.17.tar.gz
|
||||
URL_HASH SHA256=dfdd77e4ea1b57ff3a6dbde6b0bdc3f31db5ac99e7fdd4eaf9e1fbb6ec2db8ce
|
||||
CONFIGURE_COMMAND
|
||||
${CMAKE_PASSTHROUGH_ENV}
|
||||
"${PERL_EXECUTABLE}"
|
||||
"<SOURCE_DIR>/Configure"
|
||||
"--prefix=<INSTALL_DIR>"
|
||||
$<$<CONFIG:Debug>:-d>
|
||||
no-deprecated
|
||||
no-dso
|
||||
no-dtls
|
||||
no-engine
|
||||
|
@ -78,8 +77,8 @@ ExternalProject_Get_Property(OpenSSL INSTALL_DIR)
|
|||
set(OpenSSL_INSTALL_DIR "${INSTALL_DIR}")
|
||||
|
||||
ExternalProject_Add(DPP
|
||||
URL https://github.com/Syping/DPP/archive/067dfb0c5728432dd24f74375173cf0fc8cbc4ca.tar.gz
|
||||
URL_HASH SHA256=ea794219d32bc58eeb23536b3b18fbc119bd747773c6f7c98cf8e96e6d91693a
|
||||
URL https://github.com/brainboxdotcc/DPP/archive/refs/tags/v10.1.3.tar.gz
|
||||
URL_HASH SHA256=a32d94dcd6b23430afff82918234e4e28e0616bd2ddf743c5ab2f1778c5a600b
|
||||
CMAKE_ARGS
|
||||
-DAVX_TYPE=AVX0
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
|
@ -87,6 +86,7 @@ ExternalProject_Add(DPP
|
|||
${CMAKE_PASSTHROUGH_ARGS}
|
||||
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
|
||||
-DDPP_BUILD_TEST=OFF
|
||||
-DDPP_NO_CORO=ON
|
||||
-DDPP_NO_VCPKG=ON
|
||||
-DRUN_LDCONFIG=OFF
|
||||
"-DOpenSSL_ROOT=${OpenSSL_INSTALL_DIR}"
|
||||
|
|
|
@ -42,7 +42,7 @@ const std::vector<language> deepl::get_languages()
|
|||
}
|
||||
|
||||
try {
|
||||
dpp::https_client http_request(m_hostname, 443, "/v2/languages?type=target", "GET", {}, { {"Authorization"s, "DeepL-Auth-Key " + m_apiKey} }, false);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, 443, "/v2/languages?type=target", "GET", {}, { {"Authorization"s, "DeepL-Auth-Key " + m_apiKey} }, false);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_array()) {
|
||||
|
@ -93,7 +93,7 @@ const std::string deepl::translate(const std::string &text, const std::string &s
|
|||
};
|
||||
|
||||
try {
|
||||
dpp::https_client http_request(m_hostname, 443, "/v2/translate", "POST", json_body.dump(), http_headers, false);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, 443, "/v2/translate", "POST", json_body.dump(), http_headers, false);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_object()) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifndef TRANSLATOR_DEEPL_H
|
||||
#define TRANSLATOR_DEEPL_H
|
||||
|
||||
#include <dpp/cluster.h>
|
||||
#include "../../core/translator.h"
|
||||
|
||||
namespace bot {
|
||||
|
@ -31,6 +32,7 @@ namespace bot {
|
|||
const std::string translate(const std::string &text, const std::string &source, const std::string &target) override;
|
||||
|
||||
private:
|
||||
dpp::cluster m_cluster;
|
||||
std::string m_apiKey;
|
||||
std::string m_hostname;
|
||||
supported_languages m_languages;
|
||||
|
|
|
@ -42,7 +42,7 @@ const std::vector<language> libretranslate::get_languages()
|
|||
}
|
||||
|
||||
try {
|
||||
dpp::https_client http_request(m_hostname, m_port, m_url + "languages", "GET", {}, {}, !m_tls);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, m_port, m_url + "languages", "GET", {}, {}, !m_tls);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_array()) {
|
||||
|
@ -91,7 +91,7 @@ const std::string libretranslate::translate(const std::string &text, const std::
|
|||
json_body["apiKey"] = m_apiKey;
|
||||
|
||||
try {
|
||||
dpp::https_client http_request(m_hostname, m_port, m_url + "translate", "POST", json_body.dump(), http_headers, !m_tls);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, m_port, m_url + "translate", "POST", json_body.dump(), http_headers, !m_tls);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_object()) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define TRANSLATOR_LIBRETRANSLATE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <dpp/cluster.h>
|
||||
#include "../../core/translator.h"
|
||||
|
||||
namespace bot {
|
||||
|
@ -33,6 +34,7 @@ namespace bot {
|
|||
const std::string translate(const std::string &text, const std::string &source, const std::string &target) override;
|
||||
|
||||
private:
|
||||
dpp::cluster m_cluster;
|
||||
std::string m_apiKey;
|
||||
std::string m_hostname;
|
||||
supported_languages m_languages;
|
||||
|
|
|
@ -43,7 +43,7 @@ const std::vector<language> lingvatranslate::get_languages()
|
|||
}
|
||||
|
||||
try {
|
||||
dpp::https_client http_request(m_hostname, m_port, m_url + "api/v1/languages/target", "GET", {}, {}, !m_tls);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, m_port, m_url + "api/v1/languages/target", "GET", {}, {}, !m_tls);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_object()) {
|
||||
|
@ -81,7 +81,7 @@ const std::vector<language> lingvatranslate::get_languages()
|
|||
const std::string lingvatranslate::translate(const std::string &text, const std::string &source, const std::string &target)
|
||||
{
|
||||
try {
|
||||
dpp::https_client http_request(m_hostname, m_port, m_url + "api/v1/" + source + "/" + target + "/" + dpp::utility::url_encode(text), "GET", {}, {}, !m_tls);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, m_port, m_url + "api/v1/" + source + "/" + target + "/" + dpp::utility::url_encode(text), "GET", {}, {}, !m_tls);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_object()) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define TRANSLATOR_LINGVATRANSLATE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <dpp/cluster.h>
|
||||
#include "../../core/translator.h"
|
||||
|
||||
namespace bot {
|
||||
|
@ -33,6 +34,7 @@ namespace bot {
|
|||
const std::string translate(const std::string &text, const std::string &source, const std::string &target) override;
|
||||
|
||||
private:
|
||||
dpp::cluster m_cluster;
|
||||
std::string m_hostname;
|
||||
supported_languages m_languages;
|
||||
uint16_t m_port;
|
||||
|
|
|
@ -46,7 +46,7 @@ const std::vector<language> mozhi::get_languages()
|
|||
const std::string parameters = dpp::utility::make_url_parameters({
|
||||
{"engine"s, m_engine}
|
||||
});
|
||||
dpp::https_client http_request(m_hostname, m_port, m_url + "api/target_languages" + parameters, "GET", {}, {}, !m_tls);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, m_port, m_url + "api/target_languages" + parameters, "GET", {}, {}, !m_tls);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_array()) {
|
||||
|
@ -87,7 +87,7 @@ const std::string mozhi::translate(const std::string &text, const std::string &s
|
|||
{"to"s, target},
|
||||
{"text"s, text},
|
||||
});
|
||||
dpp::https_client http_request(m_hostname, m_port, m_url + "api/translate" + parameters, "GET", {}, {}, !m_tls);
|
||||
dpp::https_client http_request(&m_cluster, m_hostname, m_port, m_url + "api/translate" + parameters, "GET", {}, {}, !m_tls);
|
||||
if (http_request.get_status() == 200) {
|
||||
const dpp::json response = dpp::json::parse(http_request.get_content());
|
||||
if (response.is_object()) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define TRANSLATOR_MOZHI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <dpp/cluster.h>
|
||||
#include "../../core/translator.h"
|
||||
|
||||
namespace bot {
|
||||
|
@ -33,6 +34,7 @@ namespace bot {
|
|||
const std::string translate(const std::string &text, const std::string &source, const std::string &target) override;
|
||||
|
||||
private:
|
||||
dpp::cluster m_cluster;
|
||||
std::string m_engine;
|
||||
std::string m_hostname;
|
||||
supported_languages m_languages;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue