Skip to content

Commit 770f88b

Browse files
committed
Formatting improvements
Use Discord timestamps in edit/delete logs instead of literal text. Move jump URLs to the same line in reaction logs now that discord formats message links nicely
1 parent dba50fd commit 770f88b

File tree

2 files changed

+19
-46
lines changed

2 files changed

+19
-46
lines changed
Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
package me.moeszyslak.logbot.embeds
22

33
import dev.kord.common.kColor
4+
import dev.kord.core.entity.User
45
import dev.kord.rest.builder.message.EmbedBuilder
5-
import me.jakejmattson.discordkt.util.simpleDescriptor
6+
import me.jakejmattson.discordkt.util.*
67
import me.moeszyslak.logbot.extensions.createContinuableField
78
import me.moeszyslak.logbot.services.CachedMessage
89
import java.awt.Color
9-
import java.time.ZoneOffset
10-
import java.time.format.DateTimeFormatter
10+
import java.time.Instant
11+
12+
fun formatTimeStamp(timestamp: Instant) =
13+
TimeStamp.at(timestamp, TimeStyle.RELATIVE) + "\n" + TimeStamp.at(timestamp, TimeStyle.DATETIME_LONG)
14+
15+
fun User.formatDisplay() = "$mention ($fullName)"
1116

1217
fun EmbedBuilder.createMessageDeleteEmbed(cachedMessage: CachedMessage) {
1318
title = "Message Deleted"
1419
color = Color.RED.kColor
1520

16-
field {
17-
name = "User"
18-
value = cachedMessage.user.simpleDescriptor()
19-
inline = true
20-
}
21-
22-
field {
23-
name = "Channel"
24-
value = cachedMessage.channel.mention
25-
inline = true
26-
}
21+
addInlineField("User", cachedMessage.user.formatDisplay())
22+
addInlineField("Channel", cachedMessage.channel.mention)
2723

2824
createContinuableField("Content", cachedMessage.content)
2925

@@ -34,49 +30,26 @@ fun EmbedBuilder.createMessageDeleteEmbed(cachedMessage: CachedMessage) {
3430
}
3531
}
3632

37-
field {
38-
name = "Sent at"
39-
value = cachedMessage.timestamp.atOffset(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME)
40-
inline = true
41-
}
42-
33+
addInlineField("Sent at", formatTimeStamp(cachedMessage.timestamp))
4334
}
4435

4536
fun EmbedBuilder.createMessageEditedEmbed(newMessage: CachedMessage, cachedMessage: CachedMessage) {
4637
title = "Message Edited"
4738
color = Color.ORANGE.kColor
4839

49-
field {
50-
name = "User"
51-
value = cachedMessage.user.simpleDescriptor()
52-
inline = true
53-
}
54-
55-
field {
56-
name = "Channel"
57-
value = cachedMessage.channel.mention
58-
inline = true
59-
}
40+
addInlineField("User", cachedMessage.user.formatDisplay())
41+
addInlineField("Channel", cachedMessage.channel.mention)
6042

6143
field {
6244
name = "Link"
63-
value = "[Jump To](https://discord.com/channels/${cachedMessage.guildId}/${cachedMessage.channel.id}/${cachedMessage.messageId})"
45+
value =
46+
"[Jump To](https://discord.com/channels/${cachedMessage.guildId}/${cachedMessage.channel.id}/${cachedMessage.messageId})"
6447
inline = true
6548
}
6649

6750
createContinuableField("Old", cachedMessage.content)
6851
createContinuableField("New", newMessage.content)
6952

70-
71-
field {
72-
name = "Old message sent at"
73-
value = cachedMessage.timestamp.atOffset(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME)
74-
inline = true
75-
}
76-
77-
field {
78-
name = "New message sent at"
79-
value = newMessage.timestamp.atOffset(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME)
80-
inline = true
81-
}
53+
addInlineField("Original", formatTimeStamp(cachedMessage.timestamp))
54+
addInlineField("Edited", formatTimeStamp(newMessage.timestamp))
8255
}

src/main/kotlin/me/moeszyslak/logbot/services/LoggerService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class LoggerService(private val config: Configuration, private val discord: Disc
4848
addToLog(guild, "VOICE LEAVE :: <#${channelId.value}> :: ${user.descriptor()}", false)
4949

5050
fun reactionAdd(guild: Guild, reaction: ReactionEmoji, member: Member, channel: MessageChannelBehavior, jumpUrl: String) =
51-
addToLog(guild, "REACTION ADD :: ${member.descriptor()} :: ${reaction.mention} :: ${channel.mention} \n$jumpUrl", false)
51+
addToLog(guild, "REACTION ADD :: ${member.descriptor()} :: ${reaction.mention} :: ${channel.mention} :: $jumpUrl", false)
5252

5353
fun reactionRemove(guild: Guild, reaction: ReactionEmoji, member: Member, channel: MessageChannelBehavior, jumpUrl: String) =
54-
addToLog(guild, "REACTION REMOVE :: ${member.descriptor()} :: ${reaction.mention} :: ${channel.mention} \n$jumpUrl", false)
54+
addToLog(guild, "REACTION REMOVE :: ${member.descriptor()} :: ${reaction.mention} :: ${channel.mention} :: $jumpUrl", false)
5555

5656
@OptIn(DelicateCoroutinesApi::class)
5757
suspend fun logDaemon() {

0 commit comments

Comments
 (0)