Skip to content

Commit c229b4e

Browse files
committed
config
1 parent d4e3fb1 commit c229b4e

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

src/main/kotlin/net/lz1998/mirai/SpringMiraiClientApplication.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package net.lz1998.mirai
22

3+
import net.lz1998.mirai.properties.ClientProperties
34
import org.springframework.boot.autoconfigure.SpringBootApplication
5+
import org.springframework.boot.context.properties.EnableConfigurationProperties
46
import org.springframework.boot.runApplication
57
import org.springframework.context.annotation.Bean
68
import org.springframework.context.annotation.Configuration
79
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter
810

911
@SpringBootApplication
12+
@EnableConfigurationProperties(ClientProperties::class)
1013
class SpringMiraiClientApplication
1114

1215
fun main(args: Array<String>) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.lz1998.mirai.properties
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties
4+
5+
6+
@ConfigurationProperties("bot.client")
7+
class ClientProperties {
8+
var wsUrl = "ws://127.0.0.1/ws/cq/"
9+
}

src/main/kotlin/net/lz1998/mirai/service/BotService.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ package net.lz1998.mirai.service
33
import dto.HttpDto
44
import net.lz1998.mirai.entity.RemoteBot
55
import net.lz1998.mirai.entity.WebsocketBotClient
6+
import net.lz1998.mirai.properties.ClientProperties
7+
import org.springframework.beans.factory.annotation.Autowired
68
import org.springframework.stereotype.Service
79

810
@Service
911
class BotService {
1012
val botMap = mutableMapOf<Long, RemoteBot>()
1113

14+
@Autowired
15+
lateinit var clientProperties: ClientProperties
16+
1217
@Synchronized
1318
suspend fun createBot(botId: Long, password: String) {
1419
var bot = botMap[botId]
1520
if (bot == null) {
16-
bot = WebsocketBotClient(botId, password, "ws://127.0.0.1:8081/ws/cq/")
21+
bot = WebsocketBotClient(botId, password, wsUrl = clientProperties.wsUrl)
1722
botMap[botId] = bot
1823
bot.initBot()
1924
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
server.port=9000
2+
bot.client.wsUrl="ws://localhost:8081/ws/test/"

0 commit comments

Comments
 (0)