use string chunking for method replyEphemeral(String)
This commit is contained in:
1 parent
8479f719ab
commit
9861fac769
3 files changed
+24
-7
No files matched your search
@@ -65,8 +65,7 @@ public class HelpCommand extends AbstractCommand {
|
||||
Button info = BuiltInTask.createButton(BotInfo.class).primary("Info");
|
||||
Button reportbug = BuiltInTask.createButton(ReportBug.class).danger("Report bug");
|
||||
ActionRow row = ActionRow.of(commands, info, reportbug);
|
||||
context.replyEphemeral("Help has been sent in DM!");
|
||||
context.sendMessageInPrivate("Thanks for using the Net Neutrality Bot! What do you need help with?", List.of(row));
|
||||
context.replyEphemeral("Thanks for using the Net Neutrality Bot! What do you need help with?", List.of(row));
|
||||
return CommandExecutionResult.none();
|
||||
}
|
||||
|
||||
@@ -75,8 +74,7 @@ public class HelpCommand extends AbstractCommand {
|
||||
return CommandExecutionResult.warn("Command does not exist");
|
||||
}
|
||||
|
||||
context.replyEphemeral("Help has been sent in DM!");
|
||||
context.sendMessageInPrivate(MessageFunction.buildCommandHelpMessage(container));
|
||||
context.replyEphemeral(MessageFunction.buildCommandHelpMessage(container));
|
||||
return CommandExecutionResult.none();
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,11 @@ public class MessageCommandContext extends CommandContext {
|
||||
|
||||
@Override
|
||||
public void reply(MessageCreateData messageCreateData, boolean ephemeral, List<LayoutComponent> components, Consumer<AsyncContext> consumer) {
|
||||
if (ephemeral) {
|
||||
sendMessageInPrivate(messageCreateData, components);
|
||||
return;
|
||||
}
|
||||
|
||||
if (getChannel() != null && getChannel().canTalk()) {
|
||||
message.reply(messageCreateData).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
||||
}
|
||||
|
||||
@@ -140,15 +140,23 @@ public interface Context {
|
||||
defer(false, consumer);
|
||||
}
|
||||
|
||||
default void replyEphemeral(MessageCreateData messageCreateData, List<LayoutComponent> components) {
|
||||
reply(messageCreateData, true, components, asyncMessage -> {});
|
||||
}
|
||||
|
||||
default void replyEphemeral(MessageCreateData messageCreateData) {
|
||||
reply(messageCreateData, true, List.of(), asyncMessage -> {});
|
||||
replyEphemeral(messageCreateData, List.of());
|
||||
}
|
||||
|
||||
default void replyEphemeral(String message) {
|
||||
replyEphemeral(MessageCreateData.fromContent(message));
|
||||
replyEphemeralWithLimit(message);
|
||||
}
|
||||
|
||||
default void replyEphemeral(MessageEmbed... embeds) {
|
||||
default void replyEphemeral(String message, List<LayoutComponent> components) {
|
||||
replyEphemeral(MessageCreateData.fromContent(message), components);
|
||||
}
|
||||
|
||||
default void replyEphemeral(List<MessageEmbed> embeds) {
|
||||
replyEphemeral(MessageCreateData.fromEmbeds(embeds));
|
||||
}
|
||||
|
||||
@@ -185,6 +193,12 @@ public interface Context {
|
||||
}
|
||||
}
|
||||
|
||||
private void replyEphemeralWithLimit(String message) {
|
||||
for (String chunk : ContextUtils.splitMessage(message, Message.MAX_CONTENT_LENGTH)) {
|
||||
replyEphemeral(MessageCreateData.fromContent(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessageInPrivateWithLimit(String message) {
|
||||
for (String chunk : ContextUtils.splitMessage(message, Message.MAX_CONTENT_LENGTH)) {
|
||||
sendMessageInPrivate(MessageCreateData.fromContent(chunk));
|
||||
|
||||
Reference in new issue
Block a user