chore(release): v0.1.7
Set HttpClient version to HTTP/1.1 in ProfanityChecker.java
This commit is contained in:
parent
ce52c98668
commit
7ae321a413
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
### Исправлено
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue