diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d35e1f..1a2c879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/). +## [0.1.7] - 2024-10-23 + +### Changed + +- **ProfanityChecker.java**: + - Set HTTP version to HTTP/1.1 for HttpClient. + ## [0.1.6] - 2024-10-21 ### Fixed diff --git a/CHANGELOG.ru.md b/CHANGELOG.ru.md index d31a001..2a8edfc 100644 --- a/CHANGELOG.ru.md +++ b/CHANGELOG.ru.md @@ -4,6 +4,13 @@ Формат основан на [Keep a Changelog](https://keepachangelog.com/ru/1.0.0/), и этот проект придерживается [Семантического Версионирования](https://semver.org/lang/ru/). +## [0.1.7] - 2024-10-23 + +### Изменено + +- **ProfanityChecker.java**: + - Установлена версия HTTP на HTTP/1.1 для HttpClient. + ## [0.1.6] - 2024-10-21 ### Исправлено diff --git a/gradle.properties b/gradle.properties index 8f296af..0105d59 100644 --- a/gradle.properties +++ b/gradle.properties @@ -38,7 +38,7 @@ mod_name=ChatIT # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=0.1.6-BETA +mod_version=0.1.7-BETA # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/org/itqop/chatit/utils/ProfanityChecker.java b/src/main/java/org/itqop/chatit/utils/ProfanityChecker.java index f11f4b4..12eb8f7 100644 --- a/src/main/java/org/itqop/chatit/utils/ProfanityChecker.java +++ b/src/main/java/org/itqop/chatit/utils/ProfanityChecker.java @@ -12,6 +12,7 @@ import org.slf4j.Logger; import com.mojang.logging.LogUtils; import com.google.gson.Gson; +import com.google.gson.JsonObject; public class ProfanityChecker { @@ -29,20 +30,16 @@ public class ProfanityChecker { if (apiUrl == null || apiUrl.isEmpty()) { if (useRegex) { - if (containsProfanity(message)) { - return 1.0; - } else { - return 0.0; - } + return containsProfanity(message) ? 1.0 : 0.0; } else { return 0.0; } } String jsonRequest = GSON.toJson(new MessageRequest(message)); - HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(apiUrl)) + .version(HttpClient.Version.HTTP_1_1) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonRequest, StandardCharsets.UTF_8)) .build(); @@ -51,13 +48,17 @@ public class ProfanityChecker { String responseBody = response.body(); - return Double.parseDouble(responseBody); + if (response.statusCode() != 200) { + throw new RuntimeException("Ошибка API: " + responseBody); + } + + JsonObject jsonResponse = GSON.fromJson(responseBody, JsonObject.class); + + return jsonResponse.get("toxicity_score").getAsDouble(); } catch (Exception e) { LOGGER.error(e.toString()); if (Config.useRegex) { - if (containsProfanity(message)) { - return 1.0; - } + return containsProfanity(message) ? 1.0 : 0.0; } return 0.0; } @@ -72,8 +73,18 @@ public class ProfanityChecker { } private static class MessageRequest { + private String text; public MessageRequest(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; } } }