Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
4bec7d75
Commit
4bec7d75
authored
Feb 18, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make java user happier
parent
29091e81
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
100 additions
and
16 deletions
+100
-16
mirai-core-qqandroid/build.gradle.kts
mirai-core-qqandroid/build.gradle.kts
+4
-4
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+2
-1
mirai-core/build.gradle.kts
mirai-core/build.gradle.kts
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt
+5
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/AtAll.kt
...c/commonMain/kotlin/net.mamoe.mirai/message/data/AtAll.kt
+6
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt
...rc/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt
+5
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
...c/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
+8
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
...commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
+3
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
...nMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
+21
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
...Main/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
+7
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt
...mmonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt
+11
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
...monMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
+5
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt
...src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt
+8
-0
mirai-demos/mirai-demo-java/src/main/java/demo/BlockingTest.java
...emos/mirai-demo-java/src/main/java/demo/BlockingTest.java
+11
-2
No files found.
mirai-core-qqandroid/build.gradle.kts
View file @
4bec7d75
...
...
@@ -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"
))
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
4bec7d75
...
...
@@ -216,7 +216,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
troopListData
.
groups
.
forEach
{
troopNum
->
launch
{
try
{
try
{
bot
.
groups
.
delegate
.
addLast
(
@Suppress
(
"DuplicatedCode"
)
GroupImpl
(
...
...
mirai-core/build.gradle.kts
View file @
4bec7d75
...
...
@@ -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"
))
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt
View file @
4bec7d75
...
...
@@ -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
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/AtAll.kt
View file @
4bec7d75
...
...
@@ -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
/**
* "@全体成员"
*
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt
View file @
4bec7d75
...
...
@@ -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
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
View file @
4bec7d75
...
...
@@ -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
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
View file @
4bec7d75
...
...
@@ -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
())
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
View file @
4bec7d75
...
...
@@ -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
)
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
View file @
4bec7d75
...
...
@@ -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
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt
View file @
4bec7d75
...
...
@@ -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
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
View file @
4bec7d75
...
...
@@ -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
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt
View file @
4bec7d75
...
...
@@ -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
)
...
...
mirai-demos/mirai-demo-java/src/main/java/demo/BlockingTest.java
View file @
4bec7d75
...
...
@@ -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"
);
sender
.
sendMessage
(
"Hello World!"
);
System
.
out
.
println
(
"发送完了"
);
sender
.
sendMessage
(
MessageUtils
.
newChain
()
.
plus
(
new
At
(
message
.
getSender
()))
.
plus
(
Image
.
fromId
(
"{xxxx}.jpg"
))
.
plus
(
"123465"
)
);
});
Thread
.
sleep
(
999999999
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment