Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.

Commit e5ebcf2

Browse files
Merge pull request #15 from beanbeanjuice/integration
Added the KawaiiAPI
2 parents 73ce342 + 17e83df commit e5ebcf2

File tree

6 files changed

+104
-38
lines changed

6 files changed

+104
-38
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: CodeQL
22

33
on:
4+
push:
5+
branches: [ integration ]
46
pull_request:
57
# The branches below must be a subset of the branches above
68
branches: [ integration ]

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<maven.compiler.target>16</maven.compiler.target>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
17-
<version.number>1.3.0</version.number>
17+
<version.number>1.3.1</version.number>
1818
</properties>
1919

2020
<profiles>
@@ -151,6 +151,13 @@
151151
</distributionManagement>
152152

153153
<dependencies>
154+
<!-- Kawaii API -->
155+
<dependency>
156+
<groupId>com.beanbeanjuice</groupId>
157+
<artifactId>kawaii-api-wrapper</artifactId>
158+
<version>1.1.0</version>
159+
</dependency>
160+
154161
<!-- GPG Plugin -->
155162
<dependency>
156163
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.beanbeanjuice.cafeapi;
22

3+
import com.beanbeanjuice.KawaiiAPI;
34
import com.beanbeanjuice.cafeapi.requests.*;
45
import com.beanbeanjuice.cafeapi.user.Users;
56
import com.beanbeanjuice.cafeapi.cafebot.beancoins.users.DonationUsers;
@@ -27,6 +28,7 @@ public class CafeAPI {
2728
private String apiKey;
2829
private String userAgent;
2930
private static RequestLocation requestLocation;
31+
public KawaiiAPI KAWAII_API;
3032

3133
public Users USER;
3234

@@ -82,14 +84,27 @@ public CafeAPI(@NotNull String username, @NotNull String password, @NotNull Requ
8284
CAFE_USER = new CafeUsers(apiKey);
8385
BIRTHDAY = new Birthdays(apiKey);
8486
DONATION_USER = new DonationUsers(apiKey);
85-
INTERACTION_PICTURE = new InteractionPictures(apiKey);
87+
INTERACTION_PICTURE = new InteractionPictures(apiKey, this);
88+
89+
KAWAII_API = new KawaiiAPI("anonymous");
8690
}
8791

92+
/**
93+
* @return The {@link RequestLocation} for the {@link CafeAPI}.
94+
*/
8895
@NotNull
8996
public static RequestLocation getRequestLocation() {
9097
return requestLocation;
9198
}
9299

100+
/**
101+
* Sets the {@link KawaiiAPI} token.
102+
* @param token The {@link String} token for the {@link KawaiiAPI}.
103+
*/
104+
public void setKawaiiAPI(@NotNull String token) {
105+
KAWAII_API = new KawaiiAPI(token);
106+
}
107+
93108
private String getToken(@NotNull String username, @NotNull String password) {
94109
Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.POST)
95110
.setRoute("/user/login")

src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,57 @@
22

33
import com.beanbeanjuice.cafeapi.cafebot.interactions.users.Interaction;
44
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Nullable;
56

67
/**
78
* An enum used for {@link Interaction Interaction} types.
89
*
910
* @author beanbeanjuice
11+
* @since 1.3.1
1012
*/
1113
public enum InteractionType {
1214

13-
HUG ("hug_amount"),
14-
PUNCH ("punch_amount"),
15-
KISS ("kiss_amount"),
16-
BITE ("bite_amount"),
17-
BLUSH ("blush_amount"),
18-
CUDDLE ("cuddle_amount"),
19-
NOM ("nom_amount"),
20-
POKE ("poke_amount"),
21-
SLAP ("slap_amount"),
22-
STAB ("stab_amount"),
23-
HMPH ("hmph_amount"),
24-
POUT ("pout_amount"),
25-
THROW ("throw_amount"),
26-
SMILE ("smile_amount"),
27-
STARE ("stare_amount"),
28-
TICKLE ("tickle_amount"),
29-
RAGE ("rage_amount"),
30-
YELL ("yell_amount"),
31-
HEADPAT ("headpat_amount"),
32-
CRY ("cry_amount"),
33-
DANCE ("dance_amount"),
34-
DAB ("dab_amount"),
35-
BONK ("bonk_amount"),
36-
SLEEP ("sleep_amount"),
37-
DIE ("die_amount"),
38-
WELCOME ("welcome_amount"),
39-
LICK ("lick_amount"),
40-
SHUSH ("shush_amount");
15+
HUG ("hug_amount", true, "hug"),
16+
PUNCH ("punch_amount", true, "punch"),
17+
KISS ("kiss_amount", true, "kiss"),
18+
BITE ("bite_amount", true, "bite"),
19+
BLUSH ("blush_amount", true, "blush"),
20+
CUDDLE ("cuddle_amount", true, "cuddle"),
21+
NOM ("nom_amount", true, "nom"),
22+
POKE ("poke_amount", true, "poke"),
23+
SLAP ("slap_amount", true, "slap"),
24+
STAB ("stab_amount", false, null),
25+
HMPH ("hmph_amount", false, null),
26+
POUT ("pout_amount", true, "pout"),
27+
THROW ("throw_amount", false, null),
28+
SMILE ("smile_amount", true, "smile"),
29+
STARE ("stare_amount", true, "stare"),
30+
TICKLE ("tickle_amount", true, "tickle"),
31+
RAGE ("rage_amount", false, null),
32+
YELL ("yell_amount", true, "scream"),
33+
HEADPAT ("headpat_amount", true, "pat"),
34+
CRY ("cry_amount", true, "cry"),
35+
DANCE ("dance_amount", true, "dance"),
36+
DAB ("dab_amount", false, null),
37+
BONK ("bonk_amount", false, null),
38+
SLEEP ("sleep_amount", true, "sleepy"),
39+
DIE ("die_amount", false, null),
40+
WELCOME ("welcome_amount", false, null),
41+
LICK ("lick_amount", true, "lick"),
42+
SHUSH ("shush_amount", false, null);
4143

4244
private final String type;
45+
private final Boolean isKawaiiAPI;
46+
private final String kawaiiAPIString;
4347

4448
/**
4549
* Creates a new {@link InteractionType} static object.
4650
* @param type The {@link String type} of {@link Interaction Interaction}.
4751
*/
48-
InteractionType(@NotNull String type) {
52+
InteractionType(@NotNull String type, @NotNull Boolean isKawaiiAPI, @Nullable String kawaiiAPIString) {
4953
this.type = type;
54+
this.isKawaiiAPI = isKawaiiAPI;
55+
this.kawaiiAPIString = kawaiiAPIString;
5056
}
5157

5258
/**
@@ -56,4 +62,21 @@ public enum InteractionType {
5662
public String getType() {
5763
return type;
5864
}
65+
66+
/**
67+
* @return True, if the image should be returned from the {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI}.
68+
*/
69+
@NotNull
70+
public Boolean isKawaiiAPI() {
71+
return isKawaiiAPI;
72+
}
73+
74+
/**
75+
* @return The {@link String} for retrieving the {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI} image.
76+
*/
77+
@Nullable
78+
public String getKawaiiAPIString() {
79+
return kawaiiAPIString;
80+
}
81+
5982
}

src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
* A class used to retrieve random pictures from the {@link CafeAPI CafeAPI}.
1818
*
1919
* @author beanbeanjuice
20+
* @since 1.3.1
2021
*/
2122
public class InteractionPictures implements com.beanbeanjuice.cafeapi.api.CafeAPI {
2223

2324
private String apiKey;
25+
private final CafeAPI cafeAPI;
2426

2527
/**
2628
* Creates a new {@link InteractionPictures} object.
2729
* @param apiKey The {@link String apiKey} used for authorization.
2830
*/
29-
public InteractionPictures(@NotNull String apiKey) {
31+
public InteractionPictures(@NotNull String apiKey, @NotNull CafeAPI cafeAPI) {
3032
this.apiKey = apiKey;
33+
this.cafeAPI = cafeAPI;
3134
}
3235

3336
/**
@@ -41,12 +44,16 @@ public InteractionPictures(@NotNull String apiKey) {
4144
@NotNull
4245
public String getRandomInteractionPicture(@NotNull InteractionType type)
4346
throws AuthorizationException, ResponseException, TeaPotException {
44-
Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET)
45-
.setRoute("/interaction_pictures/" + type)
46-
.setAuthorization(apiKey)
47-
.build();
47+
if (type.isKawaiiAPI()) {
48+
return cafeAPI.KAWAII_API.GIF.getGIF(type.getKawaiiAPIString());
49+
} else {
50+
Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET)
51+
.setRoute("/interaction_pictures/" + type)
52+
.setAuthorization(apiKey)
53+
.build();
4854

49-
return request.getData().get("url").asText();
55+
return request.getData().get("url").asText();
56+
}
5057
}
5158

5259
/**

src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
import org.junit.jupiter.api.DisplayName;
88
import org.junit.jupiter.api.Test;
99

10+
/**
11+
* Tests the {@link com.beanbeanjuice.cafeapi.cafebot.interactions.pictures.InteractionPictures InteractionPictures}.
12+
* This confirms that the {@link CafeAPI} and {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI} are both working.
13+
*
14+
* @author beanbeanjuice
15+
* @since 1.3.1
16+
*/
1017
public class InteractionPictureTest {
1118

1219
@Test
@@ -17,7 +24,12 @@ public void testInteractionPicturesAPI() {
1724
// Goes through every interaction type.
1825
Assertions.assertDoesNotThrow(() -> {
1926
for (InteractionType type : InteractionType.values()) {
20-
Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type));
27+
28+
if (type.isKawaiiAPI())
29+
Assertions.assertTrue(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type).startsWith("https://api.kawaii.red/gif/"));
30+
31+
else
32+
Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type));
2133
}
2234
});
2335
}

0 commit comments

Comments
 (0)