Fix broadcast tab complete, add placeholder support to Discord formatted broadcast

This commit is contained in:
Vankka 2022-04-12 13:19:26 +03:00
parent eba37d9b6f
commit a84eef853c
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0

View File

@ -80,7 +80,7 @@ public abstract class BroadcastCommand implements GameCommandExecutor, GameComma
.suggester(command)
.then(
GameCommand.stringGreedy("content")
.suggester(command)
.suggester((__, ___, ____) -> Collections.emptyList())
.executor(command)
)
)
@ -132,10 +132,6 @@ public abstract class BroadcastCommand implements GameCommandExecutor, GameComma
GameCommandArguments previousArguments,
String currentInput
) {
if (previousArguments.has("channel")) {
return Collections.emptyList();
}
String input = currentInput.toLowerCase(Locale.ROOT);
return discordSRV.channelConfig().getKeys().stream()
.filter(key -> key.toLowerCase(Locale.ROOT).startsWith(input))
@ -153,14 +149,19 @@ public abstract class BroadcastCommand implements GameCommandExecutor, GameComma
return;
}
content = getContent(content);
SendableDiscordMessage message = getDiscordContent(content);
for (DiscordMessageChannel messageChannel : channels) {
messageChannel.sendMessage(SendableDiscordMessage.builder().setContent(content).build());
messageChannel.sendMessage(message);
}
sender.sendMessage(Component.text("Broadcasted!", NamedTextColor.GRAY));
}
public SendableDiscordMessage getDiscordContent(String content) {
content = getContent(content);
return SendableDiscordMessage.builder().setContent(content).build();
}
public abstract String getContent(String content);
public static class Discord extends BroadcastCommand {
@ -170,9 +171,19 @@ public abstract class BroadcastCommand implements GameCommandExecutor, GameComma
}
@Override
public String getContent(String content) {
public SendableDiscordMessage getDiscordContent(String content) {
return SendableDiscordMessage.builder()
// Keep as is, allow newlines though
return content.replace("\\n", "\n");
.setContent(content.replace("\\n", "\n"))
.toFormatter()
.applyPlaceholderService()
.build();
}
// See above
@Override
public String getContent(String content) {
return null;
}
}