Exposed
This commit is contained in:
@@ -11,19 +11,31 @@ repositories {
|
||||
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/ktor/eap") }
|
||||
}
|
||||
|
||||
val ktorVersion = "1.6.7"
|
||||
dependencies {
|
||||
// Ktor
|
||||
val ktorVersion: String by project
|
||||
implementation("io.ktor:ktor-server-netty:$ktorVersion")
|
||||
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
||||
|
||||
// Trixnity
|
||||
implementation("net.folivo:trixnity-appservice:1.1.6")
|
||||
implementation("net.folivo:trixnity-appservice:1.1.8")
|
||||
|
||||
// Exposed
|
||||
val exposedVersion: String by project
|
||||
dependencies {
|
||||
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
|
||||
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
|
||||
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
|
||||
}
|
||||
|
||||
// H2 database
|
||||
implementation("com.h2database:h2:2.1.210")
|
||||
|
||||
// Logger
|
||||
implementation("io.github.microutils:kotlin-logging-jvm:2.1.21")
|
||||
implementation("ch.qos.logback:logback-classic:1.2.10")
|
||||
|
||||
// JUnit
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.6.10")
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.code.style=official
|
||||
exposedVersion=0.37.3
|
||||
ktorVersion=1.6.7
|
||||
@@ -3,7 +3,6 @@ package eu.fosil.okupamicoche
|
||||
import eu.fosil.okupamicoche.services.EventTnxService
|
||||
import eu.fosil.okupamicoche.services.RoomService
|
||||
import eu.fosil.okupamicoche.services.UserService
|
||||
import io.ktor.http.*
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.AppserviceService
|
||||
import net.folivo.trixnity.appservice.rest.DefaultAppserviceService
|
||||
@@ -14,13 +13,10 @@ import net.folivo.trixnity.core.model.events.m.room.RoomMessageEventContent
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
val matrixClient = MatrixApiClient(
|
||||
baseUrl = Url("http://okupamicoche-synapse:8008/"),
|
||||
).apply { accessToken.value = "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46" }
|
||||
fun createAppService(matrixApiClient:MatrixApiClient): AppserviceService {
|
||||
|
||||
fun createAppService(): AppserviceService {
|
||||
val appserviceService = DefaultAppserviceService(
|
||||
EventTnxService(), UserService(), RoomService()
|
||||
EventTnxService(), UserService(matrixApiClient), RoomService(matrixApiClient)
|
||||
)
|
||||
|
||||
appserviceService.subscribeAllEvents {
|
||||
@@ -39,8 +35,8 @@ fun createAppService(): AppserviceService {
|
||||
|
||||
if (it.content.body.startsWith("!travel")) {
|
||||
logger.info("send!")
|
||||
matrixClient.rooms.joinRoom(roomId)
|
||||
matrixClient.rooms.sendMessageEvent(
|
||||
matrixApiClient.rooms.joinRoom(roomId)
|
||||
matrixApiClient.rooms.sendMessageEvent(
|
||||
roomId,
|
||||
RoomMessageEventContent.TextMessageEventContent("Te creo un viaje?")
|
||||
)
|
||||
@@ -1,34 +1,55 @@
|
||||
package eu.fosil.okupamicoche
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.launch
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.MatrixAppserviceProperties
|
||||
import net.folivo.trixnity.appservice.rest.matrixAppserviceModule
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.client.api.model.rooms.Visibility
|
||||
import net.folivo.trixnity.core.model.RoomAliasId
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
suspend fun main() {
|
||||
|
||||
val matrixApiClient = MatrixApiClient(
|
||||
baseUrl = Url("http://okupamicoche-synapse:8008/"),
|
||||
).apply { accessToken.value = "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46" }
|
||||
|
||||
coroutineScope {
|
||||
launch {
|
||||
|
||||
val roomAliasRes = matrixClient.rooms.getRoomAlias(RoomAliasId("#viajes:okupamicoche-synapse")).getOrNull()
|
||||
val roomAliasRes =
|
||||
matrixApiClient.rooms.getRoomAlias(RoomAliasId("#viajes:okupamicoche-synapse")).getOrNull()
|
||||
if (roomAliasRes == null) {
|
||||
logger.info("Creating #viajes:okupamicoche-synapse public room")
|
||||
matrixClient.rooms.createRoom(
|
||||
matrixApiClient.rooms.createRoom(
|
||||
visibility = Visibility.PUBLIC,
|
||||
roomAliasId = RoomAliasId("#viajes:okupamicoche-synapse")
|
||||
)
|
||||
} else {
|
||||
val mainRoomId = roomAliasRes.roomId
|
||||
val alreadyJoinedToMainRoom = (matrixApiClient.rooms.getJoinedRooms().getOrNull()?.filter { roomId ->
|
||||
roomId == mainRoomId
|
||||
}?.firstOrNull()) !== null
|
||||
logger.info("alreadyJoinedToMainRoom=$alreadyJoinedToMainRoom")
|
||||
|
||||
val roomStateRes = matrixApiClient.rooms.getState(mainRoomId).getOrNull()
|
||||
roomStateRes?.collect { stateEvent ->
|
||||
logger.debug("stateEvent=$stateEvent")
|
||||
}
|
||||
}
|
||||
|
||||
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
|
||||
matrixAppserviceModule(
|
||||
properties = MatrixAppserviceProperties("312df522183efd404ec1cd22d2ffa4bbc76a8c1ccf541dd692eef281356bb74e"),
|
||||
appserviceService = createAppService()
|
||||
appserviceService = createAppService(matrixApiClient)
|
||||
)
|
||||
}.start(wait = true)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import eu.fosil.okupamicoche.matrixClient
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.room.AppserviceRoomService
|
||||
import net.folivo.trixnity.appservice.rest.room.CreateRoomParameter
|
||||
@@ -11,9 +10,7 @@ import net.folivo.trixnity.core.model.RoomId
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
class RoomService : AppserviceRoomService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
class RoomService(override val matrixApiClient: MatrixApiClient) : AppserviceRoomService {
|
||||
|
||||
override suspend fun getCreateRoomParameter(roomAlias: RoomAliasId): CreateRoomParameter {
|
||||
logger.info("getCreateRoomParameter")
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import eu.fosil.okupamicoche.matrixClient
|
||||
import net.folivo.trixnity.appservice.rest.user.AppserviceUserService
|
||||
import net.folivo.trixnity.appservice.rest.user.RegisterUserParameter
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.core.model.UserId
|
||||
|
||||
class UserService : AppserviceUserService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
class UserService(override val matrixApiClient: MatrixApiClient) : AppserviceUserService {
|
||||
|
||||
override suspend fun getRegisterUserParameter(userId: UserId): RegisterUserParameter {
|
||||
println("getRegisterUserParameter")
|
||||
|
||||
BIN
test.mv.db
Normal file
BIN
test.mv.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user