Skip to content

Commit

Permalink
Parse markdown in Discord -> Minecraft messages
Browse files Browse the repository at this point in the history
  • Loading branch information
unilock committed Apr 15, 2024
1 parent dd25043 commit c54b9c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.9

# Mod Properties
mod_version=2.1.0
mod_version=2.2.0
maven_group=cc.unilock.nilcord
archives_base_name=nilcord

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/cc/unilock/nilcord/util/TextUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cc.unilock.nilcord.util;

import eu.pb4.placeholders.api.ParserContext;
import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.TextParserUtils;
import eu.pb4.placeholders.api.parsers.MarkdownLiteParserV1;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
Expand Down Expand Up @@ -33,7 +35,7 @@ public static Text parseDiscordMessage(String template, String attachmentChunk,
"reply_format", replyChunk,
"username", Text.literal(author.getName()),
"nickname", Text.literal(member.getEffectiveName()),
"message", Text.literal(message.getContentDisplay())
"message", MarkdownLiteParserV1.ALL.parseText(message.getContentDisplay(), ParserContext.of())
);

return Placeholders.parseText(parse(template), ANGLE_BRACKETS, placeholders);
Expand All @@ -50,7 +52,7 @@ public static Text parseDiscordReply(String template, Message refMessage) {
Map<String, Text> placeholders = Map.of(
"reply_username", Text.literal(refAuthor.getName()),
"reply_nickname", Text.literal(refMember == null ? refAuthor.getEffectiveName() : refMember.getEffectiveName()),
"reply_message", Text.literal(refMessage.getContentDisplay())
"reply_message", MarkdownLiteParserV1.ALL.parseText(refMessage.getContentDisplay(), ParserContext.of())
);

return Placeholders.parseText(parse(template), ANGLE_BRACKETS, placeholders);
Expand Down

0 comments on commit c54b9c1

Please sign in to comment.