Update version to v0.1.1

Add xor operator '^'
Add group switch
This commit is contained in:
2022-07-08 12:27:28 +08:00
parent 338e3badd3
commit c3354b2207
5 changed files with 58 additions and 9 deletions

View File

@ -1,13 +1,13 @@
plugins {
val kotlinVersion = "1.6.10"
val kotlinVersion = "1.7.0"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
id("net.mamoe.mirai-console") version "2.11.1"
id("net.mamoe.mirai-console") version "2.12.0"
}
group = "top.jie65535"
version = "0.1.0"
version = "0.1.1"
repositories {
maven("https://maven.aliyun.com/repository/public") // 阿里云国内代理仓库

View File

@ -0,0 +1,30 @@
package top.jie65535.j24
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.CompositeCommand
import net.mamoe.mirai.console.command.getGroupOrNull
import net.mamoe.mirai.contact.Group
object PluginCommand : CompositeCommand(
PluginMain, "j24"
) {
@SubCommand
suspend fun CommandSender.enable(group: Group? = getGroupOrNull()) {
if (group == null) {
sendMessage("必须指定群")
return
}
PluginConfig.enabledGroups.add(group.id)
sendMessage("OK")
}
@SubCommand
suspend fun CommandSender.disable(group: Group? = getGroupOrNull()) {
if (group == null) {
sendMessage("必须指定群")
return
}
PluginConfig.enabledGroups.remove(group.id)
sendMessage("OK")
}
}

View File

@ -0,0 +1,8 @@
package top.jie65535.j24
import net.mamoe.mirai.console.data.AutoSavePluginConfig
import net.mamoe.mirai.console.data.value
object PluginConfig : AutoSavePluginConfig("config") {
val enabledGroups: MutableSet<Long> by value()
}

View File

@ -1,16 +1,17 @@
package top.jie65535.j24
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
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.event.subscribeGroupMessages
import net.mamoe.mirai.utils.info
object PluginMain : KotlinPlugin(
JvmPluginDescription(
id = "top.jie65535.j24",
name = "J 24点游戏",
version = "0.1.0"
version = "0.1.1"
) {
author("jie65535")
info("24点游戏")
@ -20,15 +21,19 @@ object PluginMain : KotlinPlugin(
override fun onEnable() {
logger.info { "Plugin loaded" }
PluginCommand.register()
PluginConfig.reload()
val eventChannel = GlobalEventChannel.parentScope(this)
eventChannel.subscribeMessages {
startsWith("24点") quoteReply {
eventChannel.subscribeGroupMessages {
startsWith("24点") and content { PluginConfig.enabledGroups.contains(this.group.id) } 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 {
startsWith("") and content { PluginConfig.enabledGroups.contains(this.group.id) } quoteReply {
val game = games[sender.id]
if (game == null) {
"你还没有抽数字哦说“24点”来开始游戏吧"
@ -42,6 +47,7 @@ object PluginMain : KotlinPlugin(
"答错了,计算结果为 $result"
}
} catch (e: Throwable) {
// logger.error(e)
"错误:${e.message}"
}
}

View File

@ -25,7 +25,12 @@ class Point24 {
return (args[0].toInt() and args[1].toInt()).toDouble()
}
},
object : Operator("|", 2, true, Operator.PRECEDENCE_ADDITION - 3) {
object : Operator("^", 2, true, Operator.PRECEDENCE_ADDITION - 3) {
override fun apply(vararg args: Double): Double {
return (args[0].toInt() xor args[1].toInt()).toDouble()
}
},
object : Operator("|", 2, true, Operator.PRECEDENCE_ADDITION - 4) {
override fun apply(vararg args: Double): Double {
return (args[0].toInt() or args[1].toInt()).toDouble()
}