working ping example using matrix-spring-boot-bot:0.4.8
This commit is contained in:
@@ -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