mirror of
https://github.com/jie65535/JDice.git
synced 2025-06-02 17:39:11 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
d5132d587c | |||
e6c476f948 | |||
66f8798528 | |||
e2d4d00bb0 | |||
73a4b77c3b | |||
7981ca3fef |
@ -1,8 +1,8 @@
|
|||||||
# J Dice
|
# J Dice
|
||||||
基于Mirai Console的骰子插件
|
基于Mirai Console的骰子插件
|
||||||
|
|
||||||
用法十分简单,`3d6`表示投出`3`颗`6`面骰子,下限是`3`,上限是`3*6`即(3~18)。
|
用法十分简单, `3d6` 表示投出 `3` 颗 `6` 面骰子,下限是 `3`,上限是 `3*6` 即(3~18)。
|
||||||
|
|
||||||
`d20` 表示投出`1`颗`20`面骰子。
|
`d20` 表示投出`1`颗`20`面骰子,可以在一条消息中投多次,例如 `d20, d20 d20`。(即正则可匹配多个结果)
|
||||||
|
|
||||||
匹配的正则表达式如下`\b(\d*)[dD](\d+)\b`
|
匹配的正则表达式如下 `\b(\d{0,3})[dD](\d{1,3})\b`
|
@ -1,13 +1,13 @@
|
|||||||
plugins {
|
plugins {
|
||||||
val kotlinVersion = "1.7.10"
|
val kotlinVersion = "1.8.10"
|
||||||
kotlin("jvm") version kotlinVersion
|
kotlin("jvm") version kotlinVersion
|
||||||
kotlin("plugin.serialization") 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"
|
group = "top.jie65535"
|
||||||
version = "0.1.1"
|
version = "0.3.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://maven.aliyun.com/repository/public")
|
maven("https://maven.aliyun.com/repository/public")
|
||||||
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal 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
|
@ -2,9 +2,10 @@ package top.jie65535
|
|||||||
|
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
||||||
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
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.event.subscribeMessages
|
||||||
import net.mamoe.mirai.message.data.MessageSource.Key.quote
|
import net.mamoe.mirai.message.data.MessageSource.Key.quote
|
||||||
|
import net.mamoe.mirai.message.data.PlainText
|
||||||
import net.mamoe.mirai.utils.info
|
import net.mamoe.mirai.utils.info
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
@ -12,27 +13,36 @@ 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.3.0",
|
||||||
) {
|
) {
|
||||||
author("jie65535")
|
author("jie65535")
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
private val regex = Regex("""\b(\d*)[dD](\d+)\b""")
|
private val regex = Regex("""(?<!\S)(\d{0,3})[dD]([1-9]\d{0,2})(?!\S)""")
|
||||||
private val random = Random(System.currentTimeMillis())
|
private val random = Random(System.currentTimeMillis())
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
GlobalEventChannel.parentScope(this)
|
globalEventChannel().subscribeMessages {
|
||||||
.subscribeMessages {
|
has<PlainText> { plainText ->
|
||||||
regex.finding {
|
regex.findAll(plainText.content).map {
|
||||||
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 in 1..100 && top in 2..100) {
|
||||||
val value = random.nextInt(count, count * top + 1)
|
var value = 0
|
||||||
subject.sendMessage(message.quote() + value.toString())
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info { "Plugin loaded. https://github.com/jie65535/JDice" }
|
logger.info { "Plugin loaded. https://github.com/jie65535/JDice" }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user