Skip to content

Commit 69cfdfc

Browse files
committed
controller
1 parent bd4b528 commit 69cfdfc

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/main/kotlin/net/lz1998/mirai/controller/BotController.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dto.HttpDto
44
import kotlinx.coroutines.GlobalScope
55
import kotlinx.coroutines.launch
66
import net.lz1998.mirai.service.BotService
7+
import net.lz1998.mirai.service.MyLoginSolver
78
import org.springframework.beans.factory.annotation.Autowired
89
import org.springframework.web.bind.annotation.*
910

@@ -14,6 +15,9 @@ class BotController {
1415
@Autowired
1516
lateinit var botService: BotService
1617

18+
@Autowired
19+
lateinit var myLoginSolver: MyLoginSolver
20+
1721

1822
// 创建一个机器人并登陆
1923
@RequestMapping("/create/v1", produces = ["application/x-protobuf"], consumes = ["application/x-protobuf"])
@@ -23,7 +27,7 @@ class BotController {
2327
}
2428

2529
@RequestMapping("/list/v1", produces = ["application/x-protobuf"], consumes = ["application/x-protobuf"])
26-
fun listBot(@RequestBody param: HttpDto.ListBotReq): HttpDto.ListBotResp {
30+
fun listBot(): HttpDto.ListBotResp {
2731
val botList = botService.listBot()
2832
return HttpDto.ListBotResp.newBuilder().addAllBotList(botList).build()
2933
}

src/main/kotlin/net/lz1998/mirai/controller/CaptchaController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CaptchaController {
1515
lateinit var myLoginSolver: MyLoginSolver
1616

1717
@RequestMapping("/list/v1", produces = ["application/x-protobuf"], consumes = ["application/x-protobuf"])
18-
fun getCaptchaList(@RequestBody param: HttpDto.GetCaptchaListReq): HttpDto.GetCaptchaListResp {
18+
fun getCaptchaList(): HttpDto.GetCaptchaListResp {
1919
val captchaList = myLoginSolver.getCaptchaList()
2020
return HttpDto.GetCaptchaListResp.newBuilder().addAllCaptchaList(captchaList).build()
2121
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ class BotService {
2121

2222
fun listBot(): Collection<HttpDto.Bot> {
2323
return botMap.values.map { remoteBot ->
24-
HttpDto.Bot.newBuilder().setBotId(remoteBot.botId).setIsOnline(remoteBot.bot.isOnline).build()
24+
HttpDto.Bot.newBuilder().setBotId(remoteBot.botId).setIsOnline(
25+
try {
26+
remoteBot.bot.isOnline
27+
} catch (e: Exception) {
28+
false
29+
}
30+
).build()
2531
}
2632
}
2733

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,32 @@ class MyLoginSolver : LoginSolver() {
1616
// 图片验证码登陆
1717
override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
1818
val def = CompletableDeferred<String>()
19-
loginMap[bot.id] = LoginData(bot.id, LoginDataType.PIC_CAPTCHA, def, data, null)
19+
val loginData = LoginData(bot.id, LoginDataType.PIC_CAPTCHA, def, data, null)
20+
loginMap[bot.id] = loginData
2021
return def.await().trim()
2122
}
2223

2324
// 滑动验证
2425
override suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String? {
2526
val def = CompletableDeferred<String>()
26-
loginMap[bot.id] = LoginData(bot.id, LoginDataType.SLIDER_CAPTCHA, def, null, url)
27+
val loginData = LoginData(bot.id, LoginDataType.SLIDER_CAPTCHA, def, null, url)
28+
loginMap[bot.id] = loginData
2729
return def.await().trim()
2830
}
2931

3032
// 设备锁扫码验证
3133
override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? {
3234
val def = CompletableDeferred<String>()
33-
loginMap[bot.id] = LoginData(bot.id, LoginDataType.UNSAFE_DEVICE_LOGIN_VERIFY, def, null, url)
35+
val loginData = LoginData(bot.id, LoginDataType.UNSAFE_DEVICE_LOGIN_VERIFY, def, null, url)
36+
loginMap[bot.id] = loginData
3437
return def.await().trim()
3538
}
3639

3740
fun solveLogin(botId: Long, result: String) {
3841
val loginData = loginMap[botId] ?: return
39-
loginMap.remove(botId)
4042
loginData.def.complete(result)
4143
}
4244

43-
fun getLoginData(botId: Long): LoginData? {
44-
return loginMap[botId]
45-
}
46-
4745
fun getCaptchaList(): Collection<HttpDto.Captcha> {
4846
return loginMap.values.map { loginData ->
4947
val captcha = HttpDto.Captcha.newBuilder()
@@ -78,7 +76,7 @@ data class LoginData(
7876
enum class LoginDataType(val type: String) {
7977
PIC_CAPTCHA("pic_captcha"),
8078
SLIDER_CAPTCHA("slider_captcha"),
81-
UNSAFE_DEVICE_LOGIN_VERIFY("unsafe_device_login)verify"),
79+
UNSAFE_DEVICE_LOGIN_VERIFY("unsafe_device_login_verify"),
8280
}
8381

8482
val myLoginSolver = MyLoginSolver()

0 commit comments

Comments
 (0)