mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-24 20:43:33 +08:00
Make java user happier
This commit is contained in:
parent
29091e817f
commit
4bec7d753b
mirai-core-qqandroid
build.gradle.kts
src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network
mirai-core
build.gradle.kts
src/commonMain/kotlin/net.mamoe.mirai/message/data
mirai-demos/mirai-demo-java/src/main/java/demo
@ -118,9 +118,9 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
//
|
||||
//tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
// kotlinOptions.jvmTarget = "1.8"
|
||||
//}
|
||||
|
||||
apply(from = rootProject.file("gradle/publish.gradle"))
|
||||
|
@ -216,7 +216,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
|
||||
troopListData.groups.forEach { troopNum ->
|
||||
launch {
|
||||
try {
|
||||
|
||||
try {
|
||||
bot.groups.delegate.addLast(
|
||||
@Suppress("DuplicatedCode")
|
||||
GroupImpl(
|
||||
|
@ -150,9 +150,9 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
//
|
||||
//tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
// kotlinOptions.jvmTarget = "1.8"
|
||||
//}
|
||||
|
||||
apply(from = rootProject.file("gradle/publish.gradle"))
|
||||
|
@ -7,6 +7,9 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
@file:Suppress("EXPERIMENTAL_API_USAGE")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
@ -14,6 +17,8 @@ package net.mamoe.mirai.message.data
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.groupCardOrNick
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
|
||||
/**
|
||||
|
@ -7,8 +7,14 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
/**
|
||||
* "@全体成员"
|
||||
*
|
||||
|
@ -7,8 +7,13 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,9 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
@file:Suppress("EXPERIMENTAL_API_USAGE")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
@ -14,13 +17,18 @@ package net.mamoe.mirai.message.data
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import net.mamoe.mirai.utils.io.chunkedHexToBytes
|
||||
import kotlin.js.JsName
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* 自定义表情 (收藏的表情), 图片
|
||||
*/
|
||||
sealed class Image : Message {
|
||||
companion object Key : Message.Key<Image> {
|
||||
@JvmStatic
|
||||
@JsName("fromId")
|
||||
@JvmName("fromId")
|
||||
operator fun invoke(imageId: String): Image = when (imageId.length) {
|
||||
37 -> NotOnlineImageFromFile(imageId) // /f8f1ab55-bf8e-4236-b55e-955848d7069f
|
||||
|
@ -13,6 +13,7 @@ package net.mamoe.mirai.message.data
|
||||
|
||||
import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.contact.sendMessage
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
|
||||
/**
|
||||
* 可发送的或从服务器接收的消息.
|
||||
@ -82,6 +83,7 @@ interface Message {
|
||||
* println(c)// "Hello world!"
|
||||
* ```
|
||||
*/
|
||||
@JvmSynthetic // in java they should use `plus` instead
|
||||
fun followedBy(tail: Message): MessageChain {
|
||||
require(tail !is SingleOnly) { "SingleOnly Message cannot follow another message" }
|
||||
require(this !is SingleOnly) { "SingleOnly Message cannot be followed" }
|
||||
@ -92,6 +94,7 @@ interface Message {
|
||||
override fun toString(): String
|
||||
|
||||
operator fun plus(another: Message): MessageChain = this.followedBy(another)
|
||||
|
||||
operator fun plus(another: String): MessageChain = this.followedBy(another.toMessage())
|
||||
// `+ ""` will be resolved to `plus(String)` instead of `plus(CharSeq)`
|
||||
operator fun plus(another: CharSequence): MessageChain = this.followedBy(another.toString().toMessage())
|
||||
|
@ -7,6 +7,9 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import net.mamoe.mirai.message.data.NullMessageChain.toString
|
||||
@ -14,6 +17,9 @@ import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.js.JsName
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.jvm.Volatile
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
@ -35,10 +41,12 @@ interface MessageChain : Message, MutableList<Message> {
|
||||
override fun followedBy(tail: Message): MessageChain
|
||||
// endregion
|
||||
|
||||
@JvmSynthetic
|
||||
operator fun plusAssign(message: Message) {
|
||||
this.followedBy(message)
|
||||
}
|
||||
|
||||
@JvmSynthetic // make java user happier
|
||||
operator fun plusAssign(plain: String) {
|
||||
this.plusAssign(plain.toMessage())
|
||||
}
|
||||
@ -53,7 +61,7 @@ interface MessageChain : Message, MutableList<Message> {
|
||||
operator fun <M : Message> get(key: Message.Key<M>): M = first(key)
|
||||
|
||||
override fun eq(other: Message): Boolean {
|
||||
if(other is MessageChain && other.size != this.size)
|
||||
if (other is MessageChain && other.size != this.size)
|
||||
return false
|
||||
return this.toString() == other.toString()
|
||||
}
|
||||
@ -67,13 +75,16 @@ inline operator fun <reified T : Message> MessageChain.getValue(thisRef: Any?, p
|
||||
/**
|
||||
* 构造无初始元素的可修改的 [MessageChain]. 初始大小将会被设定为 8
|
||||
*/
|
||||
@JsName("emptyMessageChain")
|
||||
@JvmName("newChain")
|
||||
@JsName("newChain")
|
||||
@Suppress("FunctionName")
|
||||
fun MessageChain(): MessageChain = EmptyMessageChain()
|
||||
|
||||
/**
|
||||
* 构造无初始元素的可修改的 [MessageChain]. 初始大小将会被设定为 [initialCapacity]
|
||||
*/
|
||||
@JvmName("newChain")
|
||||
@JsName("newChain")
|
||||
@Suppress("FunctionName")
|
||||
fun MessageChain(initialCapacity: Int): MessageChain =
|
||||
if (initialCapacity == 0) EmptyMessageChain()
|
||||
@ -83,6 +94,8 @@ fun MessageChain(initialCapacity: Int): MessageChain =
|
||||
* 构造 [MessageChain]
|
||||
* 若仅提供一个参数, 请考虑使用 [Message.toChain] 以优化性能
|
||||
*/
|
||||
@JvmName("newChain")
|
||||
@JsName("newChain")
|
||||
@Suppress("FunctionName")
|
||||
fun MessageChain(vararg messages: Message): MessageChain =
|
||||
if (messages.isEmpty()) EmptyMessageChain()
|
||||
@ -91,6 +104,8 @@ fun MessageChain(vararg messages: Message): MessageChain =
|
||||
/**
|
||||
* 构造 [MessageChain]
|
||||
*/
|
||||
@JvmName("newChain")
|
||||
@JsName("newChain")
|
||||
@Suppress("FunctionName")
|
||||
fun MessageChain(messages: Iterable<Message>): MessageChain =
|
||||
MessageChainImpl(messages.toMutableList())
|
||||
@ -106,6 +121,8 @@ fun MessageChain(messages: Iterable<Message>): MessageChain =
|
||||
*
|
||||
* @see Message.toChain receiver 模式
|
||||
*/
|
||||
@JvmName("newSingleMessageChain")
|
||||
@JsName("newChain")
|
||||
@MiraiExperimentalAPI
|
||||
@UseExperimental(ExperimentalContracts::class)
|
||||
@Suppress("FunctionName")
|
||||
@ -301,7 +318,7 @@ internal inline class MessageChainImpl constructor(
|
||||
constructor(vararg messages: Message) : this(messages.toMutableList())
|
||||
|
||||
// region Message override
|
||||
override fun toString(): String = this.delegate.joinToString("") { it.toString() }
|
||||
override fun toString(): String = this.delegate.joinToString("") { it.toString() }
|
||||
|
||||
override operator fun contains(sub: String): Boolean = delegate.any { it.contains(sub) }
|
||||
override fun followedBy(tail: Message): MessageChain {
|
||||
@ -352,6 +369,7 @@ internal inline class SingleMessageChainImpl(
|
||||
|
||||
// region Message override
|
||||
override operator fun contains(sub: String): Boolean = delegate.contains(sub)
|
||||
|
||||
override fun followedBy(tail: Message): MessageChain {
|
||||
require(tail !is SingleOnly) { "SingleOnly Message cannot follow another message" }
|
||||
return if (tail is MessageChain) tail.apply { followedBy(delegate) }
|
||||
|
@ -7,8 +7,14 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
/**
|
||||
* 消息源, 用于被引用. 它将由协议模块实现.
|
||||
* 消息源只用于 [QuoteReply]
|
||||
@ -18,7 +24,7 @@ package net.mamoe.mirai.message.data
|
||||
* @see MessageSource.quote 引用这条消息, 创建 [MessageChain]
|
||||
*/
|
||||
interface MessageSource : Message {
|
||||
companion object : Message.Key<MessageSource>
|
||||
companion object Key : Message.Key<MessageSource>
|
||||
|
||||
/**
|
||||
* 实际上是个随机数, 但服务器确实是用它当做 uid
|
||||
|
@ -7,9 +7,19 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
/**
|
||||
* 纯文本. 可含 emoji 表情.
|
||||
*
|
||||
* 一般不需要主动构造 [PlainText], [Message] 可直接与 [String] 相加. Java 用户请使用 [MessageChain.plus]
|
||||
*/
|
||||
inline class PlainText(val stringValue: String) : Message {
|
||||
override operator fun contains(sub: String): Boolean = sub in stringValue
|
||||
override fun toString(): String = stringValue
|
||||
@ -17,7 +27,7 @@ inline class PlainText(val stringValue: String) : Message {
|
||||
companion object Key : Message.Key<PlainText>
|
||||
|
||||
override fun eq(other: Message): Boolean {
|
||||
if(other is MessageChain){
|
||||
if (other is MessageChain) {
|
||||
return other eq this.toString()
|
||||
}
|
||||
return other is PlainText && other.stringValue == this.stringValue
|
||||
|
@ -7,10 +7,15 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
|
||||
/**
|
||||
|
@ -7,10 +7,17 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageUtils")
|
||||
|
||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
/**
|
||||
* XML 消息, 如分享, 卡片等.
|
||||
*
|
||||
@ -30,6 +37,7 @@ inline class XMLMessage(val stringValue: String) : Message,
|
||||
* 构造一条 XML 消息
|
||||
*/
|
||||
@XMLDsl
|
||||
@MiraiExperimentalAPI("还未支持")
|
||||
inline fun buildXMLMessage(block: @XMLDsl XMLMessageBuilder.() -> Unit): XMLMessage =
|
||||
XMLMessage(XMLMessageBuilder().apply(block).text)
|
||||
|
||||
|
@ -5,6 +5,9 @@ import net.mamoe.mirai.japt.BlockingContacts;
|
||||
import net.mamoe.mirai.japt.BlockingQQ;
|
||||
import net.mamoe.mirai.japt.Events;
|
||||
import net.mamoe.mirai.message.GroupMessage;
|
||||
import net.mamoe.mirai.message.data.At;
|
||||
import net.mamoe.mirai.message.data.Image;
|
||||
import net.mamoe.mirai.message.data.MessageUtils;
|
||||
|
||||
class BlockingTest {
|
||||
|
||||
@ -19,8 +22,14 @@ class BlockingTest {
|
||||
|
||||
Events.subscribeAlways(GroupMessage.class, (GroupMessage message) -> {
|
||||
final BlockingQQ sender = BlockingContacts.createBlocking(message.getSender());
|
||||
sender.sendMessage("Hello World!");
|
||||
System.out.println("发送完了");
|
||||
|
||||
sender.sendMessage("Hello");
|
||||
sender.sendMessage(MessageUtils.newChain()
|
||||
.plus(new At(message.getSender()))
|
||||
.plus(Image.fromId("{xxxx}.jpg"))
|
||||
.plus("123465")
|
||||
);
|
||||
});
|
||||
|
||||
Thread.sleep(999999999);
|
||||
|
Loading…
Reference in New Issue
Block a user