learning api
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
val ktorVersion = "1.6.7"
|
||||
val kotlinVersion = "1.6.10"
|
||||
|
||||
|
||||
plugins {
|
||||
application
|
||||
kotlin("jvm") version "1.6.10"
|
||||
@@ -9,15 +5,13 @@ plugins {
|
||||
|
||||
group = "eu.fosil"
|
||||
version = "0.0.1"
|
||||
application {
|
||||
mainClass.set("eu.fosil.okupamicoche.ApplicationKt")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/ktor/eap") }
|
||||
}
|
||||
|
||||
val ktorVersion = "1.6.7"
|
||||
dependencies {
|
||||
// Ktor
|
||||
implementation("io.ktor:ktor-server-netty:$ktorVersion")
|
||||
@@ -27,9 +21,10 @@ dependencies {
|
||||
implementation("net.folivo:trixnity-appservice:1.1.6")
|
||||
|
||||
// Logger
|
||||
implementation("io.github.microutils:kotlin-logging-jvm:2.1.21")
|
||||
implementation("ch.qos.logback:logback-classic:1.2.10")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.6.10")
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
@@ -38,3 +33,11 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
jvmTarget = "11"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("eu.fosil.okupamicoche.MainKt")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ sender_localpart: "okupamicoche"
|
||||
namespaces:
|
||||
users: [ ]
|
||||
aliases:
|
||||
- regex: "#viaje_.*"
|
||||
exclusive: false
|
||||
- regex: "#viaje.*"
|
||||
exclusive: true
|
||||
rooms: [ ]
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
kotlin.code.style=official
|
||||
org.gradle.daemon=true
|
||||
kotlin.code.style=official
|
||||
@@ -8,11 +8,13 @@ import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.DefaultAppserviceService
|
||||
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.core.model.events.Event
|
||||
import net.folivo.trixnity.core.model.events.MessageEventContent
|
||||
import net.folivo.trixnity.core.model.events.m.room.CreateEventContent
|
||||
import net.folivo.trixnity.core.model.events.m.room.RoomMessageEventContent
|
||||
|
||||
@@ -20,6 +22,8 @@ val matrixClient = MatrixApiClient(
|
||||
baseUrl = Url("http://okupamicoche-synapse:8008/"),
|
||||
).apply { accessToken.value = "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46" }
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
suspend fun main() {
|
||||
coroutineScope {
|
||||
val appserviceService = DefaultAppserviceService(
|
||||
@@ -27,17 +31,29 @@ suspend fun main() {
|
||||
)
|
||||
|
||||
appserviceService.subscribeAllEvents {
|
||||
println(it)
|
||||
logger.debug("All events: $it")
|
||||
}
|
||||
|
||||
appserviceService.subscribe<CreateEventContent> {
|
||||
if (it is Event.RoomEvent) {
|
||||
println("${it.content.creator} created ${it.roomId}")
|
||||
logger.info("${it.content.creator} created room ${it.roomId}")
|
||||
}
|
||||
}
|
||||
|
||||
appserviceService.subscribe<RoomMessageEventContent.TextMessageEventContent> {
|
||||
println("TextMessageEventContent body=${it.content.body}")
|
||||
if (it is Event.MessageEvent) {
|
||||
val roomId = it.roomId
|
||||
logger.info("${it.sender} sent \"${it.content.body}\" on $roomId")
|
||||
|
||||
if (it.content.body.startsWith("!travel")) {
|
||||
logger.info("send!")
|
||||
matrixClient.rooms.joinRoom(roomId)
|
||||
matrixClient.rooms.sendMessageEvent(
|
||||
roomId,
|
||||
RoomMessageEventContent.TextMessageEventContent("Te creo un viaje?")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.event.AppserviceEventTnxService
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
class EventTnxService : AppserviceEventTnxService {
|
||||
override suspend fun eventTnxProcessingState(tnxId: String): AppserviceEventTnxService.EventTnxProcessingState {
|
||||
println("eventTnxProcessingState tnxId=$tnxId")
|
||||
logger.debug("eventTnxProcessingState tnxId=$tnxId")
|
||||
return AppserviceEventTnxService.EventTnxProcessingState.NOT_PROCESSED
|
||||
// return AppserviceEventTnxService.EventTnxProcessingState.PROCESSED
|
||||
}
|
||||
|
||||
override suspend fun onEventTnxProcessed(tnxId: String) {
|
||||
println("onEventTnxProcessed tnxId=$tnxId")
|
||||
logger.debug("onEventTnxProcessed tnxId=$tnxId")
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,31 @@
|
||||
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
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.client.api.model.rooms.Visibility
|
||||
import net.folivo.trixnity.core.model.RoomAliasId
|
||||
import net.folivo.trixnity.core.model.RoomId
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
class RoomService : AppserviceRoomService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
|
||||
override suspend fun getCreateRoomParameter(roomAlias: RoomAliasId): CreateRoomParameter {
|
||||
println("getCreateRoomParameter")
|
||||
return CreateRoomParameter()
|
||||
logger.info("getCreateRoomParameter")
|
||||
return CreateRoomParameter(Visibility.PUBLIC)
|
||||
}
|
||||
|
||||
override suspend fun onCreatedRoom(roomAlias: RoomAliasId, roomId: RoomId) {
|
||||
println("onCreatedRoom")
|
||||
logger.info("onCreatedRoom")
|
||||
}
|
||||
|
||||
override suspend fun roomExistingState(roomAlias: RoomAliasId): AppserviceRoomService.RoomExistingState {
|
||||
println("roomExistingState")
|
||||
logger.info("roomExistingState")
|
||||
return AppserviceRoomService.RoomExistingState.DOES_NOT_EXISTS
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
<pattern>%-5level %logger{36} - %msg%n</pattern>
|
||||
<!-- <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>-->
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
|
||||
Reference in New Issue
Block a user