Skip to content

Commit

Permalink
Merge pull request #332 from Deyan2306/development
Browse files Browse the repository at this point in the history
Pickup command & refactoring
  • Loading branch information
DxsSucuk authored Apr 24, 2023
2 parents b67fd0f + 5c9f38d commit 0933d53
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 68 deletions.
5 changes: 5 additions & 0 deletions languages/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ command:
slashNotSupported: "This Command doesn't support Slash Commands yet!"
onlySlashSupported: "This Command only supports Slash-Commands!"
description:
pickupline: "You need a pickup line? We got you."
birthday: "Let the bot remember your Birthday."
instagramNotifier: "Manage your Instagram-Notifier!"
redditNotifier: "Manage your Reddit-Notifier!"
Expand Down Expand Up @@ -631,3 +632,7 @@ category:
community: "Community Tools that allow you to interact with your community."
nsfw: "NSFW stuff that you can only use in NSFW Channels."
hidden: "Hidden Commands that are only visible to the Owner of the Bot."
pickupline:
no_response: "I can't come up with a response right now."
response: ":speaking_head: %s"
responseNsfw: ":red_circle: ||%s|| **NSFW**"
66 changes: 66 additions & 0 deletions src/main/java/de/presti/ree6/commands/impl/fun/PickUpLine.java
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 src/main/java/de/presti/ree6/commands/impl/fun/Waifu.java
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];
}
}

0 comments on commit 0933d53

Please sign in to comment.