Archiviert
1
0

Merge pull request 'Add Message Spliting' (#240) from betterDiscord into master

Reviewed-on: SteamWar/BungeeCore#240
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
YoyoNow 2021-09-08 19:47:26 +02:00
Commit 8eaffa1051

Datei anzeigen

@ -75,29 +75,40 @@ public class DiscordTicketListener extends BasicDiscordListener {
} else if(event.getComponentId().startsWith("close-")) { } else if(event.getComponentId().startsWith("close-")) {
TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG); TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG);
MessageBuilder builder = new MessageBuilder(); LinkedList<StringBuilder> stringBuilders = new LinkedList<>();
StringBuilder stringBuilder = new StringBuilder(); stringBuilders.add(new StringBuilder());
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> { new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return; if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return;
stringBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ") StringBuilder currentBuilder = new StringBuilder();
currentBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
.append("**") .append("**")
.append(message.getAuthor().getName()) .append(message.getAuthor().getName())
.append("**: ") .append("**: ")
.append(message.getContentRaw()); .append(message.getContentRaw());
if(!message.getAttachments().isEmpty()) { if(!message.getAttachments().isEmpty()) {
stringBuilder.append("\n") currentBuilder.append("\n")
.append("Files: ").append("\n"); .append("Files: ").append("\n");
message.getAttachments().forEach(attachment -> stringBuilder.append(attachment.getUrl()).append("\n")); message.getAttachments().forEach(attachment -> currentBuilder.append(attachment.getUrl()).append("\n"));
} }
stringBuilder.append("\n"); currentBuilder.append("\n");
if(currentBuilder.length() >= 4096) {
stringBuilders.getLast().append(currentBuilder.substring(0, 4090));
stringBuilders.add(new StringBuilder(currentBuilder.substring(4090, currentBuilder.length() - 1)));
} else if (currentBuilder.length() + stringBuilders.getLast().length() >= 4096) {
stringBuilders.add(new StringBuilder(currentBuilder.toString()));
} else {
stringBuilders.getLast().append(currentBuilder);
}
}); });
stringBuilder.append("\n"); String footer = "<t:" + Instant.now().getEpochSecond() + "> **" + event.getUser().getName() + "**: Ticket geschlossen";
stringBuilder.append("<t:").append(Instant.now().getEpochSecond()).append("> ") if(stringBuilders.getLast().length() + footer.length() > 4090) {
.append("**").append(event.getUser().getName()).append("**: ") stringBuilders.add(new StringBuilder(footer));
.append("Ticket geschlossen"); } else {
stringBuilders.getLast().append(footer);
}
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.GREEN); embedBuilder.setColor(Color.GREEN);
@ -107,11 +118,13 @@ public class DiscordTicketListener extends BasicDiscordListener {
embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl()); embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl());
embedBuilder.setTimestamp(Instant.now()); embedBuilder.setTimestamp(Instant.now());
embedBuilder.setTitle(event.getTextChannel().getName()); embedBuilder.setTitle(event.getTextChannel().getName());
embedBuilder.setDescription(stringBuilder); stringBuilders.forEach(stringBuilder -> {
embedBuilder.setDescription(stringBuilder.toString());
MessageBuilder builder = new MessageBuilder();
builder.setEmbeds(embedBuilder.build()); builder.setEmbeds(embedBuilder.build());
logChannel.sendMessage(builder.build()).complete(); logChannel.sendMessage(builder.build()).queue();
});
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName()); Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
event.getTextChannel().delete().reason("Closed").queue(); event.getTextChannel().delete().reason("Closed").queue();