Skip to content

Commit

Permalink
v1.7.4
Browse files Browse the repository at this point in the history
= Switched to local Image creation from API, on Hornyjail.
  • Loading branch information
DxsSucuk committed Apr 13, 2022
1 parent e72a55e commit ebf3577
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>de.presti</groupId>
<artifactId>Ree6</artifactId>
<version>1.7.3</version>
<version>1.7.4</version>
<packaging>jar</packaging>
<name>Ree6</name>
<description>Ree6 is an open-Source Discord Bot.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.presti.ree6.commands.CommandEvent;
import de.presti.ree6.commands.interfaces.ICommand;
import de.presti.ree6.main.Main;
import de.presti.ree6.utils.data.ImageCreationUtility;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void sendHornyJail(Member member, CommandEvent commandEvent) {
HttpResponse response = httpClient.execute(request);

Main.getInstance().getCommandManager().sendMessage(member.getAsMention() + " is now in the Hornyjail!", commandEvent.getTextChannel(), commandEvent.getInteractionHook());
commandEvent.getTextChannel().sendFile(response.getEntity().getContent(), "hornyjail.png").queue();
commandEvent.getTextChannel().sendFile(ImageCreationUtility.createHornyJailImage(member.getUser()), "hornyjail.png").queue();
if (commandEvent.isSlashCommand()) commandEvent.getInteractionHook().sendMessage("Check below!").queue();
} catch (Exception ex) {
Main.getInstance().getCommandManager().sendMessage("Error while putting someone in the Hornyjail!\nError: " + ex.getMessage().replaceAll(Main.getInstance().getConfig().getConfiguration().getString("dagpi.apitoken"), "Ree6TopSecretAPIToken"), commandEvent.getTextChannel(), commandEvent.getInteractionHook());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/presti/ree6/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void main(String[] args) {

// Create a new Instance of the Bot, as well as add the Events.
try {
BotWorker.createBot(BotVersion.PUBLIC, "1.7.3");
BotWorker.createBot(BotVersion.DEV, "1.7.3");
instance.musicWorker = new MusicWorker();
instance.addEvents();
} catch (Exception ex) {
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/de/presti/ree6/utils/data/ImageCreationUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,94 @@ public static byte[] createRankImage(UserLevel userLevel) throws IOException {
return outputStream.toByteArray();
}

/**
* Generate a HornyJail Image with Java native Graphics2D.
*
* @param user the User Object.
* @return the bytes of the Image.
* @throws IOException when URL-Format is Invalid or the URL is not a valid Image.
*/
public static byte[] createHornyJailImage(User user) throws IOException {
if (user == null)
return new byte[128];

// Generate a 128x128 Image Background.
BufferedImage base = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
BufferedImage userImage;

// Generated a Circle Image with the Avatar of the User.
if (user.getAvatarUrl() != null) {
userImage = ImageIO.read(new URL(user.getAvatarUrl()));
} else {
userImage = ImageIO.read(new URL(user.getDefaultAvatarUrl()));
}

// Create a new Graphics2D instance from the base.
Graphics2D graphics2D = base.createGraphics();

// Change the background to black.
graphics2D.setColor(Color.BLACK);
graphics2D.fillRoundRect(0, 0, base.getWidth(), base.getHeight(), 10, 10);

// Draw basic Information, such as the User Image, Username and the Experience Rect.
graphics2D.drawImage(userImage, null, 0, 0);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(4, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(5, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(19, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(20, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(33, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(34, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(48, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(49, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(63, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(64, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(78, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(79, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(94, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(95, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(109, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(110, -1, 3, 130);

graphics2D.setColor(Color.DARK_GRAY);
graphics2D.drawRect(124, -1, 4, 130);
graphics2D.setColor(Color.GRAY);
graphics2D.fillRect(125, -1, 3, 130);

// Close the Graphics2d instance.
graphics2D.dispose();

// Create a ByteArrayOutputStream to convert the BufferedImage to a Array of Bytes.
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

ImageIO.write(base, "PNG", outputStream);
return outputStream.toByteArray();
}

/**
* Generated a Circle Shaped Version of the given Image.
*
Expand Down

0 comments on commit ebf3577

Please sign in to comment.