1
1
package me.moeszyslak.logbot.embeds
2
2
3
3
import dev.kord.common.kColor
4
+ import dev.kord.core.entity.User
4
5
import dev.kord.rest.builder.message.EmbedBuilder
5
- import me.jakejmattson.discordkt.util.simpleDescriptor
6
+ import me.jakejmattson.discordkt.util.*
6
7
import me.moeszyslak.logbot.extensions.createContinuableField
7
8
import me.moeszyslak.logbot.services.CachedMessage
8
9
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 )"
11
16
12
17
fun EmbedBuilder.createMessageDeleteEmbed (cachedMessage : CachedMessage ) {
13
18
title = " Message Deleted"
14
19
color = Color .RED .kColor
15
20
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)
27
23
28
24
createContinuableField(" Content" , cachedMessage.content)
29
25
@@ -34,49 +30,26 @@ fun EmbedBuilder.createMessageDeleteEmbed(cachedMessage: CachedMessage) {
34
30
}
35
31
}
36
32
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))
43
34
}
44
35
45
36
fun EmbedBuilder.createMessageEditedEmbed (newMessage : CachedMessage , cachedMessage : CachedMessage ) {
46
37
title = " Message Edited"
47
38
color = Color .ORANGE .kColor
48
39
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)
60
42
61
43
field {
62
44
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} )"
64
47
inline = true
65
48
}
66
49
67
50
createContinuableField(" Old" , cachedMessage.content)
68
51
createContinuableField(" New" , newMessage.content)
69
52
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))
82
55
}
0 commit comments