Compare commits

...

10 Commits

Author SHA1 Message Date
d5132d587c 更新Mirai依赖到2.16.0
优化正则表达式匹配条件
2025-03-01 00:14:01 +08:00
e6c476f948 更新Mirai依赖到2.15.0
修复返回null的问题
2024-03-25 23:56:45 +08:00
66f8798528 Update README 2023-02-10 13:19:16 +08:00
e2d4d00bb0 Update mirai version to 2.14.0 2023-02-10 13:16:21 +08:00
73a4b77c3b Add multiple matches
Update only matches plain text
2023-02-10 13:16:04 +08:00
7981ca3fef Add numeric range limit (<=100)
Add gradle-wrapper.properties
Fix multiple dice issue
2023-02-09 10:46:12 +00:00
907a30b654 Update Regex 2023-02-02 10:02:10 +00:00
52b61d41d1 Update version to 0.1.1 2023-02-02 09:57:37 +00:00
0975e7e49c
Update Regex to \b(\d*)[dD](\d+)\b 2023-02-02 17:40:35 +08:00
f631218c0c Fix value bounds 2023-01-31 22:32:32 +08:00
5 changed files with 31 additions and 16 deletions

View File

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

View File

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

View File

@ -0,0 +1,5 @@
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 Normal file → Executable file
View File

View File

@ -2,9 +2,10 @@ 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
@ -12,24 +13,33 @@ object JDice : KotlinPlugin(
JvmPluginDescription(
id = "top.jie65535.dice",
name = "J Dice",
version = "0.1.0",
version = "0.3.0",
) {
author("jie65535")
}
) {
private val regex = Regex("""(\d*)[dD](\d+)""")
private val regex = Regex("""(?<!\S)(\d{0,3})[dD]([1-9]\d{0,2})(?!\S)""")
private val random = Random(System.currentTimeMillis())
override fun onEnable() {
GlobalEventChannel.parentScope(this)
.subscribeMessages {
regex.finding {
globalEventChannel().subscribeMessages {
has<PlainText> { plainText ->
regex.findAll(plainText.content).map {
val (c, d) = it.destructured
val count = if (c.isEmpty()) 1 else c.toInt()
val top = d.toInt()
if (count > 0 && top > 1) {
val value = random.nextInt(count, count * top) + 1
subject.sendMessage(message.quote() + value.toString())
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
}
}.filter{ it != null }.joinToString().let {
if (it.isNotEmpty())
subject.sendMessage(message.quote() + it)
}
}
}