Skip to content

Commit

Permalink
add opportuntity to create ImageBoards collection via constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Oct 13, 2023
1 parent a25781a commit aa77e2d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/main/java/net/kodehawa/lib/imageboards/DefaultImageBoards.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

package net.kodehawa.lib.imageboards;

import net.kodehawa.lib.imageboards.boards.DefaultBoards;
import net.kodehawa.lib.imageboards.entities.impl.*;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

/**
* Utility class representing already-created objects around the most used image boards.
Expand All @@ -41,17 +37,12 @@
* @author Kodehawa
*/
public class DefaultImageBoards {
private static final OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(3, TimeUnit.SECONDS)
.readTimeout(3, TimeUnit.SECONDS)
.build();

public static final ImageBoard<FurryImage> E621 = new ImageBoard<>(client, DefaultBoards.E621, FurryImage.class);
public static final ImageBoard<KonachanImage> KONACHAN = new ImageBoard<>(client, DefaultBoards.KONACHAN, KonachanImage.class);
public static final ImageBoard<Rule34Image> RULE34 = new ImageBoard<>(client, DefaultBoards.R34, Rule34Image.class);
public static final ImageBoard<YandereImage> YANDERE = new ImageBoard<>(client, DefaultBoards.YANDERE, YandereImage.class);
public static final ImageBoard<DanbooruImage> DANBOORU = new ImageBoard<>(client, DefaultBoards.DANBOORU, DanbooruImage.class);
public static final ImageBoard<SafebooruImage> SAFEBOORU = new ImageBoard<>(client, DefaultBoards.SAFEBOORU, SafebooruImage.class);
public static final ImageBoard<SafeFurryImage> E926 = new ImageBoard<>(client, DefaultBoards.E926, SafeFurryImage.class);
public static final ImageBoard<GelbooruImage> GELBOORU = new ImageBoard<>(client, DefaultBoards.GELBOORU, GelbooruImage.class);
public static final ImageBoard<FurryImage> E621 = ImageBoards.Default.E621;
public static final ImageBoard<KonachanImage> KONACHAN = ImageBoards.Default.KONACHAN;
public static final ImageBoard<Rule34Image> RULE34 = ImageBoards.Default.RULE34;
public static final ImageBoard<YandereImage> YANDERE = ImageBoards.Default.YANDERE;
public static final ImageBoard<DanbooruImage> DANBOORU = ImageBoards.Default.DANBOORU;
public static final ImageBoard<SafebooruImage> SAFEBOORU = ImageBoards.Default.SAFEBOORU;
public static final ImageBoard<SafeFurryImage> E926 = ImageBoards.Default.E926;
public static final ImageBoard<GelbooruImage> GELBOORU = ImageBoards.Default.GELBOORU;
}
87 changes: 87 additions & 0 deletions src/main/java/net/kodehawa/lib/imageboards/ImageBoards.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2017 Kodehawa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.kodehawa.lib.imageboards;

import net.kodehawa.lib.imageboards.boards.DefaultBoards;
import net.kodehawa.lib.imageboards.entities.impl.*;
import okhttp3.OkHttpClient;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.TimeUnit;

/**
* Utility class representing already-created objects around the most used image boards.
* As of now, this contains the following boorus / imageboards:
* <ul>
* <li>e621 - Furry pictures, both NSFW and safe.</li>
* <li>Konachan (owned by booru.org) - Anime pictures, both NSFW and safe.</li>
* <li>Rule34 (owned by booru.org) - Anime pictures, only NSFW</li>
* <li>Yande.re - Anime pictures, both NSFW and safe (though tagging is sloppy, would recommend setting this to only NSFW)</li>
* <li>Danbooru (the original one) - Anime pictures, both NSFW and safe.</li>
* <li>Safebooru (owned by booru.org) - Anime pictures, only safe.</li>
* <li>e926 (a safe version of e621) - Furry pictures, only safe.</li>
* </ul>
*
* It's recommended to lock the usage of the boorus to only NSFW channels unless the image is safe. If you're not
* using this for a discord bot, then just use as your own discretion :P
*
* In difference with {@link DefaultImageBoards} this class allow you to configure {@link OkHttpClient} via passing
* your own client into constructor.
*
* @author Kodehawa
* @author InsanusMokrassar
*/
public class ImageBoards {
@NotNull
public final ImageBoard<FurryImage> E621;
@NotNull
public final ImageBoard<KonachanImage> KONACHAN;
@NotNull
public final ImageBoard<Rule34Image> RULE34;
@NotNull
public final ImageBoard<YandereImage> YANDERE;
@NotNull
public final ImageBoard<DanbooruImage> DANBOORU;
@NotNull
public final ImageBoard<SafebooruImage> SAFEBOORU;
@NotNull
public final ImageBoard<SafeFurryImage> E926;
@NotNull
public final ImageBoard<GelbooruImage> GELBOORU;

public ImageBoards(@Nullable OkHttpClient client) {
OkHttpClient localClient = client;
if (localClient == null) {
localClient = new OkHttpClient.Builder()
.connectTimeout(3, TimeUnit.SECONDS)
.readTimeout(3, TimeUnit.SECONDS)
.build();
}

E621 = new ImageBoard<>(localClient, DefaultBoards.E621, FurryImage.class);
KONACHAN = new ImageBoard<>(localClient, DefaultBoards.KONACHAN, KonachanImage.class);
RULE34 = new ImageBoard<>(localClient, DefaultBoards.R34, Rule34Image.class);
YANDERE = new ImageBoard<>(localClient, DefaultBoards.YANDERE, YandereImage.class);
DANBOORU = new ImageBoard<>(localClient, DefaultBoards.DANBOORU, DanbooruImage.class);
SAFEBOORU = new ImageBoard<>(localClient, DefaultBoards.SAFEBOORU, SafebooruImage.class);
E926 = new ImageBoard<>(localClient, DefaultBoards.E926, SafeFurryImage.class);
GELBOORU = new ImageBoard<>(localClient, DefaultBoards.GELBOORU, GelbooruImage.class);
}

public static final ImageBoards Default = new ImageBoards(null);
}

0 comments on commit aa77e2d

Please sign in to comment.