Skip to content

Commit a372954

Browse files
committed
loginSolver
1 parent 89eea7b commit a372954

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BotController {
3030
@RequestMapping("/getLoginUrl")
3131
fun getLoginUrl(botId: Long): String? {
3232
val loginData = myLoginSolver.getLoginData(botId) ?: return null
33-
return if (loginData.type == LoginDataType.PIC_CAPTCHA) {
33+
return if (loginData.type != LoginDataType.PIC_CAPTCHA) {
3434
loginData.url
3535
} else {
3636
null

src/main/kotlin/net/lz1998/mirai/entity/RemoteBot.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface RemoteBot {
1717
suspend fun initBot() {
1818
bot = Bot(botId, password) {
1919
fileBasedDeviceInfo("device.json")
20-
// loginSolver = myLoginSolver
20+
loginSolver = myLoginSolver
2121
noNetworkLog()
2222
}.alsoLogin()
2323
bot.subscribeAlways<BotEvent> {

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,31 @@ class MyLoginSolver : LoginSolver() {
1010
// TODO 通过轮询查询 loginMap
1111
val loginMap = mutableMapOf<Long, LoginData>()
1212

13+
// 图片验证码登陆
1314
override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
1415
val def = CompletableDeferred<String>()
1516
loginMap[bot.id] = LoginData(LoginDataType.PIC_CAPTCHA, def, data, null)
1617
return def.await().trim()
1718
}
1819

20+
// 滑动验证
1921
override suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String? {
2022
val def = CompletableDeferred<String>()
2123
loginMap[bot.id] = LoginData(LoginDataType.SLIDER_CAPTCHA, def, null, url)
2224
return def.await().trim()
2325
}
2426

27+
// 设备锁扫码验证
2528
override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? {
2629
val def = CompletableDeferred<String>()
2730
loginMap[bot.id] = LoginData(LoginDataType.UNSAFE_DEVICE_LOGIN_VERIFY, def, null, url)
2831
return def.await().trim()
2932
}
3033

3134
fun solveLogin(botId: Long, result: String) {
32-
loginMap[botId]?.def?.complete(result)
35+
val loginData = loginMap[botId] ?: return
36+
loginMap.remove(botId)
37+
loginData.def.complete(result)
3338
}
3439

3540
fun getLoginData(botId: Long): LoginData? {

src/main/kotlin/net/lz1998/mirai/utils/MsgConverter.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suspend fun OnebotBase.Message.toMiraiMessage(bot: Bot, contact: Contact): Messa
2020
"image" -> {
2121
return try {
2222
withContext(Dispatchers.IO) {
23-
URL(dataMap["file"]?:"").openConnection().getInputStream().uploadAsImage(contact)
23+
URL(dataMap["file"] ?: "").openConnection().getInputStream().uploadAsImage(contact)
2424
}
2525
} catch (e: Exception) {
2626
MSG_EMPTY
@@ -45,9 +45,12 @@ fun MessageChain.toOnebotMessage(): List<OnebotBase.Message> {
4545
val message = when (content) {
4646
is At -> OnebotBase.Message.newBuilder().setType("at").putAllData(mapOf("qq" to content.target.toString())).build()
4747
is PlainText -> OnebotBase.Message.newBuilder().setType("text").putAllData(mapOf("text" to content.content)).build()
48+
is Face -> OnebotBase.Message.newBuilder().setType("face").putAllData(mapOf("id" to content.id.toString())).build()
49+
is Image -> OnebotBase.Message.newBuilder().setType("image").putAllData(mapOf("file" to content.imageId)).build()
50+
is Voice -> OnebotBase.Message.newBuilder().setType("record").putAllData(mapOf("file" to content.fileName)).build()
4851
else -> OnebotBase.Message.newBuilder().setType("unknown").build()
4952
}
5053
messageChain.add(message)
5154
}
5255
return messageChain
53-
}
56+
}

0 commit comments

Comments
 (0)