Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmalec authored Oct 21, 2018
1 parent fc1a4f0 commit a6b9278
Show file tree
Hide file tree
Showing 24 changed files with 1,257 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/main/java/net/explodingbush/ksoftapi/KSoftAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package net.explodingbush.ksoftapi;

import net.explodingbush.ksoftapi.entities.BanAction;
import net.explodingbush.ksoftapi.entities.RedditAction;
import net.explodingbush.ksoftapi.entities.TaggedImageAction;
import net.explodingbush.ksoftapi.entities.WikihowAction;
import net.explodingbush.ksoftapi.enums.ImageTag;
import net.explodingbush.ksoftapi.enums.ImageType;

public class KSoftAPI {

private final String token;
private String request;

public KSoftAPI(String token) {
this.token = token;
}

/**
* This returns a {@link net.explodingbush.ksoftapi.entities.RedditAction RedditAction} using the declared {@link net.explodingbush.ksoftapi.enums.ImageType ImageTypes}
* @param type
* The {@link ImageType ImageType} you'd like to use
* @return {@link net.explodingbush.ksoftapi.entities.RedditAction RedditAction}s
*/
public RedditAction getRedditImage(ImageType type) {
switch (type) {
case RANDOM_MEME:
this.request = "https://api.ksoft.si/meme/random-meme";
break;
case RANDOW_AWW:
this.request = "https://api.ksoft.si/meme/random-aww";
break;
case RANDOM_NSFW:
this.request = "https://api.ksoft.si/meme/random-nsfw";
break;
case RANDOM_REDDIT:
this.request = "https://api.ksoft.si/meme/rand-reddit/";
}
return new RedditAction(token, type, request);
}

/**
* This returns a {@link net.explodingbush.ksoftapi.entities.TaggedImageAction TaggedImageAction} using the declared {@link net.explodingbush.ksoftapi.enums.ImageTag ImageTags}
* @param tag
* The {@link ImageTag ImageTag} you'd like to use
* @return {@link net.explodingbush.ksoftapi.entities.TaggedImageAction TaggedImageAction}
*/
public TaggedImageAction getTaggedImage(ImageTag tag) {
return new TaggedImageAction(token, tag);
}
/**
* This returns a {@link net.explodingbush.ksoftapi.entities.WikihowAction WikihowAction}
*
* @return {@link net.explodingbush.ksoftapi.entities.WikihowAction WikihowAction}
*/
public WikihowAction getRandomWikihow() {
return new WikihowAction(token);
}

/**
* This returns a {@link net.explodingbush.ksoftapi.entities.BanAction BanAction}
*
* @return {@link net.explodingbush.ksoftapi.entities.BanAction BanAction}
*/
public BanAction getBan() {
return new BanAction(token);
}
}
11 changes: 11 additions & 0 deletions src/main/java/net/explodingbush/ksoftapi/KSoftAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.explodingbush.ksoftapi;

public interface KSoftAction<T> {

/**
* The thing that executes the requests
* @return A method corresponding to the request
*/
T execute();

}
86 changes: 86 additions & 0 deletions src/main/java/net/explodingbush/ksoftapi/entities/AddBan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package net.explodingbush.ksoftapi.entities;

public interface AddBan {

/**
* Sets the user ID to report
*
* @param user
* User ID to report
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setUserId(String user);

/**
* Sets the user ID to report
*
* @param moderatorId
* User ID to set as the report moderator
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setModeratorId(String moderatorId);

/**
* Sets the user ID to report
*
* @param userName
* Username to set as the reportee username
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setUsername(String userName);

/**
* Sets the user ID to report
*
* @param discriminator
* Discriminator to set as the reportee discriminator
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setDiscriminator(String discriminator);

/**
* Sets the user ID to report
*
* @param reason
* The reason for the ban
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setReason(String reason);

/**
* Sets the user ID to report
*
* @param proof
* Proof of the reportee's offense
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setProof(String proof);

/**
* Sets the user ID to report
*
* <p>Default: <b>true (yes)</b></p>
*
* @param appealable
* True - Allow the ban to be appealable
*
*
* @return The AddBan instance. Useful for chaining.
*/
AddBan setAppealable(boolean appealable);

/**
* Sets a new ban to report with the appended values
*
* @return A new {@link BanAction BanAction} instance ready to report a new ban with.
* <p>No need to set an values in {@link BanAction BanAction}, just use the {@link BanAction#execute() execute} function.</p>
*/
BanAction set();

}
111 changes: 111 additions & 0 deletions src/main/java/net/explodingbush/ksoftapi/entities/Ban.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package net.explodingbush.ksoftapi.entities;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.stream.Stream;

public interface Ban {

/**
* The ID of a banned user
*
* @return The corresponding Discord user ID of the banned user
*/
long getId();

/**
* The username of a banned user
*
* @return The corresponding Discord username of the banned user
*/
String getName();

/**
* The discriminator of a banned user
*
* @return The corresponding Discord discriminator of the banned user
*/
int getDiscriminator();

/**
* The effective name of the banned user
*
* @return The corresponding Discord effective name of the banned user
* <p>An example of this could look like <b>Matt#0001</b></p>
*/
String getEffectiveName();

/**
* The moderator ID of the ban
*
* <p>If the moderator ID is not provided, it would be the Discord user tied to the KSoft token holder, or if one is provided, it's overriden to be the Ban Manager who either accepts or rejects the request.
*
* @return The corresponding Discord moderator ID of the bannned user
*
*/
long getModId();

/**
* The reason on why a user was banned
*
* @return The corresponding reason why the user was banned
*/
String getReason();

/**
* The proof of why a user was banned
*
* @return The corresponding proof of why the user was banned
*/
String getProof();

/**
* A value of a user's ban status
*
* @return The corresponding true/false if the user is banned
*/
boolean isBanActive();

/**
* A value if a user's ban is appeable
*
* @return The corresponding true/false if the user's ban is appealable
*/
boolean isAppealable();

/**
* The OffsetDateTime of a user's initial ban acceptance
*
* @return The corresponding OffsetDateTime of the user's initial ban acceptance
*/
OffsetDateTime getTimestamp();

/**
* A value of the ban's existance
*
* @return The corresponding true/false if the ban exists
*/
boolean exists();

/**
* A ban's active value
*
* @return The corresponding true/false if the ban is active
*/
boolean isBanned();

/**
* Gets a list of banned users
*
* @return An immutable list of banned users specified by {@link BanAction#getBanList(int) BanAction#getBanList}
*/
List<Ban> getBannedList();

/**
* Gets a stream of banned users
*
* @return An immutable stream of banned users specified by {@link BanAction#getBanList(int) BanAction#getBanList}
*/
Stream<Ban> getBannedStream();

}
101 changes: 101 additions & 0 deletions src/main/java/net/explodingbush/ksoftapi/entities/BanAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package net.explodingbush.ksoftapi.entities;

import net.explodingbush.ksoftapi.KSoftAction;
import net.explodingbush.ksoftapi.entities.impl.AddBanImpl;
import net.explodingbush.ksoftapi.entities.impl.BanImpl;
import net.explodingbush.ksoftapi.exceptions.AddBanException;
import net.explodingbush.ksoftapi.exceptions.LoginException;
import net.explodingbush.ksoftapi.exceptions.MissingArgumentException;
import net.explodingbush.ksoftapi.utils.JSONBuilder;
import org.json.JSONObject;

/**
* Used to interface with {@link AddBan AddBan} and {@link Ban Ban}
* <h1>Example</h1>
* <h2>Getting a ban by ID</h2>
* <code>Ban ban = new KSoftAPI(token).getBan().setUserId("492811511081861130");</code>
* <br>
* <code>System.out.println(ban.getName());</code>
* <br>
* <h2>Reporting a ban</h2>
* <code>AddBan ban = new KSoftAPI(token).getBan().addBan();</code>
* <br>
* <code>ban.setUserId("123").setReason("Bad boy").setProof("nani is bad proof").set().execute();</code>
*/

public class BanAction implements KSoftAction<Ban> {


private String banId;
private static String tokenValue;
private int results;
private boolean isAddingBan;
private JSONObject banJson;
public BanAction(String token) {
tokenValue = token;
}
public BanAction(boolean isAddingBan, JSONObject banJson) {
this.isAddingBan = isAddingBan;
this.banJson = banJson;
}

/**
* Sets the amount of bans to retrieve
* @param results
* The amount of results to use with an {@link Ban#getBannedList() Ban#getBannedList()} and/or a {@link Ban#getBannedStream() Ban#getBannedStream()}
* @return BanAction instance. Useful for chaining.
*/
public BanAction getBanList(int results) {
this.results = results;
return this;
}
/**
* Sets the amount of bans to retrieve
* @param userId
* The Discord user ID to use when retrieving an individual ban
* @return BanAction instance. Useful for chaining.
*/
public BanAction setUserId(String userId) {
this.banId = userId;
return this;
}
/**
* Returns a new {@link AddBan} instance to report a new ban
* @return A new chainable {@link AddBan} instance
*/
public AddBan addBan() {
return new AddBanImpl();
}

/**
* Executes the request with the specified parameters
*
* @return A new {@link Ban Ban} instance.
* @throws net.explodingbush.ksoftapi.exceptions.LoginException If the token is not provided or incorrect.
* @throws net.explodingbush.ksoftapi.exceptions.MissingArgumentException If using {@link net.explodingbush.ksoftapi.entities.BanAction#getBanList(int) BanAction#getBanList} and the value is invalid
*/
@Override
public Ban execute() throws LoginException {
JSONObject json;
if(isAddingBan) {
json = banJson;
JSONObject newJson = new JSONBuilder().addBanKsoft(banJson, "https://api.ksoft.si/bans/add", tokenValue);
if(newJson.has("error")) {
throw new AddBanException(newJson.getString("message"));
}
} else {
if (results == 0 && banId == null) {
throw new MissingArgumentException("Missing action value. Could not be parsed");
}
if (results == 0) {
json = new JSONBuilder().requestKsoft("https://api.ksoft.si/bans/info?user=" + String.valueOf(banId), tokenValue);
} else {
json = new JSONBuilder().requestKsoft("https://api.ksoft.si/bans/list?per_page=" + String.valueOf(results), tokenValue);
}
}
if (tokenValue.isEmpty() || !json.isNull("detail") && json.getString("detail").equalsIgnoreCase("Invalid token.")) {
throw new LoginException();
}
return new BanImpl(json);
}
}
Loading

0 comments on commit a6b9278

Please sign in to comment.