Skip to content
Merged
Prev Previous commit
Next Next commit
added chattimestamp
  • Loading branch information
emyfops committed Dec 21, 2025
commit 93f9405126437cfbabc8d9880381c3da64af3463
14 changes: 7 additions & 7 deletions src/main/kotlin/com/lambda/config/groups/FormatterSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ import com.lambda.util.NamedEnum

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

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

val group by c.setting("Tuple Prefix", FormatterConfig.TupleGrouping.Parentheses).group(baseGroup).index()
val group by c.setting("Tuple Prefix", FormatterConfig.TupleGrouping.Parentheses).group(*baseGroup).index()
override val prefix get() = group.prefix
override val postfix get() = group.postfix

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

val timeFormat by c.setting("Time Format", FormatterConfig.Time.IsoDateTime).group(baseGroup).index()
val timeFormat by c.setting("Time Format", FormatterConfig.Time.IsoDateTime).group(*baseGroup).index()
override val format get() = timeFormat.format
}
58 changes: 58 additions & 0 deletions src/main/kotlin/com/lambda/module/modules/chat/ChatTimestamp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lambda.module.modules.chat

import com.lambda.config.applyEdits
import com.lambda.config.groups.FormatterConfig
import com.lambda.config.groups.FormatterSettings
import com.lambda.event.events.ChatEvent
import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.module.Module
import com.lambda.module.tag.ModuleTag
import com.lambda.util.Formatting.format
import com.lambda.util.text.buildText
import com.lambda.util.text.literal
import com.lambda.util.text.styled
import com.lambda.util.text.text
import java.awt.Color
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit

object ChatTimestamp : Module(
name = "ChatTimestamp",
description = "Displays the time a message was sent next to it",
tag = ModuleTag.CHAT,
) {
val formatter = FormatterSettings(this).apply { applyEdits { hide(::localeEnum, ::sep, ::customSep, ::group, ::floatingPrecision); editTyped(::timeFormat) { defaultValue(FormatterConfig.Time.IsoLocalTime) } } }

private val currentTime get() =
ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault())
.truncatedTo(ChronoUnit.MINUTES)

init {
listen<ChatEvent.Receive> {
it.message = buildText {
text(it.message)
literal(" ")
styled(Color.GRAY, italic = true) { literal(currentTime.format(formatter)) }
}
}
}
}