<! For AI Layer >
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
<version>0.33.0</version>
</dependency>
<! For parsing 8kun JSON data >
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
</dependency>
</dependencies>
Use code with caution.2. The AI Text Generator ServiceThis service asks the AI model to generate a post contextually relevant to the board you are targeting.javaimport dev.langchain4j.model.openai.OpenAiChatModel;
public class AiPostGenerator {
private final OpenAiChatModel model;
public AiPostGenerator(String apiKey) {
this.model = OpenAiChatModel.builder()
.apiKey(apiKey)
.modelName("gpt-4o") // Or any preferred model
.build();
}
public String generatePostContent(String boardTopic) {
String prompt = "Write a short, engaging anonymous imageboard post about " + boardTopic +
". Keep it under 100 words. Do not use hashtags or emojis.";
return model.generate(prompt);
}
}
Use code with caution.3. The 8kun Posting Client8kun uses a standard imageboard structure. To reply to an existing thread, you must submit a multipart/form-data POST request to their posting script (usually post.php).javaimport java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
public class KunPostingBot {
private final HttpClient httpClient;
private static final String BASE_URL = "https://8kun.top";
public KunPostingBot() {
this.httpClient = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.ALWAYS)
.build();
}
public void postReply(String board, String threadId, String comment) throws Exception {
String boundary = "—JavaBoundary" + UUID.randomUUID().toString();
String url = BASE_URL + "/post.php";
// Construct the multipart body payload
StringBuilder body = new StringBuilder();
addFormField(body, boundary, "board", board);
addFormField(body, boundary, "thread", threadId);
addFormField(body, boundary, "body", comment);
addFormField(body, boundary, "post", "New+Post");
body.append("").append(boundary).append("rn");
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
.POST(HttpRequest.BodyPublishers.ofString(body.toString(), StandardCharsets.UTF_8))
.build();
HttpResponse<Stringresponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() 200 || response.statusCode() 302) {
System.out.println("Successfully attempted post placement.");
} else {
System.out.println("Failed to post. Status code: " + response.statusCode());
}
}
private void addFormField(StringBuilder body, String boundary, String name, String value) {
body.append("–").append(boundary).append("rn");
body.append("Content-Disposition: form-data; name="").append(name).append(""rnrn");
body.append(value).append("rn");
}
}
Use code with caution.4. Orchestrating the Agent ExecutionTie the AI layer and the posting network layer together inside your application's main thread loop.javapublic class MainAgent {
public static void main(String[] args) {
String aiApiKey = "your-openai-api-key";
String targetBoard = "tech"; // Target board name
String threadId = "123456"; // Target thread ID
AiPostGenerator aiGenerator = new AiPostGenerator(aiApiKey);
KunPostingBot bot = new KunPostingBot();
try {
System.out.println("Generating AI text content…");
String comment = aiGenerator.generatePostContent("Java framework efficiency");
System.out.println("Submitting post payload to 8kun…");
bot.postReply(targetBoard, threadId, comment);
} catch (Exception e) {
e.printStackTrace();
}
}
}
kek