Merge pull request 'Button Spliting' (#336) from buttons into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #336 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
dbe2349f4f
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.bot.util;
|
package de.steamwar.bungeecore.bot.util;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.DiscordTicketType;
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
@ -32,6 +33,7 @@ import net.dv8tion.jda.api.interactions.components.Button;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class DiscordTicketMessage {
|
public class DiscordTicketMessage {
|
||||||
@ -49,16 +51,26 @@ public class DiscordTicketMessage {
|
|||||||
builder.setTitle("Steamwar-Tickets");
|
builder.setTitle("Steamwar-Tickets");
|
||||||
builder.setColor(Color.RED);
|
builder.setColor(Color.RED);
|
||||||
|
|
||||||
List<Button> buttons = new ArrayList<>();
|
List<List<Button>> buttons = new ArrayList<>();
|
||||||
SteamwarDiscordBotConfig.TICKET_TYPES.forEach((s, discordTicketType) -> buttons.add(discordTicketType.toButton()));
|
chunked(new ArrayList<>(SteamwarDiscordBotConfig.TICKET_TYPES.values()), 5).forEach(discordTicketTypes -> {
|
||||||
|
buttons.add(discordTicketTypes.stream().map(DiscordTicketType::toButton).collect(Collectors.toList()));
|
||||||
|
});
|
||||||
|
|
||||||
MessageBuilder messageBuilder = new MessageBuilder();
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
messageBuilder.setEmbeds(builder.build());
|
messageBuilder.setEmbeds(builder.build());
|
||||||
messageBuilder.setActionRows(ActionRow.of(buttons));
|
messageBuilder.setActionRows(buttons.stream().map(ActionRow::of).collect(Collectors.toList()));
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
message.editMessage(messageBuilder.build()).queue();
|
message.editMessage(messageBuilder.build()).queue();
|
||||||
} else {
|
} else {
|
||||||
channel.sendMessage(messageBuilder.build()).queue();
|
channel.sendMessage(messageBuilder.build()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> List<List<T>> chunked(List<T> list, int chunkSize) {
|
||||||
|
List<List<T>> chunks = new ArrayList<>();
|
||||||
|
for (int i = 0; i < list.size(); i += chunkSize) {
|
||||||
|
chunks.add(list.subList(i, Math.min(i + chunkSize, list.size())));
|
||||||
|
}
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren