-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from Deyan2306/development
Pickup command & refactoring
- Loading branch information
Showing
3 changed files
with
146 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/de/presti/ree6/commands/impl/fun/PickUpLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package de.presti.ree6.commands.impl.fun; | ||
|
||
import com.google.gson.JsonObject; | ||
import de.presti.ree6.commands.Category; | ||
import de.presti.ree6.commands.CommandEvent; | ||
import de.presti.ree6.commands.interfaces.Command; | ||
import de.presti.ree6.commands.interfaces.ICommand; | ||
import de.presti.ree6.main.Main; | ||
import de.presti.ree6.utils.data.Data; | ||
import de.presti.ree6.utils.external.RequestUtility; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.interactions.commands.build.CommandData; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* A command to give you a random pickup line | ||
* */ | ||
|
||
@Command(name = "pickupline", description = "command.description.pickupline", category = Category.FUN) | ||
public class PickUpLine implements ICommand { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public void onPerform(CommandEvent commandEvent) { | ||
JsonObject jsonObject = RequestUtility.requestJson(RequestUtility.Request.builder().url("https://api.dagpi.xyz/data/pickupline") | ||
.bearerAuth(Main.getInstance().getConfig().getConfiguration().getString("dagpi.apitoken")).build()).getAsJsonObject(); | ||
|
||
EmbedBuilder em = new EmbedBuilder(); | ||
|
||
// Check if there is no "category" in the JSON. If so, output the error. | ||
if (!jsonObject.has("category")) { | ||
em.setTitle("Error!"); | ||
em.setColor(Color.RED); | ||
em.setDescription(commandEvent.getResource("message.default.retrievalError")); | ||
em.setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()); | ||
commandEvent.reply(em.build()); | ||
return; | ||
} | ||
|
||
if(jsonObject.has("nsfw") && jsonObject.get("nsfw").getAsBoolean()) { | ||
commandEvent.reply(commandEvent.getResource("pickupline.responseNsfw", jsonObject.get("joke").getAsString())); | ||
} else { | ||
commandEvent.reply(commandEvent.getResource("pickupline.response", jsonObject.get("joke").getAsString())); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public CommandData getCommandData() { | ||
return null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public String[] getAlias() { | ||
return new String[0]; | ||
} | ||
} |
143 changes: 75 additions & 68 deletions
143
src/main/java/de/presti/ree6/commands/impl/fun/Waifu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,75 @@ | ||
package de.presti.ree6.commands.impl.fun; | ||
|
||
import com.google.gson.JsonObject; | ||
import de.presti.ree6.commands.Category; | ||
import de.presti.ree6.commands.CommandEvent; | ||
import de.presti.ree6.commands.interfaces.Command; | ||
import de.presti.ree6.commands.interfaces.ICommand; | ||
import de.presti.ree6.main.Main; | ||
import de.presti.ree6.utils.data.Data; | ||
import de.presti.ree6.utils.external.RequestUtility; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.interactions.commands.build.CommandData; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* A command to show you are random WaiFu or Husbando. | ||
*/ | ||
@Command(name = "waifu", description = "command.description.waifu", category = Category.FUN) | ||
public class Waifu implements ICommand { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public void onPerform(CommandEvent commandEvent) { | ||
JsonObject jsonObject = RequestUtility.requestJson(RequestUtility.Request.builder().url("https://api.dagpi.xyz/data/waifu").bearerAuth(Main.getInstance().getConfig().getConfiguration().getString("dagpi.apitoken")).build()).getAsJsonObject(); | ||
|
||
EmbedBuilder em = new EmbedBuilder(); | ||
|
||
if (!jsonObject.has("series")) { | ||
em.setTitle(commandEvent.getResource("label.error")); | ||
em.setColor(Color.RED); | ||
em.setDescription(commandEvent.getResource("message.default.retrievalError")); | ||
em.setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()); | ||
commandEvent.reply(em.build()); | ||
return; | ||
} | ||
|
||
JsonObject jsonObject1 = jsonObject.get("series").getAsJsonObject(); | ||
|
||
em.setImage((jsonObject.has("display_picture") ? jsonObject.get("display_picture").getAsString() : "https://images.ree6.de/notfound.png")); | ||
em.addField("**" + commandEvent.getResource("label.character") + "**", "``" + (jsonObject.has("name") ? jsonObject.get("name").getAsString() : commandEvent.getResource("message.default.retrievalError")) + "``", true); | ||
em.addField("**" + commandEvent.getResource("label.from") + "**", "``" + (jsonObject1.has("name") ? jsonObject1.get("name").getAsString() : commandEvent.getResource("message.default.retrievalError")) + "``", true); | ||
if((jsonObject.has("nsfw") && jsonObject.get("nsfw").getAsBoolean())) { | ||
em.addField("**" + commandEvent.getResource("label.nsfw") + "**", "", true); | ||
} | ||
em.setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()); | ||
|
||
commandEvent.reply(em.build()); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public CommandData getCommandData() { | ||
return null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public String[] getAlias() { | ||
return new String[0]; | ||
} | ||
} | ||
package de.presti.ree6.commands.impl.fun; | ||
|
||
import com.google.gson.JsonObject; | ||
import de.presti.ree6.commands.Category; | ||
import de.presti.ree6.commands.CommandEvent; | ||
import de.presti.ree6.commands.interfaces.Command; | ||
import de.presti.ree6.commands.interfaces.ICommand; | ||
import de.presti.ree6.main.Main; | ||
import de.presti.ree6.utils.data.Data; | ||
import de.presti.ree6.utils.external.RequestUtility; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.interactions.commands.build.CommandData; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* A command to show you are random Waifu or Husbando. | ||
*/ | ||
@Command(name = "waifu", description = "command.description.waifu", category = Category.FUN) | ||
public class Waifu implements ICommand { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public void onPerform(CommandEvent commandEvent) { | ||
JsonObject jsonObject = RequestUtility.requestJson(RequestUtility.Request.builder().url("https://api.dagpi.xyz/data/waifu") | ||
.bearerAuth(Main.getInstance().getConfig().getConfiguration().getString("dagpi.apitoken")).build()).getAsJsonObject(); | ||
|
||
EmbedBuilder em = new EmbedBuilder(); | ||
|
||
if (!jsonObject.has("series")) { | ||
em.setTitle(commandEvent.getResource("label.error")); | ||
em.setColor(Color.RED); | ||
em.setDescription(commandEvent.getResource("message.default.retrievalError")); | ||
em.setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()); | ||
commandEvent.reply(em.build()); | ||
return; | ||
} | ||
|
||
JsonObject jsonObject1 = jsonObject.get("series").getAsJsonObject(); | ||
|
||
em.setImage((jsonObject.has("display_picture") ? jsonObject.get("display_picture").getAsString() : "https://images.ree6.de/notfound.png")); | ||
em.addField("**" + commandEvent.getResource("label.character") + "**", "``" + (jsonObject.has("name") | ||
? jsonObject.get("name").getAsString() | ||
: commandEvent.getResource("message.default.retrievalError")) + "``", true); | ||
|
||
em.addField("**" + commandEvent.getResource("label.from") + "**", "``" + (jsonObject1.has("name") | ||
? jsonObject1.get("name").getAsString() | ||
: commandEvent.getResource("message.default.retrievalError")) + "``", true); | ||
|
||
if(jsonObject.has("nsfw") && jsonObject.get("nsfw").getAsBoolean()) { | ||
em.addField("**" + commandEvent.getResource("label.nsfw") + "**", "", true); | ||
} | ||
em.setFooter(commandEvent.getMember().getUser().getAsTag() + " - " + Data.ADVERTISEMENT, commandEvent.getMember().getUser().getAvatarUrl()); | ||
|
||
commandEvent.reply(em.build()); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public CommandData getCommandData() { | ||
return null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public String[] getAlias() { | ||
return new String[0]; | ||
} | ||
} |