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.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
|
||||
|
||||
@ -21,21 +22,27 @@ object JDice : KotlinPlugin(
|
||||
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 && count <= 100 && top > 1 && top <= 100) {
|
||||
if (count in 1..100 && top in 2..100) {
|
||||
var value = 0
|
||||
for (i in 1..count) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info { "Plugin loaded. https://github.com/jie65535/JDice" }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user