Skip to content

Commit

Permalink
Fix transcript and join message.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Nov 5, 2024
1 parent 4f61203 commit bca45e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/presti/ree6/events/MenuEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
webhookMessageBuilder.addEmbeds(webhookEmbedBuilder.build());
webhookMessageBuilder.addFile(event.getGuild().getId() + "_" + ticketEntity.getTicketCount() + "_transcript.html",
TranscriptUtil.generateTranscript(event.getJDA(), event.getChannel().asTextChannel().getIterableHistory().reverse().stream().toList(),
event.getChannel().getTimeCreated().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)).replace("T", " "),
ZonedDateTime.now().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)).replace("T", " ")).getBytes(StandardCharsets.UTF_8));
event.getChannel().getTimeCreated().toZonedDateTime().toString().trim(),
ZonedDateTime.now().toOffsetDateTime().toZonedDateTime().toString().trim()).getBytes(StandardCharsets.UTF_8));

WebhookUtil.sendWebhook(null, webhookMessageBuilder.build(), ticketEntity.getLogChannelWebhookId(), ticketEntity.getLogChannelWebhookToken(), WebhookUtil.WebhookTyp.TICKET);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/presti/ree6/events/OtherEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
wmb.addFile("welcome.png", ImageCreationUtility.createJoinImage(event.getUser(), joinImage.get().getStringValue(),
messageContent.replace("%user_mention%", event.getMember().getUser().getName())));
} catch (IOException e) {
wmb.setContent(messageContent);
wmb.setContent(messageContent.replace("%user_mention%", event.getMember().getUser().getAsMention()));
log.error("Error while creating join image!", e);
}
} else {
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/de/presti/ree6/utils/data/TranscriptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,28 @@ private TranscriptUtil() {
<img class="rounded-full mr-3" src="%icon%">
</div>
<div class="flex-initial">
<div> Opened: <span class="font-bold">%opened%</span> </div>
<div> Transcript Generated: <span class="font-bold">%closed%</span> </div>
<div> Opened: <span class="font-bold date"><time dateTime="%opened%">%opened%</time></span> </div>
<div> Transcript Generated: <span class="font-bold date"><time dateTime="%closed%">%closed%</time></span> </div>
<div> Total Messages: <span class="font-bold">%messages_count%</span> </div>
</div>
</div>
<div class="messages-container">
%messages%
%messages%
</div>
</div>
</body>
<script>
document.querySelectorAll('time').forEach($e => {
const date = new Date($e.dateTime);
if ($e.classList.contains('short')) {
// output the localized date
$e.innerHTML = date.toLocaleTimeString();
} else {
// output the localized date and time
$e.innerHTML = date.toLocaleString();
}
});
</script>
</html>
""";

Expand All @@ -56,7 +68,7 @@ private TranscriptUtil() {
*/
public static final String messageTemplate = """
<div class="message-breaker"/>
<div class="name font-bold">%name%<span class="date">%time%</span> </div>
<div class="name font-bold">%name%<span class="date"><time dateTime="%time%">%time%</time></span> </div>
<div class="message">
%message%
</div>
Expand All @@ -77,7 +89,8 @@ public static String generateTranscript(JDA selfUser, List<Message> messages, St
messageBuilder.append(messageTemplate
.replace("%name%", message.getAuthor().getName())
.replace("%time%", message.getTimeCreated().toString())
.replace("%message%", message.getContentRaw()));
.replace("%message%", message.getContentRaw()))
.append("\n");
}

return template
Expand Down

0 comments on commit bca45e8

Please sign in to comment.