1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-03-26 07:20:09 +08:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
jiahua.liu 2020-02-16 20:10:24 +08:00
commit 47c26e43db
7 changed files with 108 additions and 15 deletions
gradle.properties
mirai-console-graphical
build.gradle.kts
src/main/kotlin/net/mamoe/mirai/console/graphical
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event
mirai-japt

View File

@ -2,7 +2,7 @@
kotlin.code.style=official
# config
mirai_version=0.15.1
mirai_japt_version=1.0.0
mirai_japt_version=1.0.1
kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
# kotlin

View File

@ -31,4 +31,8 @@ dependencies {
api(group = "no.tornado", name = "tornadofx", version = "1.7.19")
api("org.bouncycastle:bcprov-jdk15on:1.64")
// classpath is not set correctly by IDE
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

View File

@ -0,0 +1,17 @@
package net.mamoe.mirai.console.graphical
import net.mamoe.mirai.console.graphical.view.PrimaryView
import tornadofx.App
import tornadofx.launch
fun main(args: Array<String>) {
launch<MainApp>(args)
}
class MainApp: App(PrimaryView::class) {
override fun init() {
super.init()
}
}

View File

@ -0,0 +1,31 @@
package net.mamoe.mirai.console.graphical.controller
import net.mamoe.mirai.Bot
import net.mamoe.mirai.console.MiraiConsoleUI
import tornadofx.Controller
class MiraiController : Controller(), MiraiConsoleUI {
override fun pushLog(identity: Long, message: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun prePushBot(identity: Long) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun pushBot(bot: Bot) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun pushVersion(consoleVersion: String, consoleBuild: String, coreVersion: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override suspend fun requestInput(question: String): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun pushBotAdminStatus(identity: Long, admins: List<Long>) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}

View File

@ -0,0 +1,11 @@
package net.mamoe.mirai.console.graphical.view
import tornadofx.View
import tornadofx.borderpane
class PrimaryView : View() {
override val root = borderpane {
}
}

View File

@ -477,25 +477,44 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
}
/**
* 如果消息内容可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent`
* 如果消息内容可由正则表达式匹配([Regex.matchEntire])
*/
@MessageDsl
fun matching(regex: Regex): ListeningFilter =
content { regex.matchEntire(it) != null }
/**
* 如果 [filter] 返回 `true` 就执行 `onEvent`
* 如果消息内容可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent`
*/
@MessageDsl
inline fun matching(regex: Regex, crossinline onEvent: MessageListener<T>): Listener<T> =
content({ regex.matchEntire(it) != null }, onEvent)
inline fun matching(regex: Regex, crossinline onEvent: @MessageDsl suspend T.(MatchResult) -> Unit): Listener<T> =
always {
val find = regex.matchEntire(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply {
onEvent.invoke(this, find)
}
}
/**
* 如果消息内容可由正则表达式查找([Regex.find])
*/
@MessageDsl
fun finding(regex: Regex): ListeningFilter =
content { regex.find(it) != null }
/**
* 如果消息内容可由正则表达式查找([Regex.find]), 就执行 `onEvent`
*/
@MessageDsl
fun finding(regex: Regex): ListeningFilter =
content { regex.find(it) != null }
inline fun finding(regex: Regex, crossinline onEvent: @MessageDsl suspend T.(MatchResult) -> Unit): Listener<T> =
always {
val find = regex.find(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply {
onEvent.invoke(this, find)
}
}
/**
@ -527,11 +546,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
inline infix fun Regex.matchingReply(crossinline replier: @MessageDsl suspend T.(String) -> Any?): Listener<T> =
content({ this@matchingReply.matchEntire(it) != null }, {
inline infix fun Regex.matchingReply(crossinline replier: @MessageDsl suspend T.(MatchResult) -> Any?): Listener<T> =
always {
val find = this@matchingReply.matchEntire(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply(replier)
})
this.executeAndReply {
replier.invoke(this, find)
}
}
/**
* 若消息内容可由正则表达式查找([Regex.find]), 则执行 [replier] 并将其返回值回复给发信对象.
@ -541,11 +563,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
inline infix fun Regex.findingReply(crossinline replier: @MessageDsl suspend T.(String) -> Any?): Listener<T> =
content({ this@findingReply.find(it) != null }, {
inline infix fun Regex.findingReply(crossinline replier: @MessageDsl suspend T.(MatchResult) -> Any?): Listener<T> =
always {
val find = this@findingReply.find(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply(replier)
})
this.executeAndReply {
replier.invoke(this, find)
}
}
/**
* 不考虑空格, 若消息内容以 [this] 开始则执行 [replier] 并将其返回值回复给发信对象.

View File

@ -39,6 +39,11 @@ description = "Java helper for Mirai"
val mirai_japt_version: String by rootProject.ext
version = mirai_japt_version
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlin {
sourceSets {
all {