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
|
|
@ -35,3 +35,8 @@ LAVALINK_ENABLED=true
|
||||||
# === Spotify (для LavaSrc) ===
|
# === Spotify (для LavaSrc) ===
|
||||||
SPOTIFY_CLIENT_ID=your_spotify_client_id
|
SPOTIFY_CLIENT_ID=your_spotify_client_id
|
||||||
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
|
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
|
||||||
|
|
||||||
|
# === Rule34 API (обязательно с Aug 2025) ===
|
||||||
|
# Получить: https://rule34.xxx/index.php?page=account&s=options
|
||||||
|
R34_API_KEY=your_rule34_api_key
|
||||||
|
R34_USER_ID=your_rule34_user_id
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ services:
|
||||||
LAVALINK_PASSWORD: Hch4HiVCxkKs9JPiSnrt4Q
|
LAVALINK_PASSWORD: Hch4HiVCxkKs9JPiSnrt4Q
|
||||||
SPOTIFY_CLIENT_ID: ${SPOTIFY_CLIENT_ID}
|
SPOTIFY_CLIENT_ID: ${SPOTIFY_CLIENT_ID}
|
||||||
SPOTIFY_CLIENT_SECRET: ${SPOTIFY_CLIENT_SECRET}
|
SPOTIFY_CLIENT_SECRET: ${SPOTIFY_CLIENT_SECRET}
|
||||||
|
R34_API_KEY: ${R34_API_KEY}
|
||||||
|
R34_USER_ID: ${R34_USER_ID}
|
||||||
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY}
|
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY}
|
||||||
AI_CHANNEL_ID: ${AI_CHANNEL_ID}
|
AI_CHANNEL_ID: ${AI_CHANNEL_ID}
|
||||||
AI_CONTEXT_MSGS: ${AI_CONTEXT_MSGS:-10}
|
AI_CONTEXT_MSGS: ${AI_CONTEXT_MSGS:-10}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ public class BotConfig {
|
||||||
private final int aiDossierUpdateHours;
|
private final int aiDossierUpdateHours;
|
||||||
private final String aiDebateChannelId;
|
private final String aiDebateChannelId;
|
||||||
private final LavalinkConfig lavalinkConfig;
|
private final LavalinkConfig lavalinkConfig;
|
||||||
|
private final String r34ApiKey;
|
||||||
|
private final String r34UserId;
|
||||||
|
|
||||||
public BotConfig(
|
public BotConfig(
|
||||||
String mainToken,
|
String mainToken,
|
||||||
|
|
@ -36,7 +38,9 @@ public class BotConfig {
|
||||||
int aiDossierMsgs,
|
int aiDossierMsgs,
|
||||||
int aiDossierUpdateHours,
|
int aiDossierUpdateHours,
|
||||||
String aiDebateChannelId,
|
String aiDebateChannelId,
|
||||||
LavalinkConfig lavalinkConfig) {
|
LavalinkConfig lavalinkConfig,
|
||||||
|
String r34ApiKey,
|
||||||
|
String r34UserId) {
|
||||||
this.mainToken = mainToken;
|
this.mainToken = mainToken;
|
||||||
this.musicToken = musicToken;
|
this.musicToken = musicToken;
|
||||||
this.radioToken = radioToken;
|
this.radioToken = radioToken;
|
||||||
|
|
@ -54,6 +58,8 @@ public class BotConfig {
|
||||||
this.aiDossierUpdateHours = aiDossierUpdateHours;
|
this.aiDossierUpdateHours = aiDossierUpdateHours;
|
||||||
this.aiDebateChannelId = aiDebateChannelId;
|
this.aiDebateChannelId = aiDebateChannelId;
|
||||||
this.lavalinkConfig = lavalinkConfig;
|
this.lavalinkConfig = lavalinkConfig;
|
||||||
|
this.r34ApiKey = r34ApiKey;
|
||||||
|
this.r34UserId = r34UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMainToken() {
|
public String getMainToken() {
|
||||||
|
|
@ -127,4 +133,12 @@ public class BotConfig {
|
||||||
public LavalinkConfig getLavalinkConfig() {
|
public LavalinkConfig getLavalinkConfig() {
|
||||||
return lavalinkConfig;
|
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"));
|
int aiDossierUpdateHours = Integer.parseInt(getEnv(dotenv, "AI_DOSSIER_UPDATE_HOURS", "24"));
|
||||||
String aiDebateChannelId = dotenv.get("AI_DEBATE_CHANNEL_ID");
|
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();
|
LavalinkConfig lavalinkConfig = getLavalinkConfig();
|
||||||
LoggerDecorator.success(logger, "Конфигурация загружена успешно");
|
LoggerDecorator.success(logger, "Конфигурация загружена успешно");
|
||||||
return new BotConfig(
|
return new BotConfig(
|
||||||
|
|
@ -102,6 +105,8 @@ public final class ConfigLoader {
|
||||||
aiDossierMsgs,
|
aiDossierMsgs,
|
||||||
aiDossierUpdateHours,
|
aiDossierUpdateHours,
|
||||||
aiDebateChannelId,
|
aiDebateChannelId,
|
||||||
lavalinkConfig);
|
lavalinkConfig,
|
||||||
|
r34ApiKey,
|
||||||
|
r34UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package creator.loki.feature.image;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
import creator.loki.config.BotConfig;
|
||||||
|
|
||||||
public class ImageModule extends AbstractModule {
|
public class ImageModule extends AbstractModule {
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ public class ImageModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
ImageService provideImageService() {
|
ImageService provideImageService(BotConfig config) {
|
||||||
return new ImageService();
|
return new ImageService(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
import creator.loki.config.BotConfig;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
@ -25,9 +26,13 @@ public class ImageService {
|
||||||
"https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1";
|
"https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1";
|
||||||
|
|
||||||
private final OkHttpClient client;
|
private final OkHttpClient client;
|
||||||
|
private final String r34ApiKey;
|
||||||
|
private final String r34UserId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ImageService() {
|
public ImageService(BotConfig config) {
|
||||||
|
this.r34ApiKey = config.getR34ApiKey();
|
||||||
|
this.r34UserId = config.getR34UserId();
|
||||||
this.client =
|
this.client =
|
||||||
new OkHttpClient.Builder()
|
new OkHttpClient.Builder()
|
||||||
.connectTimeout(15, TimeUnit.SECONDS)
|
.connectTimeout(15, TimeUnit.SECONDS)
|
||||||
|
|
@ -88,6 +93,9 @@ public class ImageService {
|
||||||
int capped = Math.min(limit, 100);
|
int capped = Math.min(limit, 100);
|
||||||
String url =
|
String url =
|
||||||
R34_API + "&tags=" + encodeTags(tags) + "&limit=" + capped + "&pid=" + (page - 1);
|
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);
|
return fetchBooruJson(url, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue