Add numeric range limit (<=100)

Add gradle-wrapper.properties
Fix multiple dice issue
This commit is contained in:
2023-02-09 10:46:12 +00:00
parent 907a30b654
commit 7981ca3fef
4 changed files with 13 additions and 5 deletions

View File

@ -7,7 +7,7 @@ plugins {
} }
group = "top.jie65535" group = "top.jie65535"
version = "0.1.1" version = "0.1.2"
repositories { repositories {
maven("https://maven.aliyun.com/repository/public") 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.6-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0
gradlew vendored Normal file → Executable file
View File

View File

@ -12,12 +12,12 @@ object JDice : KotlinPlugin(
JvmPluginDescription( JvmPluginDescription(
id = "top.jie65535.dice", id = "top.jie65535.dice",
name = "J Dice", name = "J Dice",
version = "0.1.1", version = "0.1.2",
) { ) {
author("jie65535") author("jie65535")
} }
) { ) {
private val regex = Regex("""\b(\d*)[dD](\d+)\b""") private val regex = Regex("""\b(\d{0,3})[dD](\d{1,3})\b""")
private val random = Random(System.currentTimeMillis()) private val random = Random(System.currentTimeMillis())
override fun onEnable() { override fun onEnable() {
@ -27,8 +27,11 @@ object JDice : KotlinPlugin(
val (c, d) = it.destructured val (c, d) = it.destructured
val count = if (c.isEmpty()) 1 else c.toInt() val count = if (c.isEmpty()) 1 else c.toInt()
val top = d.toInt() val top = d.toInt()
if (count > 0 && top > 1) { if (count > 0 && count <= 100 && top > 1 && top <= 100) {
val value = random.nextInt(count, count * top + 1) var value = 0
for (i in 1..count) {
value += random.nextInt(1, top + 1)
}
subject.sendMessage(message.quote() + value.toString()) subject.sendMessage(message.quote() + value.toString())
} }
} }