Browse Source

Bonk Kommando

pull/2/head
Yannic Link 4 years ago
parent
commit
4992ccb885
5 changed files with 72 additions and 1 deletions
  1. +5
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/command/YoshiCommandDistributor.java
  2. +59
    -0
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/BonkCommand.java
  3. +8
    -0
      app/src/main/java/de/yannicpunktdee/yoshibot/utils/Resources.java
  4. BIN
      rsc/bonks/bonk1.png
  5. BIN
      rsc/bonks/bonk2.png

+ 5
- 1
app/src/main/java/de/yannicpunktdee/yoshibot/command/YoshiCommandDistributor.java View File

@ -59,6 +59,9 @@ public class YoshiCommandDistributor {
case PAT: case PAT:
command = new PatCommand(context); command = new PatCommand(context);
break; break;
case BONK:
command = new BonkCommand(context);
break;
default: default:
context.getEvent().getTextChannel().sendMessage("Dieses Kommando existiert noch nicht.").queue(); context.getEvent().getTextChannel().sendMessage("Dieses Kommando existiert noch nicht.").queue();
break; break;
@ -104,7 +107,8 @@ public class YoshiCommandDistributor {
*/ */
DELETE, DELETE,
SAUCE, SAUCE,
PAT
PAT,
BONK
} }


+ 59
- 0
app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/BonkCommand.java View File

@ -0,0 +1,59 @@
package de.yannicpunktdee.yoshibot.command.commands;
import de.yannicpunktdee.yoshibot.command.YoshiCommand;
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext;
import de.yannicpunktdee.yoshibot.utils.GifSequenceWriter;
import de.yannicpunktdee.yoshibot.utils.Resources;
import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public class BonkCommand extends YoshiCommand {
public BonkCommand(YoshiCommandContext context) {
super(context);
}
@Override
public boolean execute() {
if(!super.execute()) return false;
File outFile = new File(Resources.getTempPath() + UUID.randomUUID().toString() + ".gif");
try {
BufferedImage inPicture = ImageIO.read(downloadAttachmentToFile(null, null));
BufferedImage bonk1Picture = ImageIO.read(new File(Resources.getBonkPngPath() + "bonk1.png"));
BufferedImage bonk2Picture = ImageIO.read(new File(Resources.getBonkPngPath() + "bonk2.png"));
BufferedImage frame1 = getOutFrame(bonk1Picture, inPicture, 615, 155, 185, 345);
ImageOutputStream output = new FileImageOutputStream(outFile);
GifSequenceWriter writer = new GifSequenceWriter(output, frame1.getType(), 100, true);
writer.writeToSequence(frame1);
writer.writeToSequence(getOutFrame(bonk2Picture, inPicture, 455, 155, 345, 345));
writer.close();
output.close();
} catch (IOException e) {
sendMessage("GIF konnte nicht erstellt werden.");
return false;
}
context.getEvent().getTextChannel().sendFile(outFile).queue();
return true;
}
private BufferedImage getOutFrame(BufferedImage bonkDogGraphics, BufferedImage personGraphics, int x, int y, int width, int height){
BufferedImage outFrame = new BufferedImage(800, 500, BufferedImage.TYPE_INT_RGB);
Graphics2D g = outFrame.createGraphics();
g.setColor(Color.black);
g.drawImage(personGraphics, x, y, width, height, null);
g.drawImage(bonkDogGraphics, 0, 0, 680, 412, null);
return outFrame;
}
}

+ 8
- 0
app/src/main/java/de/yannicpunktdee/yoshibot/utils/Resources.java View File

@ -39,6 +39,8 @@ public final class Resources {
private static String patPngPath; private static String patPngPath;
@Getter @Getter
private static String imagePath; private static String imagePath;
@Getter
private static String bonkPngPath;
@Getter @Getter
private static String jda_builder_string; private static String jda_builder_string;
@ -77,6 +79,7 @@ public final class Resources {
if (isOk) isOk = initTagFilter(); if (isOk) isOk = initTagFilter();
if (isOk) isOk = initPatPngPath(); if (isOk) isOk = initPatPngPath();
if (isOk) isOk = initImages(); if (isOk) isOk = initImages();
if (isOk) isOk = initBonkPngPath();
if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen."); if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen.");
else Logger.logError("Die Konfiguration konnte nicht geladen werden"); else Logger.logError("Die Konfiguration konnte nicht geladen werden");
@ -174,6 +177,11 @@ public final class Resources {
patPngPath = verifyExists(resourcePath + "pats/", File::isDirectory); patPngPath = verifyExists(resourcePath + "pats/", File::isDirectory);
return patPngPath != null; return patPngPath != null;
} }
private static boolean initBonkPngPath() {
bonkPngPath = verifyExists(resourcePath + "bonks/", File::isDirectory);
return bonkPngPath != null;
}
private static boolean initGuildId() { private static boolean initGuildId() {
if (!propertiesFile.containsKey("guild_id")) { if (!propertiesFile.containsKey("guild_id")) {


BIN
rsc/bonks/bonk1.png View File

Before After
Width: 680  |  Height: 412  |  Size: 152 KiB

BIN
rsc/bonks/bonk2.png View File

Before After
Width: 680  |  Height: 412  |  Size: 146 KiB

Loading…
Cancel
Save