Skip to content

Commit

Permalink
Add SFW content to Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewVynnytskyi committed Jan 26, 2024
1 parent fa00e6b commit 4e23e31
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 33 deletions.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 33 additions & 2 deletions src/main/java/org/hentaibot/HentaiBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.apache.log4j.Logger;
import org.hentaibot.dtos.Rule34Dto;
import org.hentaibot.dtos.WaifuDto;
import org.hentaibot.network.AnimeWaifuQueries;
import org.hentaibot.network.Client;
import org.hentaibot.network.ClientSFW;
import org.hentaibot.network.HentaiQueries;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
Expand Down Expand Up @@ -30,7 +33,7 @@ public class HentaiBot extends TelegramLongPollingBot {
private static final Logger logger = Logger.getLogger(HentaiBot.class.getName());

private static final HentaiQueries hentaiClient = Client.getNsfwClient();

private static final AnimeWaifuQueries animeClient = ClientSFW.getSfwClient();
private final String botName;

public HentaiBot(String botName, String botToken) {
Expand Down Expand Up @@ -85,7 +88,7 @@ public void respondNsfw(String chatId) {

try {
hentaiClient
.getNsfw("anime", pageId)
.getNsfw("female", pageId)
.enqueue(
new Callback<>() {
@Override
Expand Down Expand Up @@ -120,6 +123,33 @@ public void onFailure(Call<List<Rule34Dto>> call, Throwable throwable) {
}

public void respondSfw(String chatId) {
final String[] categories = new String[]{"waifu", "neko", "shinobu", "megumin", "hug", "awoo", "kiss", "lick", "smug", "blush", "smile", "wave", "nom", "glomp", "slap", "kill", "happy", "wink", "poke", "dance", "cringe"};
String urlCategory = categories[random.nextInt(0, categories.length)];
animeClient
.getSFW(urlCategory)
.enqueue(
new Callback<>() {
@Override
public void onResponse(Call<WaifuDto> call, Response<WaifuDto> response) {
var picSDto = response.body();
logger.info("\nResponse:\n" + picSDto.getUrl() + "\n");

if (picSDto == null) {
onFailure(call, new IOException("Response body is null"));
return;
}

var path = picSDto.getUrl();
respondWithContent(chatId, path);
}

@Override
public void onFailure(Call<WaifuDto> call, Throwable throwable) {
logger.error(throwable.getMessage());
respondWithText(chatId, "Failed to get hentai. Try again later");
}
}
);

}

Expand Down Expand Up @@ -174,6 +204,7 @@ public void respondWithVideo(String chatId, InputFile file) {
response.setChatId(chatId);
response.setVideo(file);


try {
execute(response);
} catch (TelegramApiException ex) {
Expand Down
28 changes: 1 addition & 27 deletions src/main/java/org/hentaibot/dtos/Rule34Dto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,7 @@

// DTO - data transfer object

/**
*
* {
* "preview_url": "https://api-cdn.rule34.xxx/thumbnails/5377/thumbnail_4388d1ab31d98c6d0fd7ed114456b79f.jpg",
* "sample_url": "https://api-cdn.rule34.xxx/samples/5377/sample_4388d1ab31d98c6d0fd7ed114456b79f.jpg",
* "file_url": "https://api-cdn.rule34.xxx/images/5377/4388d1ab31d98c6d0fd7ed114456b79f.png",
* "directory": 5377,
* "hash": "4388d1ab31d98c6d0fd7ed114456b79f",
* "width": 2048,
* "height": 12672,
* "id": 9416035,
* "image": "4388d1ab31d98c6d0fd7ed114456b79f.png",
* "change": 1706095421,
* "owner": "antipenitant",
* "parent_id": 0,
* "rating": "explicit",
* "sample": true,
* "sample_height": 5259,
* "sample_width": 850,
* "score": 0,
* "tags": "anus ass breasts danganronpa harukawa_maki pussy tagme ultimateenf",
* "source": "https://www.deviantart.com/ultimateenf/art/Maki-chained-down-849989950",
* "status": "active",
* "has_notes": false,
* "comment_count": 0
* }
*/

public class Rule34Dto {
private String file_url;
private String tags;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/hentaibot/dtos/WaifuDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.hentaibot.dtos;

public class WaifuDto {
private String url;


public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "File url: " + url;
}
}
4 changes: 0 additions & 4 deletions src/main/java/org/hentaibot/network/AnimeQueries.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/java/org/hentaibot/network/AnimeWaifuQueries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.hentaibot.network;

import org.hentaibot.dtos.WaifuDto;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;

import java.util.List;
import java.util.Random;

public interface AnimeWaifuQueries {

Random random = new Random();
//String[] categories = new String[]{"waifu", "neko", "shinobu", "megumin", "bully", "cuddle", "cry", "hug", "awoo", "kiss", "lick", "pat", "smug", "bonk", "yeet", "blush", "smile", "wave", "highfive", "handhold", "nom", "bite", "glomp", "slap", "kill", "kick", "happy", "wink", "poke", "dance", "cringe"};
static String urlCategory = "waifu";
static String urlForm = "/sfw/"; //+ urlCategory;
@GET("/sfw/{category}")
Call<WaifuDto> getSFW(

@Path("category") String category

);
}
20 changes: 20 additions & 0 deletions src/main/java/org/hentaibot/network/ClientNSFW.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.hentaibot.network;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ClientNSFW {

private static Retrofit clientNWaifu = null;

private static final String UrlNclient = "https://api.waifu.pics";

public HentaiWaifuQueries getNSFWClient()
{
if(clientNWaifu == null)
{
clientNWaifu = new Retrofit.Builder().baseUrl(UrlNclient).addConverterFactory(GsonConverterFactory.create()).build();
}
return clientNWaifu.create(HentaiWaifuQueries.class);
}
}
20 changes: 20 additions & 0 deletions src/main/java/org/hentaibot/network/ClientSFW.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.hentaibot.network;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ClientSFW {

private static Retrofit clientWaifu = null;

private static final String UrlClient = "https://api.waifu.pics/";

public static AnimeWaifuQueries getSfwClient()
{
if (clientWaifu == null)
{
clientWaifu = new Retrofit.Builder().baseUrl(UrlClient).addConverterFactory(GsonConverterFactory.create()).build();
}
return clientWaifu.create(AnimeWaifuQueries.class);
}
}
20 changes: 20 additions & 0 deletions src/main/java/org/hentaibot/network/HentaiWaifuQueries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.hentaibot.network;

import org.hentaibot.dtos.WaifuDto;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

import java.util.List;

public interface HentaiWaifuQueries {

@GET("/nsfw/")
Call<List<WaifuDto>> getNSFW(
@Query("category") String category
);




}

0 comments on commit 4e23e31

Please sign in to comment.