Commit b57fe1bb authored by jiahua.liu's avatar jiahua.liu

ConfigSectionList

parent 125bfd32
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() {
}
\ No newline at end of file
...@@ -131,13 +131,6 @@ object DefaultCommands { ...@@ -131,13 +131,6 @@ object DefaultCommands {
} }
bot.login() bot.login()
bot.subscribeMessages { bot.subscribeMessages {
contains("test") {
if (this is GroupMessage) {
quoteReply("Hello $senderName")
} else {
reply("Hello!")
}
}
this.startsWith("/") { this.startsWith("/") {
if (bot.checkManager(this.sender.id)) { if (bot.checkManager(this.sender.id)) {
val sender = ContactCommandSender(this.subject) val sender = ContactCommandSender(this.subject)
...@@ -149,7 +142,6 @@ object DefaultCommands { ...@@ -149,7 +142,6 @@ object DefaultCommands {
} }
sendMessage("$qqNumber login successes") sendMessage("$qqNumber login successes")
MiraiConsole.frontEnd.pushBot(bot) MiraiConsole.frontEnd.pushBot(bot)
} catch (e: Exception) { } catch (e: Exception) {
sendMessage("$qqNumber login failed -> " + e.message) sendMessage("$qqNumber login failed -> " + e.message)
} }
......
...@@ -48,6 +48,7 @@ interface Config { ...@@ -48,6 +48,7 @@ interface Config {
fun getFloatList(key: String): List<Float> fun getFloatList(key: String): List<Float>
fun getDoubleList(key: String): List<Double> fun getDoubleList(key: String): List<Double>
fun getLongList(key: String): List<Long> fun getLongList(key: String): List<Long>
fun getConfigSectionList(key: String): List<ConfigSection>
operator fun set(key: String, value: Any) operator fun set(key: String, value: Any)
operator fun get(key: String): Any? operator fun get(key: String): Any?
operator fun contains(key: String): Boolean operator fun contains(key: String): Boolean
...@@ -271,6 +272,16 @@ interface ConfigSection : Config, MutableMap<String, Any> { ...@@ -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() } 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 { override fun exist(key: String): Boolean {
return get(key) != null return get(key) != null
} }
......
package mirai.test
import java.io.File
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment