|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2019-2022 Mamoe Technologies and contributors.
|
|
|
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
|
|
|
*
|
|
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
|
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
|
@@ -7,6 +7,8 @@
|
|
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
|
|
*/
|
|
|
|
|
|
+@file:OptIn(ConsoleFrontEndImplementation::class)
|
|
|
+
|
|
|
package net.mamoe.mirai.console.command
|
|
|
|
|
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
@@ -15,6 +17,7 @@ import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.sync.Mutex
|
|
|
import kotlinx.coroutines.sync.withLock
|
|
|
import net.mamoe.mirai.Bot
|
|
|
+import net.mamoe.mirai.console.ConsoleFrontEndImplementation
|
|
|
import net.mamoe.mirai.console.MiraiConsole
|
|
|
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
|
|
import net.mamoe.mirai.console.MiraiConsoleImplementation.ConsoleDataScope.Companion.get
|
|
@@ -51,6 +54,7 @@ import net.mamoe.mirai.console.plugin.version
|
|
|
import net.mamoe.mirai.console.util.*
|
|
|
import net.mamoe.mirai.event.events.EventCancelledException
|
|
|
import net.mamoe.mirai.utils.BotConfiguration
|
|
|
+import net.mamoe.mirai.utils.MiraiExperimentalApi
|
|
|
import java.lang.management.ManagementFactory
|
|
|
import java.lang.management.MemoryMXBean
|
|
|
import java.lang.management.MemoryUsage
|
|
@@ -64,6 +68,7 @@ import kotlin.system.exitProcess
|
|
|
public interface BuiltInCommand : Command
|
|
|
|
|
|
// for identification
|
|
|
+@OptIn(ConsoleExperimentalApi::class)
|
|
|
internal interface BuiltInCommandInternal : Command, BuiltInCommand
|
|
|
|
|
|
/**
|
|
@@ -126,7 +131,10 @@ public object BuiltInCommands {
|
|
|
|
|
|
private val closingLock = Mutex()
|
|
|
|
|
|
- @OptIn(DelicateCoroutinesApi::class)
|
|
|
+ @OptIn(
|
|
|
+ DelicateCoroutinesApi::class, ConsoleFrontEndImplementation::class, ConsoleExperimentalApi::class,
|
|
|
+ ConsoleInternalApi::class
|
|
|
+ )
|
|
|
@Handler
|
|
|
public suspend fun CommandSender.handle() {
|
|
|
GlobalScope.launch {
|
|
@@ -162,6 +170,7 @@ public object BuiltInCommands {
|
|
|
description = "登出一个账号",
|
|
|
), BuiltInCommandInternal {
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Handler
|
|
|
public suspend fun CommandSender.handle(
|
|
|
@Name("qq") id: Long
|
|
@@ -181,6 +190,7 @@ public object BuiltInCommands {
|
|
|
description = loginCommandInstance.description,
|
|
|
), BuiltInCommandInternal {
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Handler
|
|
|
@JvmOverloads
|
|
|
public suspend fun CommandSender.handle(
|
|
@@ -237,6 +247,7 @@ public object BuiltInCommands {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Description("授权一个权限")
|
|
|
@SubCommand("permit", "grant", "add")
|
|
|
public suspend fun CommandSender.permit(
|
|
@@ -247,6 +258,7 @@ public object BuiltInCommands {
|
|
|
sendMessage("OK")
|
|
|
}
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Description("撤销一个权限")
|
|
|
@SubCommand("cancel", "deny", "remove")
|
|
|
public suspend fun CommandSender.cancel(
|
|
@@ -257,6 +269,7 @@ public object BuiltInCommands {
|
|
|
sendMessage("OK")
|
|
|
}
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Description("撤销一个权限及其所有子权限")
|
|
|
@SubCommand("cancelAll", "denyAll", "removeAll")
|
|
|
public suspend fun CommandSender.cancelAll(
|
|
@@ -267,6 +280,7 @@ public object BuiltInCommands {
|
|
|
sendMessage("OK")
|
|
|
}
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Description("查看被授权权限列表")
|
|
|
@SubCommand("permittedPermissions", "pp", "grantedPermissions", "gp")
|
|
|
public suspend fun CommandSender.permittedPermissions(
|
|
@@ -423,11 +437,13 @@ public object BuiltInCommands {
|
|
|
ConsoleCommandOwner, "autoLogin", "自动登录",
|
|
|
description = "自动登录设置",
|
|
|
overrideContext = buildCommandArgumentContext {
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
ConfigurationKey::class with ConfigurationKey.Parser
|
|
|
}
|
|
|
), BuiltInCommandInternal {
|
|
|
@Description("查看自动登录账号列表")
|
|
|
@SubCommand
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
public suspend fun CommandSender.list() {
|
|
|
val config = DataScope.get<AutoLoginConfig>()
|
|
|
sendMessage(buildString {
|
|
@@ -454,6 +470,7 @@ public object BuiltInCommands {
|
|
|
|
|
|
@Description("添加自动登录, passwordKind 可选 PLAIN 或 MD5")
|
|
|
@SubCommand
|
|
|
+ @ConsoleExperimentalApi
|
|
|
public suspend fun CommandSender.add(account: Long, password: String, passwordKind: PasswordKind = PLAIN) {
|
|
|
val config = DataScope.get<AutoLoginConfig>()
|
|
|
val accountStr = account.toString()
|
|
@@ -465,6 +482,7 @@ public object BuiltInCommands {
|
|
|
sendMessage("已成功添加 '$account'.")
|
|
|
}
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Description("清除所有配置")
|
|
|
@SubCommand
|
|
|
public suspend fun CommandSender.clear() {
|
|
@@ -473,6 +491,7 @@ public object BuiltInCommands {
|
|
|
sendMessage("已清除所有自动登录配置.")
|
|
|
}
|
|
|
|
|
|
+ @OptIn(ConsoleExperimentalApi::class)
|
|
|
@Description("删除一个账号")
|
|
|
@SubCommand
|
|
|
public suspend fun CommandSender.remove(account: Long) {
|
|
@@ -485,6 +504,7 @@ public object BuiltInCommands {
|
|
|
sendMessage("账号 '$account' 未配置自动登录.")
|
|
|
}
|
|
|
|
|
|
+ @ConsoleExperimentalApi
|
|
|
@Description("设置一个账号的一个配置项")
|
|
|
@SubCommand
|
|
|
public suspend fun CommandSender.setConfig(account: Long, configKey: ConfigurationKey, value: String) {
|
|
@@ -509,6 +529,7 @@ public object BuiltInCommands {
|
|
|
}
|
|
|
|
|
|
@Description("删除一个账号的一个配置项")
|
|
|
+ @ConsoleExperimentalApi
|
|
|
@SubCommand
|
|
|
public suspend fun CommandSender.removeConfig(account: Long, configKey: ConfigurationKey) {
|
|
|
val config = DataScope.get<AutoLoginConfig>()
|
|
@@ -583,6 +604,7 @@ public object BuiltInCommands {
|
|
|
val max: Long,
|
|
|
)
|
|
|
|
|
|
+ @OptIn(MiraiExperimentalApi::class)
|
|
|
@Handler
|
|
|
public suspend fun CommandSender.handle() {
|
|
|
sendAnsiMessage {
|
|
@@ -668,9 +690,11 @@ public object BuiltInCommands {
|
|
|
v < e50 -> {
|
|
|
green()
|
|
|
}
|
|
|
+
|
|
|
v < e90 -> {
|
|
|
lightRed()
|
|
|
}
|
|
|
+
|
|
|
else -> {
|
|
|
red()
|
|
|
}
|