Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
781dd721
Commit
781dd721
authored
Apr 25, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `LoginSolver` choosing, add `NoStandardInputForCaptchaException`
parent
79dd1354
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
14 deletions
+23
-14
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/LoginFailedException.kt
...in/kotlin/net.mamoe.mirai/network/LoginFailedException.kt
+6
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt
...c/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt
+15
-13
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt
...ain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt
+1
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/WindowHelperJvm.kt
...c/jvmMain/kotlin/net/mamoe/mirai/utils/WindowHelperJvm.kt
+1
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/LoginFailedException.kt
View file @
781dd721
...
...
@@ -36,6 +36,12 @@ class WrongPasswordException(message: String?) : LoginFailedException(true, mess
*/
class
NoServerAvailableException
(
override
val
cause
:
Throwable
?)
:
LoginFailedException
(
false
,
"no server available"
)
/**
* 无标准输入或 Kotlin 不支持此输入.
*/
class
NoStandardInputForCaptchaException
(
override
val
cause
:
Throwable
?)
:
LoginFailedException
(
true
,
"no standard input for captcha"
)
/**
* 需要短信验证时抛出. mirai 目前还不支持短信验证.
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.jvm.kt
View file @
781dd721
...
...
@@ -22,7 +22,7 @@ import kotlinx.coroutines.sync.withLock
import
kotlinx.coroutines.withContext
import
kotlinx.io.core.use
import
net.mamoe.mirai.Bot
import
java.awt.Desktop
import
net.mamoe.mirai.network.NoStandardInputForCaptchaException
import
java.awt.Image
import
java.awt.image.BufferedImage
import
java.io.File
...
...
@@ -32,6 +32,9 @@ import kotlin.coroutines.CoroutineContext
actual
typealias
Throws
=
kotlin
.
jvm
.
Throws
/**
* 自动选择 [SwingSolver] 或 [StandardCharImageLoginSolver]
*/
@MiraiExperimentalAPI
class
DefaultLoginSolver
(
val
input
:
suspend
()
->
String
,
...
...
@@ -40,10 +43,10 @@ class DefaultLoginSolver(
private
val
delegate
:
LoginSolver
init
{
if
(
WindowHelperJvm
.
isDesktopSupport
)
{
if
(
WindowHelperJvm
.
isDesktopSupport
ed
)
{
delegate
=
SwingSolver
}
else
{
delegate
=
DefaultLoginSolverImpl
(
input
,
overrideLogger
)
delegate
=
StandardCharImageLoginSolver
(
input
,
overrideLogger
)
}
}
...
...
@@ -60,9 +63,15 @@ class DefaultLoginSolver(
}
}
/**
* 使用字符图片展示验证码, 使用 [input] 获取输入, 使用 [overrideLogger] 输出
*/
@MiraiExperimentalAPI
class
DefaultLoginSolverImpl
(
class
StandardCharImageLoginSolver
(
input
:
suspend
()
->
String
,
/**
* 为 `null` 时使用 [Bot.logger]
*/
private
val
overrideLogger
:
MiraiLogger
?
=
null
)
:
LoginSolver
()
{
private
val
input
:
suspend
()
->
String
=
suspend
{
...
...
@@ -135,16 +144,9 @@ actual abstract class LoginSolver {
actual
abstract
suspend
fun
onSolveUnsafeDeviceLoginVerify
(
bot
:
Bot
,
url
:
String
):
String
?
actual
companion
object
{
actual
val
Default
:
LoginSolver
actual
val
Default
:
LoginSolver
=
@OptIn
(
MiraiExperimentalAPI
::
class
)
get
()
{
if
(
Desktop
.
isDesktopSupported
())
{
return
SwingSolver
}
return
DefaultLoginSolverImpl
(
input
=
{
withContext
(
Dispatchers
.
IO
)
{
readLine
()
}
?:
error
(
"No standard input"
)
})
}
DefaultLoginSolver
({
readLine
()
?:
throw
NoStandardInputForCaptchaException
(
null
)
})
}
}
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/LoginSolver.swing.jvm.kt
View file @
781dd721
...
...
@@ -20,6 +20,7 @@ import javax.swing.JTextField
/**
* @author Karlatemp <karlatemp@vip.qq.com> <https://github.com/Karlatemp>
*/
@SinceMirai
(
"0.39.2"
)
@MiraiExperimentalAPI
object
SwingSolver
:
LoginSolver
()
{
override
suspend
fun
onSolvePicCaptcha
(
bot
:
Bot
,
data
:
ByteArray
):
String
?
{
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/WindowHelperJvm.kt
View file @
781dd721
...
...
@@ -25,7 +25,7 @@ import javax.swing.JTextField
// 隔离类代码
internal
object
WindowHelperJvm
{
internal
val
isDesktopSupport
:
Boolean
=
internal
val
isDesktopSupport
ed
:
Boolean
=
kotlin
.
runCatching
{
Desktop
.
isDesktopSupported
()
}.
getOrElse
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment