Skip to content

Commit

Permalink
messageWithoutWebhook(ForMultiServer)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Jul 10, 2024
1 parent ee9678f commit c7bd0e5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,16 @@ public static void init() {
private static void sendDiscordMessage(String content, String username, String avatar_url) {
if (!CONFIG.generic.useWebhook) {
if (CONFIG.multiServer.enable) {
CHANNEL.sendMessage(Translations.translateMessage("message.messageWithoutWebhookForMultiServer")
.replace("%server%", CONFIG.multiServer.name)
.replace("%name%", username)
.replace("%message%", content)).queue();
CHANNEL.sendMessage(PlaceholderParser.parseMessageWithoutWebhookForMultiServer(
CONFIG.multiServer.name,
username,
content
).getString()).queue();
} else {
CHANNEL.sendMessage(Translations.translateMessage("message.messageWithoutWebhook")
.replace("%name%", username)
.replace("%message%", content)).queue();
CHANNEL.sendMessage(PlaceholderParser.parseMessageWithoutWebhook(
username,
content
).getString()).queue();
}
} else {
JsonObject body = new JsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,33 @@ public static Component parseHighMspt(String mspt, String msptLimit) {

return parser.parseText(TextNode.of(Translations.translateMessage("message.highMspt")), PlaceholderContext.of(SERVER).asParserContext());
}

public static Component parseMessageWithoutWebhook(String name, String message) {
Map<String, TextNode> placeholders = Map.of(
"name", TextNode.of(name),
"message", TextNode.of(message)
);

NodeParser parser = ParserBuilder.of()
.add(DISCORD_PARSER)
.customTags(TagLikeParser.PLACEHOLDER_ALTERNATIVE, TagLikeParser.Provider.placeholder(placeholders::get))
.build();

return parser.parseText(TextNode.of(Translations.translateMessage("message.messageWithoutWebhook")), PlaceholderContext.of(SERVER).asParserContext());
}

public static Component parseMessageWithoutWebhookForMultiServer(String server, String name, String message) {
Map<String, TextNode> placeholders = Map.of(
"server", TextNode.of(server),
"name", TextNode.of(name),
"message", TextNode.of(message)
);

NodeParser parser = ParserBuilder.of()
.add(DISCORD_PARSER)
.customTags(TagLikeParser.PLACEHOLDER_ALTERNATIVE, TagLikeParser.Provider.placeholder(placeholders::get))
.build();

return parser.parseText(TextNode.of(Translations.translateMessage("message.messageWithoutWebhookForMultiServer")), PlaceholderContext.of(SERVER).asParserContext());
}
}
4 changes: 2 additions & 2 deletions wrapper/src/main/resources/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"message.otherMessage": "<blue><bold>[{server}]</bold></blue> <gray>{message}</gray>",
"message.commandNotice": "<color:{roleColor}>{name}</color> <gray>执行了 {command} 命令!</gray>",

"message.messageWithoutWebhook": "<%name%> %message%",
"message.messageWithoutWebhookForMultiServer": "[%server%] <%name%> %message%",
"message.messageWithoutWebhook": "<{name}> {message}",
"message.messageWithoutWebhookForMultiServer": "[{server}] <{name}> {message}",

"message.serverStarted": "**服务器已启动!**",
"message.serverStopped": "**服务器已关闭!**",
Expand Down

0 comments on commit c7bd0e5

Please sign in to comment.