Compare commits

..

No commits in common. "master" and "v0.1.1" have entirely different histories.

5 changed files with 15 additions and 30 deletions

View File

@ -1,8 +1,8 @@
# J Dice
基于Mirai Console的骰子插件
用法十分简单, `3d6` 表示投出 `3` `6` 面骰子,下限是 `3`,上限是 `3*6` 即(3~18)。
用法十分简单,`3d6`表示投出`3`颗`6`面骰子,下限是`3`,上限是`3*6`即(3~18)。
`d20` 表示投出`1`颗`20`面骰子,可以在一条消息中投多次,例如 `d20, d20 d20`(即正则可匹配多个结果)
`d20` 表示投出`1`颗`20`面骰子。
匹配的正则表达式如下 `\b(\d{0,3})[dD](\d{1,3})\b`
匹配的正则表达式如下`\b(\d*)[dD](\d+)\b`

View File

@ -1,13 +1,13 @@
plugins {
val kotlinVersion = "1.8.10"
val kotlinVersion = "1.7.10"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
id("net.mamoe.mirai-console") version "2.16.0"
id("net.mamoe.mirai-console") version "2.13.4"
}
group = "top.jie65535"
version = "0.3.0"
version = "0.1.1"
repositories {
maven("https://maven.aliyun.com/repository/public")

View File

@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0
gradlew vendored Executable file → Normal file
View File

View File

@ -2,10 +2,9 @@ package top.jie65535
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.GlobalEventChannel
import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.message.data.MessageSource.Key.quote
import net.mamoe.mirai.message.data.PlainText
import net.mamoe.mirai.utils.info
import kotlin.random.Random
@ -13,36 +12,27 @@ object JDice : KotlinPlugin(
JvmPluginDescription(
id = "top.jie65535.dice",
name = "J Dice",
version = "0.3.0",
version = "0.1.1",
) {
author("jie65535")
}
) {
private val regex = Regex("""(?<!\S)(\d{0,3})[dD]([1-9]\d{0,2})(?!\S)""")
private val regex = Regex("""\b(\d*)[dD](\d+)\b""")
private val random = Random(System.currentTimeMillis())
override fun onEnable() {
globalEventChannel().subscribeMessages {
has<PlainText> { plainText ->
regex.findAll(plainText.content).map {
GlobalEventChannel.parentScope(this)
.subscribeMessages {
regex.finding {
val (c, d) = it.destructured
val count = if (c.isEmpty()) 1 else c.toInt()
val top = d.toInt()
if (count in 1..100 && top in 2..100) {
var value = 0
for (i in 1..count) {
value += random.nextInt(1, top + 1)
}
value.toString()
} else {
null
if (count > 0 && top > 1) {
val value = random.nextInt(count, count * top + 1)
subject.sendMessage(message.quote() + value.toString())
}
}.filter{ it != null }.joinToString().let {
if (it.isNotEmpty())
subject.sendMessage(message.quote() + it)
}
}
}
logger.info { "Plugin loaded. https://github.com/jie65535/JDice" }
}