Skip to content

Commit

Permalink
Add logging when sending periodic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
randomnetcat committed Dec 27, 2023
1 parent 9f33811 commit a46935b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/kotlin/org/randomcat/agorabot/features/PeriodicMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,32 @@ fun periodicMessageSource(): FeatureSource<*> = object : FeatureSource<PeriodicM

if (previousScheduled == null || checkTime >= previousScheduled) {
try {
logger.info("Sending periodic message with ID $id")

jda
.getTextChannelById(messageConfig.discordChannelId)
?.sendMessage(messageConfig.options.random(userFacingRandom()))
?.await()

// Don't need to use an update method because there is only one writer.

val nextTime = randomNextInterval(
checkTime,
messageConfig.randomInterval,
)

currentState.set(
currentState.get().copy(
messages = currentState.get().messages.put(
id,
PeriodicMessageState(
scheduledTime = randomNextInterval(
checkTime,
messageConfig.randomInterval,
),
scheduledTime = nextTime,
),
),
)
)

logger.info("Scheduling period message: ID $id; sent at $checkTime; next send at $nextTime")
} catch (e: Exception) {
logger.error("Error handling periodic message", e)
}
Expand Down

0 comments on commit a46935b

Please sign in to comment.