|
@@ -27,6 +27,7 @@ import net.mamoe.mirai.console.internal.command.CommandManagerImpl
|
|
|
import net.mamoe.mirai.console.internal.command.CommandManagerImpl.allRegisteredCommands
|
|
import net.mamoe.mirai.console.internal.command.CommandManagerImpl.allRegisteredCommands
|
|
|
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.*
|
|
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.*
|
|
|
|
|
+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.permission.BuiltInPermissionService
|
|
import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService
|
|
|
import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl
|
|
import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl
|
|
@@ -182,15 +183,30 @@ public object BuiltInCommands {
|
|
|
@JvmOverloads
|
|
@JvmOverloads
|
|
|
public suspend fun CommandSender.handle(
|
|
public suspend fun CommandSender.handle(
|
|
|
@Name("qq") id: Long,
|
|
@Name("qq") id: Long,
|
|
|
- password: String,
|
|
|
|
|
|
|
+ password: String? = null,
|
|
|
protocol: BotConfiguration.MiraiProtocol? = null,
|
|
protocol: BotConfiguration.MiraiProtocol? = null,
|
|
|
) {
|
|
) {
|
|
|
|
|
+ fun BotConfiguration.setup(protocol: BotConfiguration.MiraiProtocol?): BotConfiguration {
|
|
|
|
|
+ if (protocol != null) this.protocol = protocol
|
|
|
|
|
+ return this
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ suspend fun getPassword(id: Long): Any? {
|
|
|
|
|
+ val acc = AutoLoginConfig.accounts.firstOrNull { it.account == id.toString() }
|
|
|
|
|
+ if (acc == null) {
|
|
|
|
|
+ sendMessage("Could not find '$id' in AutoLogin config. Please specify password.")
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ return if (acc.password.kind == MD5) acc.password.value.toByteArray() else acc.password.value
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ val pwd: Any = password ?: getPassword(id) ?: return
|
|
|
kotlin.runCatching {
|
|
kotlin.runCatching {
|
|
|
- MiraiConsole.addBot(id, password) {
|
|
|
|
|
- if (protocol != null) {
|
|
|
|
|
- this.protocol = protocol
|
|
|
|
|
- }
|
|
|
|
|
- }.doLogin()
|
|
|
|
|
|
|
+ when (pwd) {
|
|
|
|
|
+ is String -> MiraiConsole.addBot(id, pwd) { setup(protocol) }.doLogin()
|
|
|
|
|
+ is ByteArray -> MiraiConsole.addBot(id, pwd) { setup(protocol) }.doLogin()
|
|
|
|
|
+ else -> throw AssertionError("Assertion failed, please report to https://github.com/mamoe/mirai-console/issues/new/choose, debug=${pwd.javaClass}")// Unreachable
|
|
|
|
|
+ }
|
|
|
}.fold(
|
|
}.fold(
|
|
|
onSuccess = { scopeWith(ConsoleCommandSender).sendMessage("${it.nick} ($id) Login successful") },
|
|
onSuccess = { scopeWith(ConsoleCommandSender).sendMessage("${it.nick} ($id) Login successful") },
|
|
|
onFailure = { throwable ->
|
|
onFailure = { throwable ->
|