diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1218cb4..93bf68c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,6 +1,8 @@ name: CodeQL on: + push: + branches: [ integration ] pull_request: # The branches below must be a subset of the branches above branches: [ integration ] diff --git a/pom.xml b/pom.xml index 2827a88..77d21cd 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 16 UTF-8 UTF-8 - 1.3.0 + 1.3.1 @@ -151,6 +151,13 @@ + + + com.beanbeanjuice + kawaii-api-wrapper + 1.1.0 + + org.apache.maven.plugins diff --git a/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java b/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java index e54f114..4046561 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java @@ -1,5 +1,6 @@ package com.beanbeanjuice.cafeapi; +import com.beanbeanjuice.KawaiiAPI; import com.beanbeanjuice.cafeapi.requests.*; import com.beanbeanjuice.cafeapi.user.Users; import com.beanbeanjuice.cafeapi.cafebot.beancoins.users.DonationUsers; @@ -27,6 +28,7 @@ public class CafeAPI { private String apiKey; private String userAgent; private static RequestLocation requestLocation; + public KawaiiAPI KAWAII_API; public Users USER; @@ -82,14 +84,27 @@ public CafeAPI(@NotNull String username, @NotNull String password, @NotNull Requ CAFE_USER = new CafeUsers(apiKey); BIRTHDAY = new Birthdays(apiKey); DONATION_USER = new DonationUsers(apiKey); - INTERACTION_PICTURE = new InteractionPictures(apiKey); + INTERACTION_PICTURE = new InteractionPictures(apiKey, this); + + KAWAII_API = new KawaiiAPI("anonymous"); } + /** + * @return The {@link RequestLocation} for the {@link CafeAPI}. + */ @NotNull public static RequestLocation getRequestLocation() { return requestLocation; } + /** + * Sets the {@link KawaiiAPI} token. + * @param token The {@link String} token for the {@link KawaiiAPI}. + */ + public void setKawaiiAPI(@NotNull String token) { + KAWAII_API = new KawaiiAPI(token); + } + private String getToken(@NotNull String username, @NotNull String password) { Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.POST) .setRoute("/user/login") diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java index e529446..f534b12 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java @@ -2,51 +2,57 @@ import com.beanbeanjuice.cafeapi.cafebot.interactions.users.Interaction; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * An enum used for {@link Interaction Interaction} types. * * @author beanbeanjuice + * @since 1.3.1 */ public enum InteractionType { - HUG ("hug_amount"), - PUNCH ("punch_amount"), - KISS ("kiss_amount"), - BITE ("bite_amount"), - BLUSH ("blush_amount"), - CUDDLE ("cuddle_amount"), - NOM ("nom_amount"), - POKE ("poke_amount"), - SLAP ("slap_amount"), - STAB ("stab_amount"), - HMPH ("hmph_amount"), - POUT ("pout_amount"), - THROW ("throw_amount"), - SMILE ("smile_amount"), - STARE ("stare_amount"), - TICKLE ("tickle_amount"), - RAGE ("rage_amount"), - YELL ("yell_amount"), - HEADPAT ("headpat_amount"), - CRY ("cry_amount"), - DANCE ("dance_amount"), - DAB ("dab_amount"), - BONK ("bonk_amount"), - SLEEP ("sleep_amount"), - DIE ("die_amount"), - WELCOME ("welcome_amount"), - LICK ("lick_amount"), - SHUSH ("shush_amount"); + HUG ("hug_amount", true, "hug"), + PUNCH ("punch_amount", true, "punch"), + KISS ("kiss_amount", true, "kiss"), + BITE ("bite_amount", true, "bite"), + BLUSH ("blush_amount", true, "blush"), + CUDDLE ("cuddle_amount", true, "cuddle"), + NOM ("nom_amount", true, "nom"), + POKE ("poke_amount", true, "poke"), + SLAP ("slap_amount", true, "slap"), + STAB ("stab_amount", false, null), + HMPH ("hmph_amount", false, null), + POUT ("pout_amount", true, "pout"), + THROW ("throw_amount", false, null), + SMILE ("smile_amount", true, "smile"), + STARE ("stare_amount", true, "stare"), + TICKLE ("tickle_amount", true, "tickle"), + RAGE ("rage_amount", false, null), + YELL ("yell_amount", true, "scream"), + HEADPAT ("headpat_amount", true, "pat"), + CRY ("cry_amount", true, "cry"), + DANCE ("dance_amount", true, "dance"), + DAB ("dab_amount", false, null), + BONK ("bonk_amount", false, null), + SLEEP ("sleep_amount", true, "sleepy"), + DIE ("die_amount", false, null), + WELCOME ("welcome_amount", false, null), + LICK ("lick_amount", true, "lick"), + SHUSH ("shush_amount", false, null); private final String type; + private final Boolean isKawaiiAPI; + private final String kawaiiAPIString; /** * Creates a new {@link InteractionType} static object. * @param type The {@link String type} of {@link Interaction Interaction}. */ - InteractionType(@NotNull String type) { + InteractionType(@NotNull String type, @NotNull Boolean isKawaiiAPI, @Nullable String kawaiiAPIString) { this.type = type; + this.isKawaiiAPI = isKawaiiAPI; + this.kawaiiAPIString = kawaiiAPIString; } /** @@ -56,4 +62,21 @@ public enum InteractionType { public String getType() { return type; } + + /** + * @return True, if the image should be returned from the {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI}. + */ + @NotNull + public Boolean isKawaiiAPI() { + return isKawaiiAPI; + } + + /** + * @return The {@link String} for retrieving the {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI} image. + */ + @Nullable + public String getKawaiiAPIString() { + return kawaiiAPIString; + } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java index c8eda19..60fc7af 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java @@ -17,17 +17,20 @@ * A class used to retrieve random pictures from the {@link CafeAPI CafeAPI}. * * @author beanbeanjuice + * @since 1.3.1 */ public class InteractionPictures implements com.beanbeanjuice.cafeapi.api.CafeAPI { private String apiKey; + private final CafeAPI cafeAPI; /** * Creates a new {@link InteractionPictures} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public InteractionPictures(@NotNull String apiKey) { + public InteractionPictures(@NotNull String apiKey, @NotNull CafeAPI cafeAPI) { this.apiKey = apiKey; + this.cafeAPI = cafeAPI; } /** @@ -41,12 +44,16 @@ public InteractionPictures(@NotNull String apiKey) { @NotNull public String getRandomInteractionPicture(@NotNull InteractionType type) throws AuthorizationException, ResponseException, TeaPotException { - Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) - .setRoute("/interaction_pictures/" + type) - .setAuthorization(apiKey) - .build(); + if (type.isKawaiiAPI()) { + return cafeAPI.KAWAII_API.GIF.getGIF(type.getKawaiiAPIString()); + } else { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) + .setRoute("/interaction_pictures/" + type) + .setAuthorization(apiKey) + .build(); - return request.getData().get("url").asText(); + return request.getData().get("url").asText(); + } } /** diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java index 70498c8..f416660 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java @@ -7,6 +7,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +/** + * Tests the {@link com.beanbeanjuice.cafeapi.cafebot.interactions.pictures.InteractionPictures InteractionPictures}. + * This confirms that the {@link CafeAPI} and {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI} are both working. + * + * @author beanbeanjuice + * @since 1.3.1 + */ public class InteractionPictureTest { @Test @@ -17,7 +24,12 @@ public void testInteractionPicturesAPI() { // Goes through every interaction type. Assertions.assertDoesNotThrow(() -> { for (InteractionType type : InteractionType.values()) { - Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type)); + + if (type.isKawaiiAPI()) + Assertions.assertTrue(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type).startsWith("https://api.kawaii.red/gif/")); + + else + Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type)); } }); }