mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Fix auto login configuration
This commit is contained in:
parent
bf83b206e2
commit
471a919248
@ -143,7 +143,7 @@ public interface MiraiConsole : CoroutineScope {
|
|||||||
return when (password) {
|
return when (password) {
|
||||||
is ByteArray -> Bot(id, password, config)
|
is ByteArray -> Bot(id, password, config)
|
||||||
is String -> 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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import net.mamoe.mirai.console.extensions.PostStartupExtension
|
|||||||
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
|
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
|
||||||
import net.mamoe.mirai.console.internal.command.CommandConfig
|
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
|
||||||
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.MD5
|
||||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.PLAIN
|
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.PLAIN
|
||||||
import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope
|
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}'")
|
error("Bad auto-login account: '${account.account}'")
|
||||||
}
|
}
|
||||||
if (id == 123456L) continue
|
if (id == 123456L) continue
|
||||||
val config = BotConfiguration()
|
fun BotConfiguration.configBot() {
|
||||||
for ((key, value) in account.configuration) {
|
mainLogger.info { "Auto-login ${account.account}" }
|
||||||
runCatching {
|
|
||||||
when (key) {
|
account.configuration[AutoLoginConfig.Account.ConfigurationKey.protocol]
|
||||||
protocol -> config.protocol = BotConfiguration.MiraiProtocol.valueOf(value.toString())
|
?.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) {
|
when (account.password.kind) {
|
||||||
PLAIN -> {
|
PLAIN -> {
|
||||||
mainLogger.info { "Auto-login ${account.account}" }
|
MiraiConsole.addBot(id, account.password.value, BotConfiguration::configBot).alsoLogin()
|
||||||
MiraiConsole.addBot(id, account.password.value).alsoLogin()
|
|
||||||
}
|
}
|
||||||
MD5 -> {
|
MD5 -> {
|
||||||
val md5 = kotlin.runCatching {
|
val md5 = kotlin.runCatching {
|
||||||
@ -251,7 +254,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
|||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
error("Bad auto-login md5: '${account.password.value}' for account $id")
|
error("Bad auto-login md5: '${account.password.value}' for account $id")
|
||||||
}
|
}
|
||||||
MiraiConsole.addBot(id, md5).alsoLogin()
|
MiraiConsole.addBot(id, md5, BotConfiguration::configBot).alsoLogin()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user