bump version to 0.3.2 and minor changes

This commit is contained in:
Syping 2026-03-29 03:37:47 +02:00
parent 58028b6e82
commit ec1294a960
7 changed files with 25 additions and 29 deletions

View file

@ -18,7 +18,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
cmake_policy(VERSION 3.16...3.27) cmake_policy(VERSION 3.16...3.27)
project(dtranslatebot VERSION 0.3.1 LANGUAGES CXX) project(dtranslatebot VERSION 0.3.2 LANGUAGES CXX)
include(GNUInstallDirs) include(GNUInstallDirs)
# dtranslatebot Source files # dtranslatebot Source files

View file

@ -15,7 +15,7 @@ Open Source Discord Translation Bot
- [LibreTranslate](https://libretranslate.com/) (Default) - [LibreTranslate](https://libretranslate.com/) (Default)
- [Lingva Translate](https://lingva.ml/) - [Lingva Translate](https://lingva.ml/)
- [Mozhi](https://codeberg.org/aryak/mozhi) - [Mozhi](https://codeberg.org/aryak/mozhi)
- [DeepL](https://deepl.com/) (Experimental) - [DeepL](https://deepl.com/)
#### Build dtranslatebot #### Build dtranslatebot

View file

@ -15,7 +15,7 @@
%endif %endif
Name: dtranslatebot Name: dtranslatebot
Version: 0.3.1 Version: 0.3.2
Release: 1%{?dist} Release: 1%{?dist}
Summary: Discord Translation Bot Summary: Discord Translation Bot
License: BSD-2-Clause License: BSD-2-Clause

View file

@ -22,7 +22,6 @@
#include "deepl.h" #include "deepl.h"
using namespace bot::translator; using namespace bot::translator;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace std::string_literals;
deepl::deepl(const std::string &hostname, const std::string apiKey) : deepl::deepl(const std::string &hostname, const std::string apiKey) :
m_hostname(hostname), m_apiKey(apiKey) m_hostname(hostname), m_apiKey(apiKey)
@ -44,7 +43,7 @@ const std::vector<language> deepl::get_languages()
try { try {
http_request request; http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target"s, true), { {"Authorization"s, "DeepL-Auth-Key "s + m_apiKey} }); http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target", true), { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_array()) { if (json_response.is_array()) {
@ -84,20 +83,20 @@ const std::vector<language> deepl::get_languages()
const std::string deepl::translate(const std::string &text, const std::string &source, const std::string &target) const std::string deepl::translate(const std::string &text, const std::string &source, const std::string &target)
{ {
const dpp::http_headers http_headers = { const dpp::http_headers http_headers = {
{"Authorization"s, "DeepL-Auth-Key " + m_apiKey}, {"Authorization", "DeepL-Auth-Key " + m_apiKey},
{"Content-Type"s, "application/json"s} {"Content-Type", "application/json"}
}; };
dpp::json json_body = { dpp::json json_body = {
{"text"s, { text } }, {"text", { text } },
{"target_lang"s, target} {"target_lang", target}
}; };
if (!source.empty()) if (!source.empty())
json_body["source_lang"] = source; json_body["source_lang"] = source;
try { try {
http_request request; http_request request;
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(), "application/json", { {"Authorization"s, "DeepL-Auth-Key " + m_apiKey} }); http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(), "application/json", { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_object()) { if (json_response.is_object()) {

View file

@ -22,7 +22,6 @@
#include "libretranslate.h" #include "libretranslate.h"
using namespace bot::translator; using namespace bot::translator;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace std::string_literals;
libretranslate::libretranslate(const std::string &hostname, uint16_t port, const std::string &url, bool tls, const std::string apiKey) : libretranslate::libretranslate(const std::string &hostname, uint16_t port, const std::string &url, bool tls, const std::string apiKey) :
m_hostname(hostname), m_port(port), m_url(url), m_tls(tls), m_apiKey(apiKey) m_hostname(hostname), m_port(port), m_url(url), m_tls(tls), m_apiKey(apiKey)
@ -44,7 +43,7 @@ const std::vector<language> libretranslate::get_languages()
try { try {
http_request request; http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "languages"s, m_tls)); http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "languages", m_tls));
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_array()) { if (json_response.is_array()) {
@ -79,14 +78,14 @@ const std::vector<language> libretranslate::get_languages()
const std::string libretranslate::translate(const std::string &text, const std::string &source, const std::string &target) const std::string libretranslate::translate(const std::string &text, const std::string &source, const std::string &target)
{ {
const dpp::http_headers http_headers = { const dpp::http_headers http_headers = {
{"Content-Type"s, "application/json"s} {"Content-Type", "application/json"}
}; };
dpp::json json_body = { dpp::json json_body = {
{"q"s, text}, {"q", text},
{"source"s, source.empty() ? "auto"s : source}, {"source", source.empty() ? "auto" : source},
{"target"s, target}, {"target", target},
{"format"s, "text"s} {"format", "text"}
}; };
if (!m_apiKey.empty()) if (!m_apiKey.empty())
@ -94,7 +93,7 @@ const std::string libretranslate::translate(const std::string &text, const std::
try { try {
http_request request; http_request request;
http_response response = request.post(http_request::legacy_url(m_hostname, m_port, m_url + "translate"s, m_tls), json_body.dump(), "application/json"); http_response response = request.post(http_request::legacy_url(m_hostname, m_port, m_url + "translate", m_tls), json_body.dump(), "application/json");
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_object()) { if (json_response.is_object()) {

View file

@ -23,7 +23,6 @@
#include "lingvatranslate.h" #include "lingvatranslate.h"
using namespace bot::translator; using namespace bot::translator;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace std::string_literals;
lingvatranslate::lingvatranslate(const std::string &hostname, uint16_t port, const std::string &url, bool tls) : lingvatranslate::lingvatranslate(const std::string &hostname, uint16_t port, const std::string &url, bool tls) :
m_hostname(hostname), m_port(port), m_url(url), m_tls(tls) m_hostname(hostname), m_port(port), m_url(url), m_tls(tls)
@ -45,7 +44,7 @@ const std::vector<language> lingvatranslate::get_languages()
try { try {
http_request request; http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/languages/target"s, m_tls)); http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/languages/target", m_tls));
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_object()) { if (json_response.is_object()) {
@ -84,7 +83,7 @@ const std::string lingvatranslate::translate(const std::string &text, const std:
{ {
try { try {
http_request request; http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/"s + (source.empty() ? "auto"s : source) + "/"s + target + "/"s + dpp::utility::url_encode(text), m_tls)); http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/" + (source.empty() ? "auto" : source) + "/" + target + "/" + dpp::utility::url_encode(text), m_tls));
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_object()) { if (json_response.is_object()) {

View file

@ -23,7 +23,6 @@
#include "mozhi.h" #include "mozhi.h"
using namespace bot::translator; using namespace bot::translator;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace std::string_literals;
mozhi::mozhi(const std::string &hostname, uint16_t port, const std::string &url, bool tls, const std::string &engine) : mozhi::mozhi(const std::string &hostname, uint16_t port, const std::string &url, bool tls, const std::string &engine) :
m_hostname(hostname), m_port(port), m_url(url), m_tls(tls), m_engine(engine) m_hostname(hostname), m_port(port), m_url(url), m_tls(tls), m_engine(engine)
@ -45,10 +44,10 @@ const std::vector<language> mozhi::get_languages()
try { try {
const std::string parameters = dpp::utility::make_url_parameters({ const std::string parameters = dpp::utility::make_url_parameters({
{"engine"s, m_engine} {"engine", m_engine}
}); });
http_request request; http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/target_languages"s, m_tls)); http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/target_languages", m_tls));
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_array()) { if (json_response.is_array()) {
@ -84,13 +83,13 @@ const std::string mozhi::translate(const std::string &text, const std::string &s
{ {
try { try {
const std::string parameters = dpp::utility::make_url_parameters({ const std::string parameters = dpp::utility::make_url_parameters({
{"engine"s, m_engine}, {"engine", m_engine},
{"from"s, source.empty() ? "auto"s : source}, {"from", source.empty() ? "auto" : source},
{"to"s, target}, {"to", target},
{"text"s, text} {"text", text}
}); });
http_request request; http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/translate"s + parameters, m_tls)); http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/translate" + parameters, m_tls));
if (response.status == 200) { if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content); const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_object()) { if (json_response.is_object()) {