mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-11 04:40:10 +08:00
Opt in config APIs
This commit is contained in:
parent
f10a1c64de
commit
ea3f51dca9
@ -79,6 +79,7 @@ abstract class PluginBase
|
||||
* 加载一个 [dataFolder] 中的 [Config]
|
||||
*/
|
||||
fun loadConfig(fileName: String): Config {
|
||||
@OptIn(ToBeRemoved::class)
|
||||
return Config.load(dataFolder.absolutePath + "/" + fileName)
|
||||
}
|
||||
|
||||
@ -112,6 +113,7 @@ abstract class PluginBase
|
||||
*/
|
||||
fun getResourcesConfig(fileName: String): Config {
|
||||
require(fileName.contains(".")) { "Unknown Config Type" }
|
||||
@OptIn(ToBeRemoved::class)
|
||||
return Config.load(getResources(fileName) ?: error("No such file: $fileName"), fileName.substringAfter('.'))
|
||||
}
|
||||
|
||||
@ -188,6 +190,7 @@ class PluginDescription(
|
||||
}
|
||||
|
||||
companion object {
|
||||
@OptIn(ToBeRemoved::class)
|
||||
fun readFromContent(content_: String, file: File): PluginDescription {
|
||||
with(Config.load(content_, "yml")) {
|
||||
try {
|
||||
|
@ -11,13 +11,11 @@ package net.mamoe.mirai.console.utils
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.plugins.ConfigSection
|
||||
import net.mamoe.mirai.console.plugins.ConfigSectionImpl
|
||||
import net.mamoe.mirai.console.plugins.loadAsConfig
|
||||
import net.mamoe.mirai.console.plugins.withDefaultWriteSave
|
||||
import net.mamoe.mirai.console.plugins.*
|
||||
import net.mamoe.mirai.console.utils.BotManagers.BOT_MANAGERS
|
||||
import java.io.File
|
||||
|
||||
@OptIn(ToBeRemoved::class)
|
||||
internal object BotManagers {
|
||||
val config = File("${MiraiConsole.path}/bot.yml").loadAsConfig()
|
||||
val BOT_MANAGERS: ConfigSection by config.withDefaultWriteSave { ConfigSectionImpl() }
|
||||
@ -30,6 +28,7 @@ fun Bot.addManagerDeprecated(long: Long) {
|
||||
addManager(long)
|
||||
}
|
||||
|
||||
@OptIn(ToBeRemoved::class)
|
||||
fun Bot.addManager(long: Long): Boolean {
|
||||
BOT_MANAGERS.putIfAbsent(this.id.toString(), mutableListOf<Long>())
|
||||
BOT_MANAGERS[this.id.toString()] =
|
||||
@ -41,6 +40,7 @@ fun Bot.addManager(long: Long): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
@OptIn(ToBeRemoved::class)
|
||||
fun Bot.removeManager(long: Long) {
|
||||
BOT_MANAGERS.putIfAbsent(this.id.toString(), mutableListOf<Long>())
|
||||
BOT_MANAGERS[this.id.toString()] =
|
||||
@ -49,6 +49,7 @@ fun Bot.removeManager(long: Long) {
|
||||
}
|
||||
|
||||
val Bot.managers: List<Long>
|
||||
@OptIn(ToBeRemoved::class)
|
||||
get() {
|
||||
BOT_MANAGERS.putIfAbsent(this.id.toString(), mutableListOf<Long>())
|
||||
return BOT_MANAGERS.getLongList(this.id.toString())
|
||||
|
Loading…
Reference in New Issue
Block a user