mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
add days placeholder
- days placeholder <days:yyyy-mm-dd> pattern added.
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user