fix: add rule34 API credentials support (required since Aug 2025)
This commit is contained in:
parent
28ce94b0ca
commit
7055fcb00d
6 changed files with 40 additions and 5 deletions
|
|
@ -18,6 +18,8 @@ public class BotConfig {
|
|||
private final int aiDossierUpdateHours;
|
||||
private final String aiDebateChannelId;
|
||||
private final LavalinkConfig lavalinkConfig;
|
||||
private final String r34ApiKey;
|
||||
private final String r34UserId;
|
||||
|
||||
public BotConfig(
|
||||
String mainToken,
|
||||
|
|
@ -36,7 +38,9 @@ public class BotConfig {
|
|||
int aiDossierMsgs,
|
||||
int aiDossierUpdateHours,
|
||||
String aiDebateChannelId,
|
||||
LavalinkConfig lavalinkConfig) {
|
||||
LavalinkConfig lavalinkConfig,
|
||||
String r34ApiKey,
|
||||
String r34UserId) {
|
||||
this.mainToken = mainToken;
|
||||
this.musicToken = musicToken;
|
||||
this.radioToken = radioToken;
|
||||
|
|
@ -54,6 +58,8 @@ public class BotConfig {
|
|||
this.aiDossierUpdateHours = aiDossierUpdateHours;
|
||||
this.aiDebateChannelId = aiDebateChannelId;
|
||||
this.lavalinkConfig = lavalinkConfig;
|
||||
this.r34ApiKey = r34ApiKey;
|
||||
this.r34UserId = r34UserId;
|
||||
}
|
||||
|
||||
public String getMainToken() {
|
||||
|
|
@ -127,4 +133,12 @@ public class BotConfig {
|
|||
public LavalinkConfig getLavalinkConfig() {
|
||||
return lavalinkConfig;
|
||||
}
|
||||
|
||||
public String getR34ApiKey() {
|
||||
return r34ApiKey;
|
||||
}
|
||||
|
||||
public String getR34UserId() {
|
||||
return r34UserId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ public final class ConfigLoader {
|
|||
int aiDossierUpdateHours = Integer.parseInt(getEnv(dotenv, "AI_DOSSIER_UPDATE_HOURS", "24"));
|
||||
String aiDebateChannelId = dotenv.get("AI_DEBATE_CHANNEL_ID");
|
||||
|
||||
String r34ApiKey = getEnv(dotenv, "R34_API_KEY", "");
|
||||
String r34UserId = getEnv(dotenv, "R34_USER_ID", "");
|
||||
|
||||
LavalinkConfig lavalinkConfig = getLavalinkConfig();
|
||||
LoggerDecorator.success(logger, "Конфигурация загружена успешно");
|
||||
return new BotConfig(
|
||||
|
|
@ -102,6 +105,8 @@ public final class ConfigLoader {
|
|||
aiDossierMsgs,
|
||||
aiDossierUpdateHours,
|
||||
aiDebateChannelId,
|
||||
lavalinkConfig);
|
||||
lavalinkConfig,
|
||||
r34ApiKey,
|
||||
r34UserId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package creator.loki.feature.image;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import creator.loki.config.BotConfig;
|
||||
|
||||
public class ImageModule extends AbstractModule {
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ public class ImageModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
ImageService provideImageService() {
|
||||
return new ImageService();
|
||||
ImageService provideImageService(BotConfig config) {
|
||||
return new ImageService(config);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.google.gson.JsonObject;
|
|||
import com.google.gson.JsonParser;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import creator.loki.config.BotConfig;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
|
@ -25,9 +26,13 @@ public class ImageService {
|
|||
"https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1";
|
||||
|
||||
private final OkHttpClient client;
|
||||
private final String r34ApiKey;
|
||||
private final String r34UserId;
|
||||
|
||||
@Inject
|
||||
public ImageService() {
|
||||
public ImageService(BotConfig config) {
|
||||
this.r34ApiKey = config.getR34ApiKey();
|
||||
this.r34UserId = config.getR34UserId();
|
||||
this.client =
|
||||
new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
|
|
@ -88,6 +93,9 @@ public class ImageService {
|
|||
int capped = Math.min(limit, 100);
|
||||
String url =
|
||||
R34_API + "&tags=" + encodeTags(tags) + "&limit=" + capped + "&pid=" + (page - 1);
|
||||
if (!r34ApiKey.isEmpty() && !r34UserId.isEmpty()) {
|
||||
url += "&api_key=" + r34ApiKey + "&user_id=" + r34UserId;
|
||||
}
|
||||
return fetchBooruJson(url, limit);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue