add days placeholder

- days placeholder <days:yyyy-mm-dd> pattern added.
This commit is contained in:
dalbodeule
2024-07-23 17:44:28 +09:00
parent 3e09989202
commit ff90e5fe7f
3 changed files with 17 additions and 16 deletions

View File

@@ -25,6 +25,7 @@ class MessageHandler(
private val dailyCounterPattern = Regex("<daily_counter:([^>]+)>")
private val namePattern = Regex("<name>")
private val followPattern = Regex("<following>")
private val daysPattern = """<days:(\d{4})-(\d{2})-(\d{2})>""".toRegex()
init {
reloadCommand()
@@ -162,6 +163,16 @@ class MessageHandler(
}
}
result = daysPattern.replace(result) {
val (year, month, day) = it.destructured
val pastDate = LocalDateTime.of(year.toInt(), month.toInt(), day.toInt(), 0, 0, 0)
val today = LocalDateTime.now()
val daysBetween = ChronoUnit.DAYS.between(pastDate, today)
daysBetween.toString()
}
result = counterPattern.replace(result) {
val name = it.groupValues[1]
CounterService.updateCounterValue(name, 1, user).toString()