mirror of
https://github.com/jie65535/JDice.git
synced 2025-06-02 17:39:11 +08:00
Add multiple matches
Update only matches plain text
This commit is contained in:
parent
7981ca3fef
commit
73a4b77c3b
@ -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
|
||||||
|
|
||||||
@ -21,18 +22,24 @@ object JDice : KotlinPlugin(
|
|||||||
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 && count <= 100 && top > 1 && top <= 100) {
|
if (count in 1..100 && top in 2..100) {
|
||||||
var value = 0
|
var value = 0
|
||||||
for (i in 1..count) {
|
for (i in 1..count) {
|
||||||
value += random.nextInt(1, top + 1)
|
value += random.nextInt(1, top + 1)
|
||||||
}
|
}
|
||||||
subject.sendMessage(message.quote() + value.toString())
|
value.toString()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}.joinToString().let {
|
||||||
|
if (it.isNotEmpty())
|
||||||
|
subject.sendMessage(message.quote() + it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user