From 390d7047f65a1bbc1abbb8279569bf15f9310e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Wed, 27 Oct 2021 17:52:33 +0300 Subject: [PATCH 1/2] toLowerCase and toUpperCase with English. --- build.gradle | 4 +- .../jagrosh/jdautilities/command/Command.java | 7 ++- .../command/impl/CommandClientImpl.java | 28 +++++----- .../commons/utils/FinderUtil.java | 56 +++++++++---------- .../examples/command/RoleinfoCommand.java | 4 +- .../jdautilities/menu/OrderedMenu.java | 3 +- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index 69dfdcfc..13ca6a3b 100644 --- a/build.gradle +++ b/build.gradle @@ -51,8 +51,8 @@ allprojects { json = { [group: 'org.json', name: 'json', version: jsonVersion] } junit = { [group: 'junit', name: 'junit', version: junitVersion] } - artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase() - moduleName = "${group}.jdautilities${rootProject == project? "" : ".${project.name.toLowerCase()}"}" + artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase(Locale.ENGLISH) + moduleName = "${group}.jdautilities${rootProject == project? "" : ".${project.name.toLowerCase(Locale.ENGLISH)}"}" } // Helper task that allows us to do a one-line method call to fully diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/Command.java b/command/src/main/java/com/jagrosh/jdautilities/command/Command.java index b66356da..0a2d254d 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/Command.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/Command.java @@ -16,6 +16,7 @@ package com.jagrosh.jdautilities.command; import java.util.Arrays; +import java.util.Locale; import java.util.Objects; import java.util.function.BiConsumer; import java.util.function.Predicate; @@ -414,13 +415,13 @@ public boolean isAllowed(TextChannel channel) String topic = channel.getTopic(); if(topic==null || topic.isEmpty()) return true; - topic = topic.toLowerCase(); - String lowerName = name.toLowerCase(); + topic = topic.toLowerCase(Locale.ENGLISH); + String lowerName = name.toLowerCase(Locale.ENGLISH); if(topic.contains("{"+lowerName+"}")) return true; if(topic.contains("{-"+lowerName+"}")) return false; - String lowerCat = category==null ? null : category.getName().toLowerCase(); + String lowerCat = category==null ? null : category.getName().toLowerCase(Locale.ENGLISH); if(lowerCat!=null) { if(topic.contains("{"+lowerCat+"}")) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index 5a3f92dc..c2332c85 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -313,13 +313,13 @@ public void addCommand(Command command, int index) throw new ArrayIndexOutOfBoundsException("Index specified is invalid: ["+index+"/"+commands.size()+"]"); synchronized(commandIndex) { - String name = command.getName().toLowerCase(); + String name = command.getName().toLowerCase(Locale.ENGLISH); //check for collision if(commandIndex.containsKey(name)) throw new IllegalArgumentException("Command added has a name or alias that has already been indexed: \""+name+"\"!"); for(String alias : command.getAliases()) { - if(commandIndex.containsKey(alias.toLowerCase())) + if(commandIndex.containsKey(alias.toLowerCase(Locale.ENGLISH))) throw new IllegalArgumentException("Command added has a name or alias that has already been indexed: \""+alias+"\"!"); } //shift if not append @@ -331,7 +331,7 @@ public void addCommand(Command command, int index) //add commandIndex.put(name, index); for(String alias : command.getAliases()) - commandIndex.put(alias.toLowerCase(), index); + commandIndex.put(alias.toLowerCase(Locale.ENGLISH), index); } commands.add(index,command); } @@ -349,7 +349,7 @@ public void addSlashCommand(SlashCommand command, int index) throw new ArrayIndexOutOfBoundsException("Index specified is invalid: ["+index+"/"+slashCommands.size()+"]"); synchronized(slashCommandIndex) { - String name = command.getName().toLowerCase(); + String name = command.getName().toLowerCase(Locale.ENGLISH); //check for collision if(slashCommandIndex.containsKey(name)) throw new IllegalArgumentException("Command added has a name that has already been indexed: \""+name+"\"!"); @@ -370,13 +370,13 @@ public void removeCommand(String name) { synchronized(commandIndex) { - if(!commandIndex.containsKey(name.toLowerCase())) + if(!commandIndex.containsKey(name.toLowerCase(Locale.ENGLISH))) throw new IllegalArgumentException("Name provided is not indexed: \"" + name + "\"!"); - int targetIndex = commandIndex.remove(name.toLowerCase()); + int targetIndex = commandIndex.remove(name.toLowerCase(Locale.ENGLISH)); Command removedCommand = commands.remove(targetIndex); for(String alias : removedCommand.getAliases()) { - commandIndex.remove(alias.toLowerCase()); + commandIndex.remove(alias.toLowerCase(Locale.ENGLISH)); } commandIndex.entrySet().stream().filter(entry -> entry.getValue()>targetIndex).collect(Collectors.toList()) .forEach(entry -> commandIndex.put(entry.getKey(), entry.getValue()-1)); @@ -632,7 +632,7 @@ else if(event.isFromType(ChannelType.PRIVATE) || event.getTextChannel().canTalk( final Command command; // this will be null if it's not a command synchronized(commandIndex) { - int i = commandIndex.getOrDefault(name.toLowerCase(), -1); + int i = commandIndex.getOrDefault(name.toLowerCase(Locale.ENGLISH), -1); command = i != -1? commands.get(i) : null; } @@ -682,15 +682,15 @@ private MessageParts getParts(MessageReceivedEvent event) { } } - final String lowerCaseContent = rawContent.toLowerCase(); + final String lowerCaseContent = rawContent.toLowerCase(Locale.ENGLISH); // Check for default prefix - if (lowerCaseContent.startsWith(prefix.toLowerCase())) { + if (lowerCaseContent.startsWith(prefix.toLowerCase(Locale.ENGLISH))) { final int prefixLength = prefix.length(); return makeMessageParts(rawContent, prefixLength); } // Check for alternate prefix - if(altprefix != null && lowerCaseContent.startsWith(altprefix.toLowerCase())) { + if(altprefix != null && lowerCaseContent.startsWith(altprefix.toLowerCase(Locale.ENGLISH))) { final int prefixLength = altprefix.length(); return makeMessageParts(rawContent, prefixLength); } @@ -698,7 +698,7 @@ private MessageParts getParts(MessageReceivedEvent event) { // Check for prefixes if (prefixes != null) { for (String pre : prefixes) { - if (lowerCaseContent.startsWith(pre.toLowerCase())) { + if (lowerCaseContent.startsWith(pre.toLowerCase(Locale.ENGLISH))) { final int prefixLength = pre.length(); return makeMessageParts(rawContent, prefixLength); } @@ -710,7 +710,7 @@ private MessageParts getParts(MessageReceivedEvent event) { Collection prefixes = settings.getPrefixes(); if(prefixes != null) { for(String prefix : prefixes) { - if(lowerCaseContent.startsWith(prefix.toLowerCase())) { + if(lowerCaseContent.startsWith(prefix.toLowerCase(Locale.ENGLISH))) { final int prefixLength = prefix.length(); return makeMessageParts(rawContent, prefixLength); } @@ -778,7 +778,7 @@ private void onSlashCommand(SlashCommandEvent event) final SlashCommand command; // this will be null if it's not a command synchronized(slashCommandIndex) { - int i = slashCommandIndex.getOrDefault(event.getName().toLowerCase(), -1); + int i = slashCommandIndex.getOrDefault(event.getName().toLowerCase(Locale.ENGLISH), -1); command = i != -1? slashCommands.get(i) : null; } diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java index 5d78084a..a303489c 100644 --- a/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java +++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java @@ -140,10 +140,10 @@ private static List jdaUserSearch(String query, JDA jda, boolean useShardM } else if(fullRefMatch.matches()) { - String lowerName = fullRefMatch.group(1).toLowerCase(); + String lowerName = fullRefMatch.group(1).toLowerCase(Locale.ENGLISH); String discrim = fullRefMatch.group(2); List users = (manager != null ? manager.getUserCache() : jda.getUserCache()) - .stream().filter(user -> user.getName().toLowerCase().equals(lowerName) + .stream().filter(user -> user.getName().toLowerCase(Locale.ENGLISH).equals(lowerName) && user.getDiscriminator().equals(discrim)) .collect(Collectors.toList()); if(!users.isEmpty()) @@ -160,16 +160,16 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); (manager != null? manager.getUserCache() : jda.getUserCache()).forEach(user -> { String name = user.getName(); if(name.equals(query)) exact.add(user); else if (name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(user); - else if (name.toLowerCase().startsWith(lowerquery) && wrongcase.isEmpty()) + else if (name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(user); - else if (name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) + else if (name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) contains.add(user); }); if(!exact.isEmpty()) @@ -256,7 +256,7 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerQuery = query.toLowerCase(); + String lowerQuery = query.toLowerCase(Locale.ENGLISH); for(User u: bans) { // If a discrim is specified then we skip all users without it. @@ -267,9 +267,9 @@ else if(DISCORD_ID.matcher(query).matches()) exact.add(u); else if(exact.isEmpty() && u.getName().equalsIgnoreCase(query)) wrongcase.add(u); - else if(wrongcase.isEmpty() && u.getName().toLowerCase().startsWith(lowerQuery)) + else if(wrongcase.isEmpty() && u.getName().toLowerCase(Locale.ENGLISH).startsWith(lowerQuery)) startswith.add(u); - else if(startswith.isEmpty() && u.getName().toLowerCase().contains(lowerQuery)) + else if(startswith.isEmpty() && u.getName().toLowerCase(Locale.ENGLISH).contains(lowerQuery)) contains.add(u); } if(!exact.isEmpty()) @@ -320,10 +320,10 @@ public static List findMembers(String query, Guild guild) } else if(fullRefMatch.matches()) { - String lowerName = fullRefMatch.group(1).toLowerCase(); + String lowerName = fullRefMatch.group(1).toLowerCase(Locale.ENGLISH); String discrim = fullRefMatch.group(2); List members = guild.getMemberCache().stream() - .filter(member -> member.getUser().getName().toLowerCase().equals(lowerName) + .filter(member -> member.getUser().getName().toLowerCase(Locale.ENGLISH).equals(lowerName) && member.getUser().getDiscriminator().equals(discrim)) .collect(Collectors.toList()); if(!members.isEmpty()) @@ -339,7 +339,7 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); guild.getMemberCache().forEach(member -> { String name = member.getUser().getName(); String effName = member.getEffectiveName(); @@ -347,9 +347,9 @@ else if(DISCORD_ID.matcher(query).matches()) exact.add(member); else if((name.equalsIgnoreCase(query) || effName.equalsIgnoreCase(query)) && exact.isEmpty()) wrongcase.add(member); - else if((name.toLowerCase().startsWith(lowerquery) || effName.toLowerCase().startsWith(lowerquery)) && wrongcase.isEmpty()) + else if((name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) || effName.toLowerCase(Locale.ENGLISH).startsWith(lowerquery)) && wrongcase.isEmpty()) startswith.add(member); - else if((name.toLowerCase().contains(lowerquery) || effName.toLowerCase().contains(lowerquery)) && startswith.isEmpty()) + else if((name.toLowerCase(Locale.ENGLISH).contains(lowerquery) || effName.toLowerCase(Locale.ENGLISH).contains(lowerquery)) && startswith.isEmpty()) contains.add(member); }); if(!exact.isEmpty()) @@ -473,16 +473,16 @@ private static List genericTextChannelSearch(String query, Snowflak ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); cache.forEach((tc) -> { String name = tc.getName(); if(name.equals(query)) exact.add(tc); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(tc); - else if(name.toLowerCase().startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(tc); - else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) contains.add(tc); }); if(!exact.isEmpty()) @@ -580,16 +580,16 @@ private static List genericVoiceChannelSearch(String query, Snowfl ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); cache.forEach((vc) -> { String name = vc.getName(); if(name.equals(query)) exact.add(vc); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(vc); - else if(name.toLowerCase().startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(vc); - else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) contains.add(vc); }); if(!exact.isEmpty()) @@ -688,16 +688,16 @@ private static List genericCategorySearch(String query, SnowflakeCache ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); cache.forEach(cat -> { String name = cat.getName(); if(name.equals(query)) exact.add(cat); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(cat); - else if(name.toLowerCase().startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(cat); - else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) contains.add(cat); }); if(!exact.isEmpty()) @@ -743,16 +743,16 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); guild.getRoleCache().forEach((role) -> { String name = role.getName(); if(name.equals(query)) exact.add(role); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(role); - else if(name.toLowerCase().startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(role); - else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) contains.add(role); }); if(!exact.isEmpty()) @@ -888,16 +888,16 @@ private static List genericEmoteSearch(String query, SnowflakeCacheView wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(); + String lowerquery = query.toLowerCase(Locale.ENGLISH); cache.forEach(emote -> { String name = emote.getName(); if(name.equals(query)) exact.add(emote); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(emote); - else if(name.toLowerCase().startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(emote); - else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) contains.add(emote); }); if(!exact.isEmpty()) diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java index fb0a2f07..5fff709c 100644 --- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java +++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java @@ -21,6 +21,8 @@ import java.awt.Color; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Locale; + import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; @@ -83,7 +85,7 @@ else if(found.size()>1) StringBuilder desr = new StringBuilder(LINESTART + "ID: **" + role.getId() + "**\n" + LINESTART + "Creation: **" + role.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**\n" + LINESTART + "Position: **" + role.getPosition()+"**\n" - + LINESTART + "Color: **#" + (color==null ? "000000" : Integer.toHexString(color.getRGB()).toUpperCase().substring(2)) + "**\n" + + LINESTART + "Color: **#" + (color==null ? "000000" : Integer.toHexString(color.getRGB()).toUpperCase(Locale.ENGLISH).substring(2)) + "**\n" + LINESTART + "Mentionable: **" + role.isMentionable() + "**\n" + LINESTART + "Hoisted: **" + role.isHoisted() + "**\n" + LINESTART + "Managed: **" + role.isManaged() + "**\n" diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java index 52e138f7..7e390ad0 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java @@ -18,6 +18,7 @@ import java.awt.Color; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; @@ -324,7 +325,7 @@ private int getMessageNumber(String message) // is 10 (the maximum number of choices in general even). // If you look carefully, you'll see that a corresponds to the // index 1, b to the index 2, and so on. - return message.length()==1 ? " abcdefghij".indexOf(message.toLowerCase()) : -1; + return message.length()==1 ? " abcdefghij".indexOf(message.toLowerCase(Locale.ENGLISH)) : -1; else { // The same as above applies here, albeit in a different way. From 44371e9893b1359e92343c2f3e3a001653a11157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 28 Oct 2021 15:27:27 +0300 Subject: [PATCH 2/2] Locale.ENGLISH -> Locale.ROOT --- build.gradle | 4 +- .../jagrosh/jdautilities/command/Command.java | 6 +- .../command/impl/CommandClientImpl.java | 28 +++++----- .../commons/utils/FinderUtil.java | 56 +++++++++---------- .../examples/command/RoleinfoCommand.java | 2 +- .../jdautilities/menu/OrderedMenu.java | 2 +- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index 13ca6a3b..da570ccd 100644 --- a/build.gradle +++ b/build.gradle @@ -51,8 +51,8 @@ allprojects { json = { [group: 'org.json', name: 'json', version: jsonVersion] } junit = { [group: 'junit', name: 'junit', version: junitVersion] } - artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase(Locale.ENGLISH) - moduleName = "${group}.jdautilities${rootProject == project? "" : ".${project.name.toLowerCase(Locale.ENGLISH)}"}" + artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase(Locale.ROOT) + moduleName = "${group}.jdautilities${rootProject == project? "" : ".${project.name.toLowerCase(Locale.ROOT)}"}" } // Helper task that allows us to do a one-line method call to fully diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/Command.java b/command/src/main/java/com/jagrosh/jdautilities/command/Command.java index 0a2d254d..30debda1 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/Command.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/Command.java @@ -415,13 +415,13 @@ public boolean isAllowed(TextChannel channel) String topic = channel.getTopic(); if(topic==null || topic.isEmpty()) return true; - topic = topic.toLowerCase(Locale.ENGLISH); - String lowerName = name.toLowerCase(Locale.ENGLISH); + topic = topic.toLowerCase(Locale.ROOT); + String lowerName = name.toLowerCase(Locale.ROOT); if(topic.contains("{"+lowerName+"}")) return true; if(topic.contains("{-"+lowerName+"}")) return false; - String lowerCat = category==null ? null : category.getName().toLowerCase(Locale.ENGLISH); + String lowerCat = category==null ? null : category.getName().toLowerCase(Locale.ROOT); if(lowerCat!=null) { if(topic.contains("{"+lowerCat+"}")) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index c2332c85..eeeaca64 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -313,13 +313,13 @@ public void addCommand(Command command, int index) throw new ArrayIndexOutOfBoundsException("Index specified is invalid: ["+index+"/"+commands.size()+"]"); synchronized(commandIndex) { - String name = command.getName().toLowerCase(Locale.ENGLISH); + String name = command.getName().toLowerCase(Locale.ROOT); //check for collision if(commandIndex.containsKey(name)) throw new IllegalArgumentException("Command added has a name or alias that has already been indexed: \""+name+"\"!"); for(String alias : command.getAliases()) { - if(commandIndex.containsKey(alias.toLowerCase(Locale.ENGLISH))) + if(commandIndex.containsKey(alias.toLowerCase(Locale.ROOT))) throw new IllegalArgumentException("Command added has a name or alias that has already been indexed: \""+alias+"\"!"); } //shift if not append @@ -331,7 +331,7 @@ public void addCommand(Command command, int index) //add commandIndex.put(name, index); for(String alias : command.getAliases()) - commandIndex.put(alias.toLowerCase(Locale.ENGLISH), index); + commandIndex.put(alias.toLowerCase(Locale.ROOT), index); } commands.add(index,command); } @@ -349,7 +349,7 @@ public void addSlashCommand(SlashCommand command, int index) throw new ArrayIndexOutOfBoundsException("Index specified is invalid: ["+index+"/"+slashCommands.size()+"]"); synchronized(slashCommandIndex) { - String name = command.getName().toLowerCase(Locale.ENGLISH); + String name = command.getName().toLowerCase(Locale.ROOT); //check for collision if(slashCommandIndex.containsKey(name)) throw new IllegalArgumentException("Command added has a name that has already been indexed: \""+name+"\"!"); @@ -370,13 +370,13 @@ public void removeCommand(String name) { synchronized(commandIndex) { - if(!commandIndex.containsKey(name.toLowerCase(Locale.ENGLISH))) + if(!commandIndex.containsKey(name.toLowerCase(Locale.ROOT))) throw new IllegalArgumentException("Name provided is not indexed: \"" + name + "\"!"); - int targetIndex = commandIndex.remove(name.toLowerCase(Locale.ENGLISH)); + int targetIndex = commandIndex.remove(name.toLowerCase(Locale.ROOT)); Command removedCommand = commands.remove(targetIndex); for(String alias : removedCommand.getAliases()) { - commandIndex.remove(alias.toLowerCase(Locale.ENGLISH)); + commandIndex.remove(alias.toLowerCase(Locale.ROOT)); } commandIndex.entrySet().stream().filter(entry -> entry.getValue()>targetIndex).collect(Collectors.toList()) .forEach(entry -> commandIndex.put(entry.getKey(), entry.getValue()-1)); @@ -632,7 +632,7 @@ else if(event.isFromType(ChannelType.PRIVATE) || event.getTextChannel().canTalk( final Command command; // this will be null if it's not a command synchronized(commandIndex) { - int i = commandIndex.getOrDefault(name.toLowerCase(Locale.ENGLISH), -1); + int i = commandIndex.getOrDefault(name.toLowerCase(Locale.ROOT), -1); command = i != -1? commands.get(i) : null; } @@ -682,15 +682,15 @@ private MessageParts getParts(MessageReceivedEvent event) { } } - final String lowerCaseContent = rawContent.toLowerCase(Locale.ENGLISH); + final String lowerCaseContent = rawContent.toLowerCase(Locale.ROOT); // Check for default prefix - if (lowerCaseContent.startsWith(prefix.toLowerCase(Locale.ENGLISH))) { + if (lowerCaseContent.startsWith(prefix.toLowerCase(Locale.ROOT))) { final int prefixLength = prefix.length(); return makeMessageParts(rawContent, prefixLength); } // Check for alternate prefix - if(altprefix != null && lowerCaseContent.startsWith(altprefix.toLowerCase(Locale.ENGLISH))) { + if(altprefix != null && lowerCaseContent.startsWith(altprefix.toLowerCase(Locale.ROOT))) { final int prefixLength = altprefix.length(); return makeMessageParts(rawContent, prefixLength); } @@ -698,7 +698,7 @@ private MessageParts getParts(MessageReceivedEvent event) { // Check for prefixes if (prefixes != null) { for (String pre : prefixes) { - if (lowerCaseContent.startsWith(pre.toLowerCase(Locale.ENGLISH))) { + if (lowerCaseContent.startsWith(pre.toLowerCase(Locale.ROOT))) { final int prefixLength = pre.length(); return makeMessageParts(rawContent, prefixLength); } @@ -710,7 +710,7 @@ private MessageParts getParts(MessageReceivedEvent event) { Collection prefixes = settings.getPrefixes(); if(prefixes != null) { for(String prefix : prefixes) { - if(lowerCaseContent.startsWith(prefix.toLowerCase(Locale.ENGLISH))) { + if(lowerCaseContent.startsWith(prefix.toLowerCase(Locale.ROOT))) { final int prefixLength = prefix.length(); return makeMessageParts(rawContent, prefixLength); } @@ -778,7 +778,7 @@ private void onSlashCommand(SlashCommandEvent event) final SlashCommand command; // this will be null if it's not a command synchronized(slashCommandIndex) { - int i = slashCommandIndex.getOrDefault(event.getName().toLowerCase(Locale.ENGLISH), -1); + int i = slashCommandIndex.getOrDefault(event.getName().toLowerCase(Locale.ROOT), -1); command = i != -1? slashCommands.get(i) : null; } diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java index a303489c..4cd81ea6 100644 --- a/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java +++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java @@ -140,10 +140,10 @@ private static List jdaUserSearch(String query, JDA jda, boolean useShardM } else if(fullRefMatch.matches()) { - String lowerName = fullRefMatch.group(1).toLowerCase(Locale.ENGLISH); + String lowerName = fullRefMatch.group(1).toLowerCase(Locale.ROOT); String discrim = fullRefMatch.group(2); List users = (manager != null ? manager.getUserCache() : jda.getUserCache()) - .stream().filter(user -> user.getName().toLowerCase(Locale.ENGLISH).equals(lowerName) + .stream().filter(user -> user.getName().toLowerCase(Locale.ROOT).equals(lowerName) && user.getDiscriminator().equals(discrim)) .collect(Collectors.toList()); if(!users.isEmpty()) @@ -160,16 +160,16 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); (manager != null? manager.getUserCache() : jda.getUserCache()).forEach(user -> { String name = user.getName(); if(name.equals(query)) exact.add(user); else if (name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(user); - else if (name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) + else if (name.toLowerCase(Locale.ROOT).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(user); - else if (name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) + else if (name.toLowerCase(Locale.ROOT).contains(lowerquery) && startswith.isEmpty()) contains.add(user); }); if(!exact.isEmpty()) @@ -256,7 +256,7 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerQuery = query.toLowerCase(Locale.ENGLISH); + String lowerQuery = query.toLowerCase(Locale.ROOT); for(User u: bans) { // If a discrim is specified then we skip all users without it. @@ -267,9 +267,9 @@ else if(DISCORD_ID.matcher(query).matches()) exact.add(u); else if(exact.isEmpty() && u.getName().equalsIgnoreCase(query)) wrongcase.add(u); - else if(wrongcase.isEmpty() && u.getName().toLowerCase(Locale.ENGLISH).startsWith(lowerQuery)) + else if(wrongcase.isEmpty() && u.getName().toLowerCase(Locale.ROOT).startsWith(lowerQuery)) startswith.add(u); - else if(startswith.isEmpty() && u.getName().toLowerCase(Locale.ENGLISH).contains(lowerQuery)) + else if(startswith.isEmpty() && u.getName().toLowerCase(Locale.ROOT).contains(lowerQuery)) contains.add(u); } if(!exact.isEmpty()) @@ -320,10 +320,10 @@ public static List findMembers(String query, Guild guild) } else if(fullRefMatch.matches()) { - String lowerName = fullRefMatch.group(1).toLowerCase(Locale.ENGLISH); + String lowerName = fullRefMatch.group(1).toLowerCase(Locale.ROOT); String discrim = fullRefMatch.group(2); List members = guild.getMemberCache().stream() - .filter(member -> member.getUser().getName().toLowerCase(Locale.ENGLISH).equals(lowerName) + .filter(member -> member.getUser().getName().toLowerCase(Locale.ROOT).equals(lowerName) && member.getUser().getDiscriminator().equals(discrim)) .collect(Collectors.toList()); if(!members.isEmpty()) @@ -339,7 +339,7 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); guild.getMemberCache().forEach(member -> { String name = member.getUser().getName(); String effName = member.getEffectiveName(); @@ -347,9 +347,9 @@ else if(DISCORD_ID.matcher(query).matches()) exact.add(member); else if((name.equalsIgnoreCase(query) || effName.equalsIgnoreCase(query)) && exact.isEmpty()) wrongcase.add(member); - else if((name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) || effName.toLowerCase(Locale.ENGLISH).startsWith(lowerquery)) && wrongcase.isEmpty()) + else if((name.toLowerCase(Locale.ROOT).startsWith(lowerquery) || effName.toLowerCase(Locale.ROOT).startsWith(lowerquery)) && wrongcase.isEmpty()) startswith.add(member); - else if((name.toLowerCase(Locale.ENGLISH).contains(lowerquery) || effName.toLowerCase(Locale.ENGLISH).contains(lowerquery)) && startswith.isEmpty()) + else if((name.toLowerCase(Locale.ROOT).contains(lowerquery) || effName.toLowerCase(Locale.ROOT).contains(lowerquery)) && startswith.isEmpty()) contains.add(member); }); if(!exact.isEmpty()) @@ -473,16 +473,16 @@ private static List genericTextChannelSearch(String query, Snowflak ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); cache.forEach((tc) -> { String name = tc.getName(); if(name.equals(query)) exact.add(tc); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(tc); - else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(tc); - else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).contains(lowerquery) && startswith.isEmpty()) contains.add(tc); }); if(!exact.isEmpty()) @@ -580,16 +580,16 @@ private static List genericVoiceChannelSearch(String query, Snowfl ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); cache.forEach((vc) -> { String name = vc.getName(); if(name.equals(query)) exact.add(vc); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(vc); - else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(vc); - else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).contains(lowerquery) && startswith.isEmpty()) contains.add(vc); }); if(!exact.isEmpty()) @@ -688,16 +688,16 @@ private static List genericCategorySearch(String query, SnowflakeCache ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); cache.forEach(cat -> { String name = cat.getName(); if(name.equals(query)) exact.add(cat); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(cat); - else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(cat); - else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).contains(lowerquery) && startswith.isEmpty()) contains.add(cat); }); if(!exact.isEmpty()) @@ -743,16 +743,16 @@ else if(DISCORD_ID.matcher(query).matches()) ArrayList wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); guild.getRoleCache().forEach((role) -> { String name = role.getName(); if(name.equals(query)) exact.add(role); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(role); - else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(role); - else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).contains(lowerquery) && startswith.isEmpty()) contains.add(role); }); if(!exact.isEmpty()) @@ -888,16 +888,16 @@ private static List genericEmoteSearch(String query, SnowflakeCacheView wrongcase = new ArrayList<>(); ArrayList startswith = new ArrayList<>(); ArrayList contains = new ArrayList<>(); - String lowerquery = query.toLowerCase(Locale.ENGLISH); + String lowerquery = query.toLowerCase(Locale.ROOT); cache.forEach(emote -> { String name = emote.getName(); if(name.equals(query)) exact.add(emote); else if(name.equalsIgnoreCase(query) && exact.isEmpty()) wrongcase.add(emote); - else if(name.toLowerCase(Locale.ENGLISH).startsWith(lowerquery) && wrongcase.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).startsWith(lowerquery) && wrongcase.isEmpty()) startswith.add(emote); - else if(name.toLowerCase(Locale.ENGLISH).contains(lowerquery) && startswith.isEmpty()) + else if(name.toLowerCase(Locale.ROOT).contains(lowerquery) && startswith.isEmpty()) contains.add(emote); }); if(!exact.isEmpty()) diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java index 5fff709c..f075492e 100644 --- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java +++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java @@ -85,7 +85,7 @@ else if(found.size()>1) StringBuilder desr = new StringBuilder(LINESTART + "ID: **" + role.getId() + "**\n" + LINESTART + "Creation: **" + role.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**\n" + LINESTART + "Position: **" + role.getPosition()+"**\n" - + LINESTART + "Color: **#" + (color==null ? "000000" : Integer.toHexString(color.getRGB()).toUpperCase(Locale.ENGLISH).substring(2)) + "**\n" + + LINESTART + "Color: **#" + (color==null ? "000000" : Integer.toHexString(color.getRGB()).toUpperCase(Locale.ROOT).substring(2)) + "**\n" + LINESTART + "Mentionable: **" + role.isMentionable() + "**\n" + LINESTART + "Hoisted: **" + role.isHoisted() + "**\n" + LINESTART + "Managed: **" + role.isManaged() + "**\n" diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java index 7e390ad0..10320cbd 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java @@ -325,7 +325,7 @@ private int getMessageNumber(String message) // is 10 (the maximum number of choices in general even). // If you look carefully, you'll see that a corresponds to the // index 1, b to the index 2, and so on. - return message.length()==1 ? " abcdefghij".indexOf(message.toLowerCase(Locale.ENGLISH)) : -1; + return message.length()==1 ? " abcdefghij".indexOf(message.toLowerCase(Locale.ROOT)) : -1; else { // The same as above applies here, albeit in a different way.