Skip to content

Commit 93f9405

Browse files
committed
added chattimestamp
1 parent 3545f72 commit 93f9405

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

src/main/kotlin/com/lambda/config/groups/FormatterSettings.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ import com.lambda.util.NamedEnum
2323

2424
class FormatterSettings(
2525
c: Configurable,
26-
baseGroup: NamedEnum,
26+
vararg baseGroup: NamedEnum,
2727
) : FormatterConfig, SettingGroup(c) {
28-
val localeEnum by c.setting("Locale", FormatterConfig.Locales.US, "The regional formatting used for numbers").group(baseGroup).index()
28+
val localeEnum by c.setting("Locale", FormatterConfig.Locales.US, "The regional formatting used for numbers").group(*baseGroup).index()
2929
override val locale get() = localeEnum.locale
3030

31-
val sep by c.setting("Separator", FormatterConfig.TupleSeparator.Comma, "Separator for string serialization of tuple data structures").group(baseGroup).index()
32-
val customSep by c.setting("Custom Separator", "") { sep == FormatterConfig.TupleSeparator.Custom }.group(baseGroup).index()
31+
val sep by c.setting("Separator", FormatterConfig.TupleSeparator.Comma, "Separator for string serialization of tuple data structures").group(*baseGroup).index()
32+
val customSep by c.setting("Custom Separator", "") { sep == FormatterConfig.TupleSeparator.Custom }.group(*baseGroup).index()
3333
override val separator get() = if (sep == FormatterConfig.TupleSeparator.Custom) customSep else sep.separator
3434

35-
val group by c.setting("Tuple Prefix", FormatterConfig.TupleGrouping.Parentheses).group(baseGroup).index()
35+
val group by c.setting("Tuple Prefix", FormatterConfig.TupleGrouping.Parentheses).group(*baseGroup).index()
3636
override val prefix get() = group.prefix
3737
override val postfix get() = group.postfix
3838

39-
val floatingPrecision by c.setting("Floating Precision", 3, 0..6, 1, "Precision for floating point numbers").group(baseGroup).index()
39+
val floatingPrecision by c.setting("Floating Precision", 3, 0..6, 1, "Precision for floating point numbers").group(*baseGroup).index()
4040
override val precision get() = floatingPrecision
4141

42-
val timeFormat by c.setting("Time Format", FormatterConfig.Time.IsoDateTime).group(baseGroup).index()
42+
val timeFormat by c.setting("Time Format", FormatterConfig.Time.IsoDateTime).group(*baseGroup).index()
4343
override val format get() = timeFormat.format
4444
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.chat
19+
20+
import com.lambda.config.applyEdits
21+
import com.lambda.config.groups.FormatterConfig
22+
import com.lambda.config.groups.FormatterSettings
23+
import com.lambda.event.events.ChatEvent
24+
import com.lambda.event.listener.SafeListener.Companion.listen
25+
import com.lambda.module.Module
26+
import com.lambda.module.tag.ModuleTag
27+
import com.lambda.util.Formatting.format
28+
import com.lambda.util.text.buildText
29+
import com.lambda.util.text.literal
30+
import com.lambda.util.text.styled
31+
import com.lambda.util.text.text
32+
import java.awt.Color
33+
import java.time.LocalDateTime
34+
import java.time.ZoneId
35+
import java.time.ZonedDateTime
36+
import java.time.temporal.ChronoUnit
37+
38+
object ChatTimestamp : Module(
39+
name = "ChatTimestamp",
40+
description = "Displays the time a message was sent next to it",
41+
tag = ModuleTag.CHAT,
42+
) {
43+
val formatter = FormatterSettings(this).apply { applyEdits { hide(::localeEnum, ::sep, ::customSep, ::group, ::floatingPrecision); editTyped(::timeFormat) { defaultValue(FormatterConfig.Time.IsoLocalTime) } } }
44+
45+
private val currentTime get() =
46+
ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault())
47+
.truncatedTo(ChronoUnit.MINUTES)
48+
49+
init {
50+
listen<ChatEvent.Receive> {
51+
it.message = buildText {
52+
text(it.message)
53+
literal(" ")
54+
styled(Color.GRAY, italic = true) { literal(currentTime.format(formatter)) }
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)