mirai-console-j24-plugin/src/main/kotlin/PluginMain.kt

53 lines
1.9 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package top.jie65535.j24
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.event.GlobalEventChannel
import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.utils.info
object PluginMain : KotlinPlugin(
JvmPluginDescription(
id = "top.jie65535.j24",
name = "J 24点游戏",
version = "0.1.0"
) {
author("jie65535")
info("24点游戏")
}
) {
private val games: MutableMap<Long, Point24> = mutableMapOf()
override fun onEnable() {
logger.info { "Plugin loaded" }
//配置文件目录 "${dataFolder.absolutePath}/"
val eventChannel = GlobalEventChannel.parentScope(this)
eventChannel.subscribeMessages {
contains("24点") quoteReply {
val game = Point24()
games[this.sender.id] = game
"你抽到了 [${game.points[0]}] [${game.points[1]}] [${game.points[2]}] [${game.points[3]}]\n" +
"请用以上四组数字组合成结果为24的算式以“答”开头验证"
}
startsWith("") quoteReply {
val game = games[sender.id]
if (game == null) {
"你还没有抽数字哦说“24点”来开始游戏吧"
} else {
try {
val result = game.evaluate(message.contentToString().removePrefix("").trim())
if (result == 24.0) {
games.remove(sender.id)
"恭喜你,答对了!"
} else {
"答错了,计算结果为 $result"
}
} catch (e: Throwable) {
"错误:${e.message}"
}
}
}
}
}
}