working ping example using matrix-spring-boot-bot:0.4.8
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,6 +5,10 @@ build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
# App service DB
|
||||
matrix.mv.db
|
||||
matrix.trace.db
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("org.springframework.boot") version "2.6.2"
|
||||
id("org.springframework.boot") version "2.4.13"
|
||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||
kotlin("jvm") version "1.6.10"
|
||||
kotlin("plugin.spring") version "1.6.10"
|
||||
kotlin("jvm") version "1.4.32"
|
||||
kotlin("plugin.spring") version "1.4.32"
|
||||
}
|
||||
|
||||
group = "eu.fosil"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||
java.sourceCompatibility = JavaVersion.VERSION_11
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -19,16 +19,19 @@ dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation ("net.folivo:matrix-spring-boot-bot:0.5.2")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
|
||||
implementation ("net.folivo:matrix-spring-boot-bot:0.4.8")
|
||||
// implementation ("net.folivo:matrix-spring-boot-bot:0.5.2")
|
||||
runtimeOnly("com.h2database:h2")
|
||||
runtimeOnly("io.r2dbc:r2dbc-h2")
|
||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = listOf("-Xjsr305=strict")
|
||||
jvmTarget = "17"
|
||||
jvmTarget = "11"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
id: "Okupa mi coche"
|
||||
url: "http://172.17.0.1:8080"
|
||||
#url: "http://172.17.0.1:8081"
|
||||
as_token: "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46"
|
||||
hs_token: "312df522183efd404ec1cd22d2ffa4bbc76a8c1ccf541dd692eef281356bb74e"
|
||||
sender_localpart: "okupamicoche"
|
||||
@@ -7,5 +8,5 @@ namespaces:
|
||||
users: [ ]
|
||||
aliases:
|
||||
- regex: "#viaje_.*"
|
||||
exclusive: true
|
||||
exclusive: false
|
||||
rooms: [ ]
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
rootProject.name = "okupamicoche"
|
||||
|
||||
// Include matrix-spring-boot-sdk for local development of the sdk
|
||||
//includeBuild("../matrix-spring-boot-sdk")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.fosil.okupamicoche
|
||||
package eu.fosil
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
|
||||
79
src/main/kotlin/eu/fosil/PingHandler.kt
Normal file
79
src/main/kotlin/eu/fosil/PingHandler.kt
Normal file
@@ -0,0 +1,79 @@
|
||||
//package eu.fosil
|
||||
//
|
||||
//import kotlinx.coroutines.flow.collect
|
||||
//import kotlinx.coroutines.flow.filter
|
||||
//import net.folivo.spring.matrix.bot.event.MatrixMessageHandler
|
||||
//import net.folivo.spring.matrix.bot.event.MessageContext
|
||||
//import net.folivo.spring.matrix.bot.user.MatrixUserService
|
||||
//import net.folivo.spring.matrix.bot.util.BotServiceHelper
|
||||
//import net.folivo.trixnity.client.rest.MatrixClient
|
||||
//import net.folivo.trixnity.core.model.events.m.room.MessageEventContent
|
||||
//import org.slf4j.LoggerFactory
|
||||
//import org.springframework.stereotype.Component
|
||||
//
|
||||
//@Component
|
||||
//class PingHandler(
|
||||
// private val matrixClient: MatrixClient,
|
||||
// private val helper: BotServiceHelper,
|
||||
// private val userService: MatrixUserService
|
||||
//) : MatrixMessageHandler {
|
||||
// companion object {
|
||||
// private val LOG = LoggerFactory.getLogger(this::class.java)
|
||||
// }
|
||||
//
|
||||
// override suspend fun handleMessage(content: MessageEventContent, context: MessageContext) {
|
||||
// println("EOEO")
|
||||
// LOG.debug(content.body)
|
||||
// LOG.debug(context.roomId.full)
|
||||
// if (content is MessageEventContent.TextMessageEventContent) {
|
||||
// if (content.body.contains("ping")) {
|
||||
// userService.getUsersByRoom(context.roomId)
|
||||
// .filter { it.isManaged }
|
||||
// .collect { member ->
|
||||
// val messageId = context.answer("pong", asUserId = member.id)
|
||||
// LOG.info("pong (messageid: $messageId)")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
package eu.fosil
|
||||
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import net.folivo.matrix.bot.event.MatrixMessageHandler
|
||||
import net.folivo.matrix.bot.event.MessageContext
|
||||
import net.folivo.matrix.bot.user.MatrixUserService
|
||||
import net.folivo.matrix.bot.util.BotServiceHelper
|
||||
import net.folivo.matrix.core.model.events.m.room.message.MessageEvent
|
||||
import net.folivo.matrix.restclient.MatrixClient
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class PingHandler(
|
||||
private val matrixClient: MatrixClient,
|
||||
private val helper: BotServiceHelper,
|
||||
private val userService: MatrixUserService
|
||||
) : MatrixMessageHandler {
|
||||
companion object {
|
||||
private val LOG = LoggerFactory.getLogger(this::class.java)
|
||||
}
|
||||
|
||||
override suspend fun handleMessage(content: MessageEvent.MessageEventContent, context: MessageContext) {
|
||||
println("handle message content=${content.body}")
|
||||
userService.getUsersByRoom(context.roomId).collect { member ->
|
||||
println(member.id)
|
||||
println(member.isManaged)
|
||||
}
|
||||
if (content.body.contains("ping")) {
|
||||
userService.getUsersByRoom(context.roomId).filter { it.isManaged }
|
||||
.collect { member ->
|
||||
val messageId = context.answer("pong", asUserId = member.id)
|
||||
LOG.info("pong (messageid: $messageId)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: jdbc:h2:file:./okupamicoche;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
jackson:
|
||||
serialization:
|
||||
write-dates-as-timestamps: false
|
||||
#server:
|
||||
# port: 8080
|
||||
# port: 8081
|
||||
|
||||
#spring:
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
# url: jdbc:h2:file:./okupamicoche;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
|
||||
# jpa:
|
||||
# database-platform: org.hibernate.dialect.H2Dialect
|
||||
# hibernate:
|
||||
# ddl-auto: update
|
||||
# jackson:
|
||||
# serialization:
|
||||
# write-dates-as-timestamps: false
|
||||
|
||||
logging:
|
||||
level:
|
||||
@@ -31,7 +35,7 @@ matrix:
|
||||
# ENABLED allows automatic joins to every invited room.
|
||||
# DISABLED disables this feature.
|
||||
# Default is RESTRICTED, which means, that only automatic joins to serverName are allowed.
|
||||
autoJoin: DISABLED
|
||||
autoJoin: ENABLED
|
||||
# (optional) Configure if ALL membership changes should be tracked/saved with help of MatrixAppserviceRoomService
|
||||
# or only membership changes of users, which are MANAGED by the bridge. Default is ALL (no tracking/saving).
|
||||
trackMembership: ALL
|
||||
|
||||
Reference in New Issue
Block a user