Skip to content

Commit

Permalink
Support animated emoji + lower case all emote name (closes #102)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisD3D committed May 19, 2024
1 parent f485181 commit 87a1c58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class M2DUtils {
public static final File CONFIG_FILE = new File("config", "mc2discord.toml");
public static final Snowflake NIL_SNOWFLAKE = Snowflake.of(0);
private static final Pattern ANY_DISCORD_MENTION_PATTERN = Pattern.compile("<(?::\\w+:|@&*|#)\\d+>");
private static final Pattern ANY_DISCORD_MENTION_PATTERN = Pattern.compile("<(?:a?:\\w+:|@&*|#)\\d+>");
private static final Pattern ANY_DISCORD_NAMED_PATTERN = Pattern.compile("@\\w+|#\\w+|:\\w+:");


Expand Down Expand Up @@ -83,7 +83,7 @@ public static List<String> breakStringInMessages(String input, int maxLineLength
output.append(word);
lineLen += word.length();
}
if (output.length() > 0) {
if (!output.isEmpty()) {
if (surroundWithCodeBlock) {
output.insert(0, "```");
output.append("```");
Expand All @@ -108,8 +108,8 @@ public static String replaceAllMentions(String str, List<User> users, List<Role>

while (matcher.find()) {
String replacement = matcher.group(0);
if (replacement.matches("<(:\\w+:)\\d+>")) { // Emojis
matcher.appendReplacement(builder, Matcher.quoteReplacement(":" + replacement.split(":")[1] + ":"));
if (replacement.matches("<a?(:\\w+:)\\d+>")) { // Emojis
matcher.appendReplacement(builder, Matcher.quoteReplacement(":" + replacement.split(":")[1].toLowerCase() + ":"));
} else if (replacement.matches("<@(\\d+)>")) { // Users
users.stream().filter(partialMember -> partialMember.getId().asString().equals(replacement.substring(2, replacement.length() - 1))).findFirst().ifPresent(user -> matcher.appendReplacement(builder, Matcher.quoteReplacement("@" + user.getUsername())));
} else if (replacement.matches("<@&(\\d+)>")) { // Roles
Expand Down
1 change: 0 additions & 1 deletion shared.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ modDescription=Link your Minecraft chat with your Discord server
modIssueTrackerUrl=https://github.com/DenisD3D/Mc2Discord/issues
modUpdateJsonUrl=https://raw.githubusercontent.com/DenisD3D/Mc2Discord/main/update.json
modDisplayUrl=https://www.curseforge.com/minecraft/mc-mods/mc2discord
discord4jVersion=3.3.0-M2

0 comments on commit 87a1c58

Please sign in to comment.