Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toLowerCase and toUpperCase with English. #30

Merged
merged 2 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
portlek marked this conversation as resolved.
Show resolved Hide resolved
moduleName = "${group}.jdautilities${rootProject == project? "" : ".${project.name.toLowerCase(Locale.ENGLISH)}"}"
}

// Helper task that allows us to do a one-line method call to fully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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+"}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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+"\"!");
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -682,23 +682,23 @@ 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);
}

// 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);
}
Expand All @@ -710,7 +710,7 @@ private MessageParts getParts(MessageReceivedEvent event) {
Collection<String> 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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ private static List<User> 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<User> 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())
Expand All @@ -160,16 +160,16 @@ else if(DISCORD_ID.matcher(query).matches())
ArrayList<User> wrongcase = new ArrayList<>();
ArrayList<User> startswith = new ArrayList<>();
ArrayList<User> 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())
Expand Down Expand Up @@ -256,7 +256,7 @@ else if(DISCORD_ID.matcher(query).matches())
ArrayList<User> wrongcase = new ArrayList<>();
ArrayList<User> startswith = new ArrayList<>();
ArrayList<User> 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.
Expand All @@ -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())
Expand Down Expand Up @@ -320,10 +320,10 @@ public static List<Member> 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<Member> 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())
Expand All @@ -339,17 +339,17 @@ else if(DISCORD_ID.matcher(query).matches())
ArrayList<Member> wrongcase = new ArrayList<>();
ArrayList<Member> startswith = new ArrayList<>();
ArrayList<Member> 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();
if(name.equals(query) || effName.equals(query))
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())
Expand Down Expand Up @@ -473,16 +473,16 @@ private static List<TextChannel> genericTextChannelSearch(String query, Snowflak
ArrayList<TextChannel> wrongcase = new ArrayList<>();
ArrayList<TextChannel> startswith = new ArrayList<>();
ArrayList<TextChannel> 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())
Expand Down Expand Up @@ -580,16 +580,16 @@ private static List<VoiceChannel> genericVoiceChannelSearch(String query, Snowfl
ArrayList<VoiceChannel> wrongcase = new ArrayList<>();
ArrayList<VoiceChannel> startswith = new ArrayList<>();
ArrayList<VoiceChannel> 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())
Expand Down Expand Up @@ -688,16 +688,16 @@ private static List<Category> genericCategorySearch(String query, SnowflakeCache
ArrayList<Category> wrongcase = new ArrayList<>();
ArrayList<Category> startswith = new ArrayList<>();
ArrayList<Category> 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())
Expand Down Expand Up @@ -743,16 +743,16 @@ else if(DISCORD_ID.matcher(query).matches())
ArrayList<Role> wrongcase = new ArrayList<>();
ArrayList<Role> startswith = new ArrayList<>();
ArrayList<Role> 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())
Expand Down Expand Up @@ -888,16 +888,16 @@ private static List<Emote> genericEmoteSearch(String query, SnowflakeCacheView<E
ArrayList<Emote> wrongcase = new ArrayList<>();
ArrayList<Emote> startswith = new ArrayList<>();
ArrayList<Emote> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
Loading