Fix auto login configuration

This commit is contained in:
Karlatemp 2020-11-18 18:25:12 +08:00
parent bf83b206e2
commit 471a919248
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 16 additions and 13 deletions

View File

@ -143,7 +143,7 @@ public interface MiraiConsole : CoroutineScope {
return when (password) {
is ByteArray -> Bot(id, password, config)
is String -> Bot(id, password, config)
else -> null!!
else -> throw IllegalArgumentException("Bad password type: `${password.javaClass.name}`. Require ByteArray or String")
}
}

View File

@ -30,7 +30,6 @@ import net.mamoe.mirai.console.extensions.PostStartupExtension
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
import net.mamoe.mirai.console.internal.command.CommandConfig
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.ConfigurationKey.protocol
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.MD5
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.PLAIN
import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope
@ -230,20 +229,24 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
error("Bad auto-login account: '${account.account}'")
}
if (id == 123456L) continue
val config = BotConfiguration()
for ((key, value) in account.configuration) {
runCatching {
when (key) {
protocol -> config.protocol = BotConfiguration.MiraiProtocol.valueOf(value.toString())
fun BotConfiguration.configBot() {
mainLogger.info { "Auto-login ${account.account}" }
account.configuration[AutoLoginConfig.Account.ConfigurationKey.protocol]
?.let { protocol ->
this.protocol = runCatching {
BotConfiguration.MiraiProtocol.valueOf(protocol.toString())
}.getOrElse {
throw IllegalArgumentException(
"Bad auto-login config value for `protocol` for account $id",
it
)
}
}.onFailure {
error("Bad auto-login config value for $key for account $id")
}
}
when (account.password.kind) {
PLAIN -> {
mainLogger.info { "Auto-login ${account.account}" }
MiraiConsole.addBot(id, account.password.value).alsoLogin()
MiraiConsole.addBot(id, account.password.value, BotConfiguration::configBot).alsoLogin()
}
MD5 -> {
val md5 = kotlin.runCatching {
@ -251,7 +254,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
}.getOrElse {
error("Bad auto-login md5: '${account.password.value}' for account $id")
}
MiraiConsole.addBot(id, md5).alsoLogin()
MiraiConsole.addBot(id, md5, BotConfiguration::configBot).alsoLogin()
}
}
}