diff --git a/src/main/java/de/presti/ree6/commands/CommandManager.java b/src/main/java/de/presti/ree6/commands/CommandManager.java index 1694cb680..4ff7d58cb 100644 --- a/src/main/java/de/presti/ree6/commands/CommandManager.java +++ b/src/main/java/de/presti/ree6/commands/CommandManager.java @@ -95,7 +95,7 @@ public void addSlashCommand(JDA jda) { for (DiscordLocale discordLocale : DiscordLocale.values()) { if (!LanguageService.languageResources.containsKey(discordLocale)) continue; - String description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description() + "_slash"); + String description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description()); if (description.equals("Missing language resource!")) { description = LanguageService.getByLocale(discordLocale, command.getClass().getAnnotation(Command.class).description()); } @@ -105,9 +105,9 @@ public void addSlashCommand(JDA jda) { } } - String description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description() + "_slash"); + String description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description()); if (description.equals("Missing language resource!")) { - description = LanguageService.getDefault(command.getClass().getAnnotation(Command.class).description()); + description = LanguageService.getDefault(description); } if (!description.equals("Missing language resource!")) { diff --git a/src/main/java/de/presti/ree6/commands/impl/fun/Cringe.java b/src/main/java/de/presti/ree6/commands/impl/fun/Cringe.java index 1c0ffed92..418de7a26 100644 --- a/src/main/java/de/presti/ree6/commands/impl/fun/Cringe.java +++ b/src/main/java/de/presti/ree6/commands/impl/fun/Cringe.java @@ -12,7 +12,7 @@ /** * A command to let the bot response to the last Message with a cringe Image. */ -@Command(name = "cringe", description = "Let shrek tell them that their message was cringe!", category = Category.FUN) +@Command(name = "cringe", description = "command.description.cringe", category = Category.FUN) public class Cringe implements ICommand { /** diff --git a/src/main/java/de/presti/ree6/sql/SQLWorker.java b/src/main/java/de/presti/ree6/sql/SQLWorker.java index 4bc7d8d73..a94a71963 100644 --- a/src/main/java/de/presti/ree6/sql/SQLWorker.java +++ b/src/main/java/de/presti/ree6/sql/SQLWorker.java @@ -88,14 +88,7 @@ public void addChatLevelData(String guildId, @Nonnull ChatUserLevel userLevel) { return; } - // Check if the User is already saved in the Database. - if (existsInChatLevel(guildId, userLevel.getUserId())) { - - // If so change the current XP to the new. - updateEntity(userLevel); - } else { - updateEntity(userLevel); - } + updateEntity(userLevel); } /** @@ -163,14 +156,7 @@ public void addVoiceLevelData(String guildId, @Nonnull VoiceUserLevel voiceUserL return; } - // Check if the User is already saved in the Database. - if (existsInVoiceLevel(guildId, voiceUserLevel.getUserId())) { - - // If so change the current XP to the new. - updateEntity(voiceUserLevel); - } else { - updateEntity(voiceUserLevel); - } + updateEntity(voiceUserLevel); } /** @@ -1157,13 +1143,7 @@ public void removeInvite(String guildId, String inviteCode) { * @param inviteUsage the Usage count of the Invite. */ public void setInvite(String guildId, String inviteCreator, String inviteCode, long inviteUsage) { - // Check if there is an entry with the same data. - if (existsInvite(guildId, inviteCreator, inviteCode)) { - // Update entry. - updateEntity(new Invite(guildId, inviteCreator, inviteUsage, inviteCode)); - } else { - updateEntity(new Invite(guildId, inviteCreator, inviteUsage, inviteCode)); - } + updateEntity(new Invite(guildId, inviteCreator, inviteUsage, inviteCode)); } /** @@ -1245,14 +1225,7 @@ public String getMessage(String guildId) { * @param content the Join Message. */ public void setMessage(String guildId, String content) { - - if (isMessageSetup(guildId)) { - // If there is already an entry just replace it. - updateEntity(new Setting(guildId, "message_join", content)); - } else { - // Create a new entry, if there was none. - updateEntity(new Setting(guildId, "message_join", content)); - } + updateEntity(new Setting(guildId, "message_join", content)); } /** @@ -1384,13 +1357,7 @@ public void setSetting(String guildId, String settingName, Object settingValue) // Check if it is null. if (settingValue == null) createSettings(guildId); - // Check if there is an entry. - if (hasSetting(guildId, settingName)) { - // If so update it. - updateEntity(new Setting(guildId, settingName, settingValue)); - } else { - updateEntity(new Setting(guildId, settingName, settingValue)); - } + updateEntity(new Setting(guildId, settingName, settingValue)); } /** @@ -1718,11 +1685,7 @@ public void optIn(String guildId, String userId) { public void addBirthday(String guildId, String channelId, String userId, String birthday) { try { BirthdayWish newBirthday = new BirthdayWish(guildId, channelId, userId, new SimpleDateFormat("dd.MM.yyyy").parse(birthday)); - if (isBirthdaySaved(guildId, userId)) { - updateEntity(newBirthday); - } else { - updateEntity(newBirthday); - } + updateEntity(newBirthday); } catch (ParseException ignore) { } } diff --git a/src/main/java/de/presti/ree6/utils/data/ImageCreationUtility.java b/src/main/java/de/presti/ree6/utils/data/ImageCreationUtility.java index 13bdc8aa1..4eed5a6f0 100644 --- a/src/main/java/de/presti/ree6/utils/data/ImageCreationUtility.java +++ b/src/main/java/de/presti/ree6/utils/data/ImageCreationUtility.java @@ -216,15 +216,13 @@ public static byte[] createRankImage(UserLevel userLevel) throws IOException { log.debug("Finished disposing Graphics2D instance. ({}ms)", System.currentTimeMillis() - actionPerformance); actionPerformance = System.currentTimeMillis(); - // Create a ByteArrayOutputStream to convert the BufferedImage to an Array of Bytes. - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - ImageIO.write(base, "PNG", outputStream); - log.debug("Finished writing Image into ByteArrayOutputStream. ({}ms)", System.currentTimeMillis() - actionPerformance); - log.debug("Finished creation in {}ms", System.currentTimeMillis() - start); - byte[] bytes = outputStream.toByteArray(); - outputStream.close(); - return bytes; + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + + ImageIO.write(base, "PNG", outputStream); + log.debug("Finished writing Image into ByteArrayOutputStream. ({}ms)", System.currentTimeMillis() - actionPerformance); + log.debug("Finished creation in {}ms", System.currentTimeMillis() - start); + return outputStream.toByteArray(); + } } /** @@ -249,6 +247,13 @@ public static byte[] createJoinImage(User user, String messageImage, String mess backgroundImage = joinBackgroundBase.get(messageImage); } else { backgroundImage = resize(ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(messageImage))), 1920, 1080); + if (backgroundImage == null) { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + + ImageIO.write(base, "PNG", outputStream); + return outputStream.toByteArray(); + } + } joinBackgroundBase.put(messageImage, backgroundImage); } @@ -308,13 +313,13 @@ public static byte[] createJoinImage(User user, String messageImage, String mess log.debug("Finished disposing Graphics2D instance. ({}ms)", System.currentTimeMillis() - actionPerformance); actionPerformance = System.currentTimeMillis(); - // Create a ByteArrayOutputStream to convert the BufferedImage to an Array of Bytes. - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { - ImageIO.write(base, "PNG", outputStream); - log.debug("Finished writing Image into ByteArrayOutputStream. ({}ms)", System.currentTimeMillis() - actionPerformance); - log.debug("Finished creation in {}ms", System.currentTimeMillis() - start); - return outputStream.toByteArray(); + ImageIO.write(base, "PNG", outputStream); + log.debug("Finished writing Image into ByteArrayOutputStream. ({}ms)", System.currentTimeMillis() - actionPerformance); + log.debug("Finished creation in {}ms", System.currentTimeMillis() - start); + return outputStream.toByteArray(); + } } /** @@ -362,13 +367,11 @@ public static byte[] createHornyJailImage(User user) throws IOException { // Close the Graphics2D instance. graphics2D.dispose(); - // Create a ByteArrayOutputStream to convert the BufferedImage to an Array of Bytes. - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { - ImageIO.write(base, "PNG", outputStream); - byte[] bytes = outputStream.toByteArray(); - outputStream.close(); - return bytes; + ImageIO.write(base, "PNG", outputStream); + return outputStream.toByteArray(); + } } /**