mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 22:05:11 +00:00
fix Discord alias emojis in referenced message parsing
This commit is contained in:
parent
5a0bf63315
commit
397326ecfe
1 changed files with 35 additions and 0 deletions
|
|
@ -58,6 +58,7 @@ public class DiscordMessageParser {
|
|||
|
||||
// Discord custom emoji patterns
|
||||
private static final Pattern CUSTOM_EMOJI_PATTERN = Pattern.compile("<a?:(\\w+):\\d+>");
|
||||
private static final Pattern DISCORD_ALIAS_EMOJI_PATTERN = Pattern.compile("(?<![A-Za-z0-9_]):[A-Za-z0-9_+\\-]+:(?![A-Za-z0-9_])");
|
||||
|
||||
// Unicode emoji pattern (basic, covering common emoji ranges)
|
||||
private static final Pattern UNICODE_EMOJI_PATTERN = Pattern.compile(
|
||||
|
|
@ -1092,6 +1093,7 @@ public class DiscordMessageParser {
|
|||
}
|
||||
if (parseCustomEmojis) {
|
||||
current = splitSegmentsByCustomEmoji(current);
|
||||
current = splitSegmentsByDiscordAliasEmoji(current);
|
||||
}
|
||||
if (parseUnicodeEmojis) {
|
||||
current = splitSegmentsByUnicodeEmoji(current);
|
||||
|
|
@ -1193,6 +1195,39 @@ public class DiscordMessageParser {
|
|||
return out;
|
||||
}
|
||||
|
||||
private static List<TextSegment> splitSegmentsByDiscordAliasEmoji(List<TextSegment> segments) {
|
||||
List<TextSegment> out = new ArrayList<>();
|
||||
for (TextSegment segment : segments) {
|
||||
if (segment.clickUrl != null || segment.text == null || segment.text.isEmpty()) {
|
||||
out.add(segment);
|
||||
continue;
|
||||
}
|
||||
Matcher matcher = DISCORD_ALIAS_EMOJI_PATTERN.matcher(segment.text);
|
||||
int cursor = 0;
|
||||
boolean matched = false;
|
||||
while (matcher.find()) {
|
||||
String alias = matcher.group();
|
||||
if (EmojiManager.getByDiscordAlias(alias).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (matcher.start() > cursor) {
|
||||
out.add(copySegment(segment, segment.text.substring(cursor, matcher.start())));
|
||||
}
|
||||
TextSegment emojiSegment = copySegment(segment, alias);
|
||||
emojiSegment.color = "yellow";
|
||||
out.add(emojiSegment);
|
||||
cursor = matcher.end();
|
||||
matched = true;
|
||||
}
|
||||
if (!matched) {
|
||||
out.add(segment);
|
||||
} else if (cursor < segment.text.length()) {
|
||||
out.add(copySegment(segment, segment.text.substring(cursor)));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static List<TextSegment> splitSegmentsByUnicodeEmoji(List<TextSegment> segments) {
|
||||
List<TextSegment> out = new ArrayList<>();
|
||||
for (TextSegment segment : segments) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue