Skip to content

Commit fb59e21

Browse files
committed
Fix stuff
- Migrate to new IRIS endpoint - Fix query
1 parent 0a41070 commit fb59e21

3 files changed

Lines changed: 9 additions & 18 deletions

File tree

bot/src/main/kotlin/commands/CurrentRideCommand.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ suspend fun RegenbogenICEExtension.currentRideCommand() =
5959
val details = detailsDeferred.await() ?: return@async defaultText
6060
val id = details.stops[index].station.id
6161

62-
val url = marudor.hafas.detailsRedirect(details.journeyId)
63-
val response = client.get(url)
6462
val marudorUrl = marudor.buildUrl {
65-
takeFrom(response.headers[HttpHeaders.Location]!!)
66-
pathSegments = encodedPathSegments // small hack to encode path
63+
path("/details/", "${details.train.type} ${details.train.number}", details.departure.scheduledTime.toString())
6764
parameters.append("stop", id)
6865
}
6966
"[$defaultText]($marudorUrl)"
@@ -86,7 +83,7 @@ suspend fun RegenbogenICEExtension.currentRideCommand() =
8683
)
8784
}
8885
val details = scope.async {
89-
marudor.hafas.details("${currentTrip.trainType} ${currentTrip.trainNumber}")
86+
marudor.journeys.details("${currentTrip.trainType} ${currentTrip.trainNumber}")
9087
}
9188
val originText =
9289
scope.fetchMarudorUrlAsync(stops, details, 0)

bot/src/main/kotlin/presence/RailTrackPresence.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import kotlinx.coroutines.sync.Mutex
1616
import kotlinx.coroutines.sync.Semaphore
1717
import kotlinx.coroutines.sync.withLock
1818
import kotlinx.coroutines.sync.withPermit
19-
import org.litote.kmongo.and
20-
import org.litote.kmongo.eq
21-
import org.litote.kmongo.`in`
22-
import org.litote.kmongo.newId
19+
import kotlinx.serialization.encodeToString
20+
import kotlinx.serialization.json.Json
21+
import org.litote.kmongo.*
2322
import kotlin.coroutines.CoroutineContext
2423
import kotlin.time.Duration.Companion.seconds
2524

@@ -42,12 +41,12 @@ class RailTrackPresence(private val kord: Kord, database: Database) : CoroutineS
4241
kord.editPresence {
4342
watching("${trip.displayName} to ${trip.destinationStation}")
4443
}
45-
checkNotifications()
4644
} else {
4745
kord.editPresence {
4846
listening("Einfahrtgeräusche")
4947
}
5048
}
49+
checkNotifications()
5150
delay(30.seconds)
5251
}
5352
}
@@ -63,13 +62,8 @@ class RailTrackPresence(private val kord: Kord, database: Database) : CoroutineS
6362
semaphore.withPermit {
6463
val (days, embeds) = buildNotificationMessage(user, notifications)
6564
?: return@launch
66-
val existingNotification =
67-
sentNotifications.findOne(
68-
and(
69-
SentNotification::user eq user,
70-
SentNotification::days `in` days,
71-
)
72-
)
65+
val query = """{"${'$'}and": [{"user": ${user.value}}, {"days": {"${'$'}in": ${Json.encodeToString(days)}}}]}""".trimIndent()
66+
val existingNotification = sentNotifications.findOne(query)
7367
runCatching {
7468
val channel = kord.getUser(user)?.getDmChannelOrNull() ?: return@launch
7569
if (existingNotification != null) {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ktor-client-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json",
1111
ktor-client-resources = { module = "io.ktor:ktor-client-resources", version.ref = "ktor" }
1212
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
1313
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version = "0.4.0" }
14-
marudor = { module = "dev.schlaubi:marudor-client-jvm", version = "1.0-20220712.004353-5" }
14+
marudor = { module = "dev.schlaubi:marudor-client-jvm", version = "1.0-SNAPSHOT" }
1515
regenbogen-ice = { module = "dev.schlaubi:regenbogen-ice-client-jvm", version = "1.0-20220715.093651-3" }
1616
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
1717
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }

0 commit comments

Comments
 (0)