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 c39873c commit 69a8e73
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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>
Expand Down
17 changes: 9 additions & 8 deletions src/main/kotlin/org/fuchss/matrix/mensa/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,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
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/org/fuchss/matrix/mensa/Translation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.Duration

class TranslationService(private val config: TranslationConfig?) {
class TranslationService(
private val config: TranslationConfig?
) {
private val logger: Logger = LoggerFactory.getLogger(TranslationService::class.java)

private val chatModel = config?.let { createChatModel(it) }
Expand Down Expand Up @@ -48,7 +50,13 @@ class TranslationService(private val config: TranslationConfig?) {
}

private fun createChatModel(config: TranslationConfig): ChatLanguageModel {
val ollama = OllamaChatModel.builder().baseUrl(config.ollamaServerUrl).modelName(config.model).timeout(Duration.ofMinutes(15)).temperature(0.0)
val ollama =
OllamaChatModel
.builder()
.baseUrl(config.ollamaServerUrl)
.modelName(config.model)
.timeout(Duration.ofMinutes(15))
.temperature(0.0)
if (config.ollamaUser != null && config.ollamaPassword != null) {
ollama.customHeaders(mapOf("Authorization" to Credentials.basic(config.ollamaUser, config.ollamaPassword)))
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/org/fuchss/matrix/mensa/api/CanteenLine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ package org.fuchss.matrix.mensa.api
* @param[name] the name of the line
* @param[meals] the food the line serves
*/
data class CanteenLine(val name: String, val meals: List<Meal>)
data class CanteenLine(
val name: String,
val meals: List<Meal>
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import org.fuchss.matrix.mensa.TranslationService
import org.fuchss.matrix.mensa.api.CanteenApi
import org.fuchss.matrix.mensa.handler.sendCanteenEventToRoom

class ShowCommand(private val canteens: List<CanteenApi>, private val translationService: TranslationService) : Command() {
class ShowCommand(
private val canteens: List<CanteenApi>,
private val translationService: TranslationService
) : Command() {
override val name: String = "show"
override val help: String = "show the mensa plan for today, if id provided, show the mensa plan for the canteen with the id"
override val params: String = "[canteen_id]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import org.fuchss.matrix.bots.command.Command
import org.fuchss.matrix.bots.markdown
import org.fuchss.matrix.mensa.Config

class SubscribeCommand(private val config: Config) : Command() {
class SubscribeCommand(
private val config: Config
) : Command() {
override val name: String = "subscribe"
override val help: String = "shows instructions to subscribe for the channel"

Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/org/fuchss/matrix/mensa/kit/SwkaMensa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ class SwkaMensa : CanteenApi {
return mensaLines
}

private fun closed(meals: List<Meal>): Boolean {
return meals.size == 1 && meals[0].name.lowercase().contains("geschlossen")
}
private fun closed(meals: List<Meal>): Boolean = meals.size == 1 && meals[0].name.lowercase().contains("geschlossen")

private fun parseMeal(meal: Element): Meal? {
val nameXPrice = meal.select("span.bg")
Expand Down Expand Up @@ -98,7 +96,11 @@ class SwkaMensa : CanteenApi {
logger.warn("Found invalid additional information format: $additionalInformation")
return emptyList()
}
return additionalInformation.replace("[", "").replace("]", "").split(",").filter { it.isNotBlank() }
return additionalInformation
.replace("[", "")
.replace("]", "")
.split(",")
.filter { it.isNotBlank() }
}

private suspend fun request(weekOfYear: Int): String {
Expand Down

0 comments on commit 69a8e73

Please sign in to comment.