Commit 47c26e43 authored by jiahua.liu's avatar jiahua.liu

Merge remote-tracking branch 'origin/master'

parents e971fd76 71b1fb34
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
kotlin.code.style=official kotlin.code.style=official
# config # config
mirai_version=0.15.1 mirai_version=0.15.1
mirai_japt_version=1.0.0 mirai_japt_version=1.0.1
kotlin.incremental.multiplatform=true kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true kotlin.parallel.tasks.in.project=true
# kotlin # kotlin
......
...@@ -31,4 +31,8 @@ dependencies { ...@@ -31,4 +31,8 @@ dependencies {
api(group = "no.tornado", name = "tornadofx", version = "1.7.19") api(group = "no.tornado", name = "tornadofx", version = "1.7.19")
api("org.bouncycastle:bcprov-jdk15on:1.64") api("org.bouncycastle:bcprov-jdk15on:1.64")
// classpath is not set correctly by IDE // classpath is not set correctly by IDE
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
} }
\ No newline at end of file
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()
}
}
\ No newline at end of file
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.
}
}
\ No newline at end of file
package net.mamoe.mirai.console.graphical.view
import tornadofx.View
import tornadofx.borderpane
class PrimaryView : View() {
override val root = borderpane {
}
}
\ No newline at end of file
...@@ -477,26 +477,45 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>( ...@@ -477,26 +477,45 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
} }
/** /**
* 如果消息内容可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent` * 如果消息内容可由正则表达式匹配([Regex.matchEntire])
*/ */
@MessageDsl @MessageDsl
fun matching(regex: Regex): ListeningFilter = fun matching(regex: Regex): ListeningFilter =
content { regex.matchEntire(it) != null } content { regex.matchEntire(it) != null }
/** /**
* 如果 [filter] 返回 `true` 就执行 `onEvent` * 如果消息内容可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent`
*/ */
@MessageDsl @MessageDsl
inline fun matching(regex: Regex, crossinline onEvent: MessageListener<T>): Listener<T> = inline fun matching(regex: Regex, crossinline onEvent: @MessageDsl suspend T.(MatchResult) -> Unit): Listener<T> =
content({ regex.matchEntire(it) != null }, onEvent) always {
val find = regex.matchEntire(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply {
onEvent.invoke(this, find)
}
}
/** /**
* 如果消息内容可由正则表达式查找([Regex.find]), 就执行 `onEvent` * 如果消息内容可由正则表达式查找([Regex.find])
*/ */
@MessageDsl @MessageDsl
fun finding(regex: Regex): ListeningFilter = fun finding(regex: Regex): ListeningFilter =
content { regex.find(it) != null } content { regex.find(it) != null }
/**
* 如果消息内容可由正则表达式查找([Regex.find]), 就执行 `onEvent`
*/
@MessageDsl
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)
}
}
/** /**
* 若消息内容包含 [this] 则回复 [reply] * 若消息内容包含 [this] 则回复 [reply]
...@@ -527,11 +546,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>( ...@@ -527,11 +546,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复 * @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/ */
@MessageDsl @MessageDsl
inline infix fun Regex.matchingReply(crossinline replier: @MessageDsl suspend T.(String) -> Any?): Listener<T> = inline infix fun Regex.matchingReply(crossinline replier: @MessageDsl suspend T.(MatchResult) -> Any?): Listener<T> =
content({ this@matchingReply.matchEntire(it) != null }, { always {
val find = this@matchingReply.matchEntire(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING") @Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply(replier) this.executeAndReply {
}) replier.invoke(this, find)
}
}
/** /**
* 若消息内容可由正则表达式查找([Regex.find]), 则执行 [replier] 并将其返回值回复给发信对象. * 若消息内容可由正则表达式查找([Regex.find]), 则执行 [replier] 并将其返回值回复给发信对象.
...@@ -541,11 +563,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>( ...@@ -541,11 +563,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复 * @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/ */
@MessageDsl @MessageDsl
inline infix fun Regex.findingReply(crossinline replier: @MessageDsl suspend T.(String) -> Any?): Listener<T> = inline infix fun Regex.findingReply(crossinline replier: @MessageDsl suspend T.(MatchResult) -> Any?): Listener<T> =
content({ this@findingReply.find(it) != null }, { always {
val find = this@findingReply.find(it) ?: return@always
@Suppress("DSL_SCOPE_VIOLATION_WARNING") @Suppress("DSL_SCOPE_VIOLATION_WARNING")
this.executeAndReply(replier) this.executeAndReply {
}) replier.invoke(this, find)
}
}
/** /**
* 不考虑空格, 若消息内容以 [this] 开始则执行 [replier] 并将其返回值回复给发信对象. * 不考虑空格, 若消息内容以 [this] 开始则执行 [replier] 并将其返回值回复给发信对象.
......
...@@ -39,6 +39,11 @@ description = "Java helper for Mirai" ...@@ -39,6 +39,11 @@ description = "Java helper for Mirai"
val mirai_japt_version: String by rootProject.ext val mirai_japt_version: String by rootProject.ext
version = mirai_japt_version version = mirai_japt_version
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlin { kotlin {
sourceSets { sourceSets {
all { all {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment