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
1c1a053b
Commit
1c1a053b
authored
Nov 25, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split Messages in separate files
parent
71218943
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
578 additions
and
589 deletions
+578
-589
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
.../src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt
...in/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/At.kt
...-core/src/commonMain/kotlin/net.mamoe.mirai/message/At.kt
+18
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Face.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/message/Face.kt
+11
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Image.kt
...re/src/commonMain/kotlin/net.mamoe.mirai/message/Image.kt
+70
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
+1
-586
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageChain.kt
...commonMain/kotlin/net.mamoe.mirai/message/MessageChain.kt
+449
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/PlainText.kt
...rc/commonMain/kotlin/net.mamoe.mirai/message/PlainText.kt
+24
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Message.kt
....mamoe.mirai/network/protocol/tim/packet/event/Message.kt
+1
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
View file @
1c1a053b
...
@@ -5,6 +5,7 @@ package net.mamoe.mirai.contact
...
@@ -5,6 +5,7 @@ package net.mamoe.mirai.contact
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.message.Message
import
net.mamoe.mirai.message.Message
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.chain
import
net.mamoe.mirai.message.singleChain
import
net.mamoe.mirai.message.singleChain
import
net.mamoe.mirai.network.BotSession
import
net.mamoe.mirai.network.BotSession
import
net.mamoe.mirai.withSession
import
net.mamoe.mirai.withSession
...
@@ -40,7 +41,7 @@ interface Contact {
...
@@ -40,7 +41,7 @@ interface Contact {
//这两个方法应写为扩展函数, 但为方便 import 还是写在这里
//这两个方法应写为扩展函数, 但为方便 import 还是写在这里
suspend
fun
sendMessage
(
plain
:
String
)
=
sendMessage
(
plain
.
singleChain
())
suspend
fun
sendMessage
(
plain
:
String
)
=
sendMessage
(
plain
.
singleChain
())
suspend
fun
sendMessage
(
message
:
Message
)
=
sendMessage
(
message
.
singleC
hain
())
suspend
fun
sendMessage
(
message
:
Message
)
=
sendMessage
(
message
.
c
hain
())
}
}
/**
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt
View file @
1c1a053b
...
@@ -11,6 +11,7 @@ import net.mamoe.mirai.contact.*
...
@@ -11,6 +11,7 @@ import net.mamoe.mirai.contact.*
import
net.mamoe.mirai.contact.data.Profile
import
net.mamoe.mirai.contact.data.Profile
import
net.mamoe.mirai.message.Message
import
net.mamoe.mirai.message.Message
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.chain
import
net.mamoe.mirai.message.singleChain
import
net.mamoe.mirai.message.singleChain
import
net.mamoe.mirai.network.protocol.tim.packet.action.RequestProfileDetailsPacket
import
net.mamoe.mirai.network.protocol.tim.packet.action.RequestProfileDetailsPacket
import
net.mamoe.mirai.network.protocol.tim.packet.action.RequestProfileDetailsResponse
import
net.mamoe.mirai.network.protocol.tim.packet.action.RequestProfileDetailsResponse
...
@@ -25,7 +26,7 @@ internal sealed class ContactImpl : Contact {
...
@@ -25,7 +26,7 @@ internal sealed class ContactImpl : Contact {
//这两个方法应写为扩展函数, 但为方便 import 还是写在这里
//这两个方法应写为扩展函数, 但为方便 import 还是写在这里
override
suspend
fun
sendMessage
(
plain
:
String
)
=
sendMessage
(
plain
.
singleChain
())
override
suspend
fun
sendMessage
(
plain
:
String
)
=
sendMessage
(
plain
.
singleChain
())
override
suspend
fun
sendMessage
(
message
:
Message
)
=
sendMessage
(
message
.
singleC
hain
())
override
suspend
fun
sendMessage
(
message
:
Message
)
=
sendMessage
(
message
.
c
hain
())
}
}
@Suppress
(
"MemberVisibilityCanBePrivate"
,
"CanBeParameter"
)
@Suppress
(
"MemberVisibilityCanBePrivate"
,
"CanBeParameter"
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/At.kt
0 → 100644
View file @
1c1a053b
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
)
package
net.mamoe.mirai.message
import
net.mamoe.mirai.contact.QQ
/**
* At 一个人
*/
inline
class
At
(
val
target
:
UInt
)
:
Message
{
constructor
(
target
:
QQ
)
:
this
(
target
.
id
)
override
val
stringValue
:
String
get
()
=
"[@$target]"
// TODO: 2019/11/25 使用群名称进行 at. 因为手机端只会显示这个文字
override
fun
toString
():
String
=
stringValue
companion
object
Key
:
Message
.
Key
<
At
>
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Face.kt
0 → 100644
View file @
1c1a053b
package
net.mamoe.mirai.message
/**
* QQ 自带表情
*/
inline
class
Face
(
val
id
:
FaceId
)
:
Message
{
override
val
stringValue
:
String
get
()
=
"[face${id.value}]"
override
fun
toString
():
String
=
stringValue
companion
object
Key
:
Message
.
Key
<
Face
>
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Image.kt
0 → 100644
View file @
1c1a053b
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
)
package
net.mamoe.mirai.message
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.network.protocol.tim.packet.action.FriendImagePacket
import
net.mamoe.mirai.utils.ExternalImage
import
net.mamoe.mirai.utils.io.debugPrintln
import
net.mamoe.mirai.utils.io.toUHexString
/**
* 图片消息. 在发送时将会区分群图片和好友图片发送.
* 由接收消息时构建, 可直接发送
*
* @param id 这个图片的 [ImageId]
*/
inline
class
Image
(
inline
val
id
:
ImageId
)
:
Message
{
override
val
stringValue
:
String
get
()
=
"[${id.value}]"
override
fun
toString
():
String
=
stringValue
companion
object
Key
:
Message
.
Key
<
Image
>
}
inline
val
Image
.
idValue
:
String
get
()
=
id
.
value
inline
class
ImageId0x06
(
override
inline
val
value
:
String
)
:
ImageId
{
override
fun
toString
():
String
=
"ImageId($value)"
}
/**
* 一般是群的图片的 id.
*/
class
ImageId0x03
constructor
(
override
inline
val
value
:
String
,
inline
val
uniqueId
:
UInt
,
inline
val
height
:
Int
,
inline
val
width
:
Int
)
:
ImageId
{
override
fun
toString
():
String
=
"ImageId(value=$value, uniqueId=${uniqueId}, height=$height, width=$width)"
val
md5
:
ByteArray
get
()
=
this
.
value
.
substringAfter
(
"{"
).
substringBefore
(
"}"
)
.
replace
(
"-"
,
""
)
.
chunked
(
2
)
.
map
{
(
it
[
0
]
+
it
[
1
].
toString
()).
toUByte
(
16
).
toByte
()
}
.
toByteArray
().
also
{
check
(
it
.
size
==
16
);
debugPrintln
(
"image md5="
+
it
.
toUHexString
());
debugPrintln
(
"imageId=$this"
)
}
}
@Suppress
(
"FunctionName"
)
fun
ImageId
(
value
:
String
):
ImageId
=
ImageId0x06
(
value
)
@Suppress
(
"FunctionName"
)
fun
ImageId
(
value
:
String
,
uniqueId
:
UInt
,
height
:
Int
,
width
:
Int
):
ImageId
=
ImageId0x03
(
value
,
uniqueId
,
height
,
width
)
/**
* 图片的标识符. 由图片的数据产生.
* 对于群, [value] 类似于 `{F61593B5-5B98-1798-3F47-2A91D32ED2FC}.jpg`, 由图片文件 MD5 直接产生.
* 对于好友, [value] 类似于 `/01ee6426-5ff1-4cf0-8278-e8634d2909ef`, 由服务器返回.
*
* @see ExternalImage.groupImageId 群图片的 [ImageId] 获取
* @see FriendImagePacket 好友图片的 [ImageId] 获取
*/
interface
ImageId
{
val
value
:
String
}
fun
ImageId
.
checkLength
()
=
check
(
value
.
length
==
37
||
value
.
length
==
42
)
{
"Illegal ImageId length"
}
fun
ImageId
.
requireLength
()
=
require
(
value
.
length
==
37
||
value
.
length
==
42
)
{
"Illegal ImageId length"
}
fun
ImageId
.
image
():
Image
=
Image
(
this
)
suspend
inline
fun
ImageId
.
sendTo
(
contact
:
Contact
)
=
contact
.
sendMessage
(
this
.
image
())
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
View file @
1c1a053b
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageChain.kt
0 → 100644
View file @
1c1a053b
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/PlainText.kt
0 → 100644
View file @
1c1a053b
package
net.mamoe.mirai.message
inline
class
PlainText
(
override
val
stringValue
:
String
)
:
Message
{
override
operator
fun
contains
(
sub
:
String
):
Boolean
=
sub
in
stringValue
override
fun
toString
():
String
=
stringValue
companion
object
Key
:
Message
.
Key
<
PlainText
>
}
/**
* 构造 [PlainText]
*/
fun
String
.
toMessage
():
PlainText
=
PlainText
(
this
)
/**
* 得到包含作为 [PlainText] 的 [this] 的 [MessageChain].
*
* @return 唯一成员且不可修改的 [SingleMessageChainImpl]
*
* @see SingleMessageChain
* @see SingleMessageChainImpl
*/
fun
String
.
singleChain
():
MessageChain
=
this
.
toMessage
().
chain
()
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Message.kt
View file @
1c1a053b
...
@@ -65,7 +65,7 @@ abstract class MessagePacketBase<TSubject : Contact> : EventPacket, BotEvent() {
...
@@ -65,7 +65,7 @@ abstract class MessagePacketBase<TSubject : Contact> : EventPacket, BotEvent() {
*/
*/
suspend
inline
fun
reply
(
message
:
MessageChain
)
=
subject
.
sendMessage
(
message
)
suspend
inline
fun
reply
(
message
:
MessageChain
)
=
subject
.
sendMessage
(
message
)
suspend
inline
fun
reply
(
message
:
Message
)
=
subject
.
sendMessage
(
message
.
singleC
hain
())
suspend
inline
fun
reply
(
message
:
Message
)
=
subject
.
sendMessage
(
message
.
c
hain
())
suspend
inline
fun
reply
(
plain
:
String
)
=
subject
.
sendMessage
(
plain
.
toMessage
())
suspend
inline
fun
reply
(
plain
:
String
)
=
subject
.
sendMessage
(
plain
.
toMessage
())
@JvmName
(
"reply1"
)
@JvmName
(
"reply1"
)
...
...
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