Skip to content

Commit

Permalink
Update Parent & Spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Sep 2, 2024
1 parent 223fb99 commit 5c2bff7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.fuchss</groupId>
<artifactId>maven-parent</artifactId>
<version>0.21.31</version>
<version>0.21.34</version>
</parent>
<groupId>org.fuchss.matrix</groupId>
<artifactId>yarb</artifactId>
Expand Down
17 changes: 9 additions & 8 deletions src/main/kotlin/org/fuchss/matrix/yarb/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ private suspend fun getMatrixClient(config: Config): MatrixClient {
}

val matrixClient =
MatrixClient.login(
baseUrl = Url(config.baseUrl),
identifier = IdentifierType.User(config.username),
password = config.password,
repositoriesModule = createRepositoriesModule(config),
mediaStore = createMediaStore(config),
initialDeviceDisplayName = "${MatrixBot::class.java.`package`.name}-${Random.Default.nextInt()}"
).getOrThrow()
MatrixClient
.login(
baseUrl = Url(config.baseUrl),
identifier = IdentifierType.User(config.username),
password = config.password,
repositoriesModule = createRepositoriesModule(config),
mediaStore = createMediaStore(config),
initialDeviceDisplayName = "${MatrixBot::class.java.`package`.name}-${Random.Default.nextInt()}"
).getOrThrow()

return matrixClient
}
13 changes: 11 additions & 2 deletions src/main/kotlin/org/fuchss/matrix/yarb/TimerManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import java.util.Timer
import java.util.TimerTask
import kotlin.time.Duration.Companion.seconds

class TimerManager(private val matrixBot: MatrixBot, javaTimer: Timer, config: Config) {
class TimerManager(
private val matrixBot: MatrixBot,
javaTimer: Timer,
config: Config
) {
companion object {
val EMOJI = ":+1:".emoji()
private val logger = LoggerFactory.getLogger(TimerManager::class.java)
Expand Down Expand Up @@ -118,7 +122,12 @@ class TimerManager(private val matrixBot: MatrixBot, javaTimer: Timer, config: C
private suspend fun removeReactionOfBot(timer: TimerData): List<UserId> {
timer.redactBotReaction(matrixBot)

val allReactions = matrixBot.room().getTimelineEventReactionAggregation(timer.roomId(), timer.botMessageId()).first().reactions
val allReactions =
matrixBot
.room()
.getTimelineEventReactionAggregation(timer.roomId(), timer.botMessageId())
.first()
.reactions
val reactions = allReactions[EMOJI] ?: return emptyList()
return reactions.filter { it != matrixBot.self() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import org.fuchss.matrix.yarb.TimerManager
import org.fuchss.matrix.yarb.getMessageId
import java.time.LocalTime

class ReminderCommand(private val config: Config, private val timerManager: TimerManager) : Command() {
class ReminderCommand(
private val config: Config,
private val timerManager: TimerManager
) : Command() {
companion object {
const val COMMAND_NAME = "new"
private val TIME_REGEX = Regex("^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$")
Expand Down Expand Up @@ -63,7 +66,8 @@ class ReminderCommand(private val config: Config, private val timerManager: Time
val time = LocalTime.parse(timeXmessage[0]).withSecond(0).minusMinutes(config.offsetInMinutes)
val now = LocalTime.now()
if (now.isAfter(time)) {
matrixBot.room()
matrixBot
.room()
.sendMessage(roomId) {
text(
"Time $time is in the past. I can only remind you at the same day :) Also remember that I'll inform you ${config.offsetInMinutes} min before :)"
Expand Down

0 comments on commit 5c2bff7

Please sign in to comment.