ConfigSectionList

This commit is contained in:
jiahua.liu 2020-02-23 15:52:41 +08:00
parent 125bfd3245
commit b57fe1bb49
4 changed files with 30 additions and 8 deletions

View File

@ -0,0 +1,16 @@
package net.mamoe.mirai.console
import net.mamoe.mirai.console.plugins.Config
import net.mamoe.mirai.console.plugins.loadAsConfig
import net.mamoe.mirai.console.plugins.withDefaultWriteSave
import java.io.File
object Data {
val section = (File(System.getProperty("user.dir") + "/setu.yml")).loadAsConfig()
val R18 = section.getList
}
fun main() {
}

View File

@ -131,13 +131,6 @@ object DefaultCommands {
}
bot.login()
bot.subscribeMessages {
contains("test") {
if (this is GroupMessage) {
quoteReply("Hello $senderName")
} else {
reply("Hello!")
}
}
this.startsWith("/") {
if (bot.checkManager(this.sender.id)) {
val sender = ContactCommandSender(this.subject)
@ -149,7 +142,6 @@ object DefaultCommands {
}
sendMessage("$qqNumber login successes")
MiraiConsole.frontEnd.pushBot(bot)
} catch (e: Exception) {
sendMessage("$qqNumber login failed -> " + e.message)
}

View File

@ -48,6 +48,7 @@ interface Config {
fun getFloatList(key: String): List<Float>
fun getDoubleList(key: String): List<Double>
fun getLongList(key: String): List<Long>
fun getConfigSectionList(key: String): List<ConfigSection>
operator fun set(key: String, value: Any)
operator fun get(key: String): Any?
operator fun contains(key: String): Boolean
@ -271,6 +272,16 @@ interface ConfigSection : Config, MutableMap<String, Any> {
return ((get(key) ?: error("ConfigSection does not contain $key ")) as List<*>).map { it.toString().toLong() }
}
override fun getConfigSectionList(key: String): List<ConfigSection> {
return ((get(key) ?: error("ConfigSection does not contain $key ")) as List<*>).map {
if (it is ConfigSection) {
it
} else {
ConfigSectionDelegation(it as MutableMap<String, Any>)
}
}
}
override fun exist(key: String): Boolean {
return get(key) != null
}

View File

@ -0,0 +1,3 @@
package mirai.test
import java.io.File