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
2b60130b
Commit
2b60130b
authored
Feb 14, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http-api support quoteReply
parent
1b3b543c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
4 deletions
+87
-4
mirai-api-http/README_CH.md
mirai-api-http/README_CH.md
+54
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
...kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
+5
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
...ain/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
+16
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/SendMessageRouteModule.kt
.../net/mamoe/mirai/api/http/route/SendMessageRouteModule.kt
+10
-2
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/Json.kt
...ttp/src/main/kotlin/net/mamoe/mirai/api/http/util/Json.kt
+2
-0
No files found.
mirai-api-http/README_CH.md
View file @
2b60130b
...
@@ -220,6 +220,44 @@ fun main() {
...
@@ -220,6 +220,44 @@ fun main() {
### 发送引用回复消息(仅支持群消息)
```
[POST] /sendQuoteMessage
```
使用此方法向指定的消息进行引用回复
#### 请求
```
json5
{
"sessionKey": "YourSession",
"target": 987654321,
"messageChain": [
{ "type": "Plain", "text":"hello\n" },
{ "type": "Plain", "text":"world" }
]
}
```
| 名字 | 类型 | 可选 | 举例 | 说明 |
| ------------ | ------ | ----- | ----------- | -------------------------------- |
| sessionKey | String | false | YourSession | 已经激活的Session |
| target | Long | false | 987654321 | 引用消息的Message Source的Uid |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码
```
json5
{
"code": 0,
"msg": "success"
}
```
### 发送图片消息(通过URL)
### 发送图片消息(通过URL)
```
```
...
@@ -308,6 +346,9 @@ Content-Type:multipart/form-data
...
@@ -308,6 +346,9 @@ Content-Type:multipart/form-data
[{
[{
"type": "GroupMessage", // 消息类型:GroupMessage或FriendMessage
"type": "GroupMessage", // 消息类型:GroupMessage或FriendMessage
"messageChain": [{ // 消息链,是一个消息对象构成的数组
"messageChain": [{ // 消息链,是一个消息对象构成的数组
"type": "Source",
"uid": 123456
},{
"type": "Plain",
"type": "Plain",
"text": "Miral牛逼"
"text": "Miral牛逼"
}],
}],
...
@@ -350,6 +391,19 @@ Content-Type:multipart/form-data
...
@@ -350,6 +391,19 @@ Content-Type:multipart/form-data
+
[ ] Xml,Xml卡片消息
+
[ ] Xml,Xml卡片消息
+
[ ] 敬请期待
+
[ ] 敬请期待
#### Source
```
json5
{
"type": "Source",
"uid": 123456
}
```
| 名字 | 类型 | 说明 |
| ---- | ---- | ------------------------------------------------------------ |
| uid | Long | 消息的识别号,用于引用回复(Source类型只在群消息中返回,且永远为chain的第一个元素) |
#### At
#### At
```
json5
```
json5
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
View file @
2b60130b
...
@@ -36,6 +36,9 @@ data class UnKnownMessagePacketDTO(val msg: String) : MessagePacketDTO()
...
@@ -36,6 +36,9 @@ data class UnKnownMessagePacketDTO(val msg: String) : MessagePacketDTO()
// Message
// Message
@Serializable
@Serializable
@SerialName
(
"Source"
)
data class
MessageSourceDTO
(
val
uid
:
Long
)
:
MessageDTO
()
@Serializable
@SerialName
(
"At"
)
@SerialName
(
"At"
)
data class
AtDTO
(
val
target
:
Long
,
val
display
:
String
)
:
MessageDTO
()
data class
AtDTO
(
val
target
:
Long
,
val
display
:
String
)
:
MessageDTO
()
@Serializable
@Serializable
...
@@ -85,6 +88,7 @@ fun MessageChainDTO.toMessageChain() =
...
@@ -85,6 +88,7 @@ fun MessageChainDTO.toMessageChain() =
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
fun
Message
.
toDTO
()
=
when
(
this
)
{
fun
Message
.
toDTO
()
=
when
(
this
)
{
is
MessageSource
->
MessageSourceDTO
(
messageUid
)
is
At
->
AtDTO
(
target
,
display
)
is
At
->
AtDTO
(
target
,
display
)
is
AtAll
->
AtAllDTO
(
0L
)
is
AtAll
->
AtAllDTO
(
0L
)
is
Face
->
FaceDTO
(
id
.
value
.
toInt
())
is
Face
->
FaceDTO
(
id
.
value
.
toInt
())
...
@@ -102,7 +106,7 @@ fun MessageDTO.toMessage() = when (this) {
...
@@ -102,7 +106,7 @@ fun MessageDTO.toMessage() = when (this) {
is
PlainDTO
->
PlainText
(
text
)
is
PlainDTO
->
PlainText
(
text
)
is
ImageDTO
->
Image
(
imageId
)
is
ImageDTO
->
Image
(
imageId
)
is
XmlDTO
->
XMLMessage
(
xml
)
is
XmlDTO
->
XMLMessage
(
xml
)
is
UnknownMessageDTO
->
PlainText
(
"assert cannot reach"
)
is
MessageSourceDTO
,
is
UnknownMessageDTO
->
PlainText
(
"assert cannot reach"
)
}
}
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
View file @
2b60130b
...
@@ -9,17 +9,32 @@
...
@@ -9,17 +9,32 @@
package
net.mamoe.mirai.api.http.queue
package
net.mamoe.mirai.api.http.queue
import
net.mamoe.mirai.message.GroupMessage
import
net.mamoe.mirai.message.MessagePacket
import
net.mamoe.mirai.message.MessagePacket
import
net.mamoe.mirai.message.data.MessageSource
import
java.util.concurrent.ConcurrentHashMap
import
java.util.concurrent.ConcurrentLinkedDeque
import
java.util.concurrent.ConcurrentLinkedDeque
class
MessageQueue
:
ConcurrentLinkedDeque
<
MessagePacket
<
*
,
*
>>()
{
class
MessageQueue
:
ConcurrentLinkedDeque
<
MessagePacket
<
*
,
*
>>()
{
val
quoteCache
=
ConcurrentHashMap
<
Long
,
GroupMessage
>()
fun
fetch
(
size
:
Int
):
List
<
MessagePacket
<
*
,
*
>>
{
fun
fetch
(
size
:
Int
):
List
<
MessagePacket
<
*
,
*
>>
{
var
count
=
size
var
count
=
size
quoteCache
.
clear
()
val
ret
=
ArrayList
<
MessagePacket
<
*
,
*
>>(
count
)
val
ret
=
ArrayList
<
MessagePacket
<
*
,
*
>>(
count
)
while
(!
this
.
isEmpty
()
&&
count--
>
0
)
{
while
(!
this
.
isEmpty
()
&&
count--
>
0
)
{
ret
.
add
(
this
.
pop
())
val
packet
=
pop
()
ret
.
add
(
packet
)
if
(
packet
is
GroupMessage
)
{
addCache
(
packet
)
}
}
}
return
ret
return
ret
}
}
private
fun
addCache
(
msg
:
GroupMessage
)
{
quoteCache
[
msg
.
message
[
MessageSource
].
messageUid
]
=
msg
}
}
}
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/SendMessageRouteModule.kt
View file @
2b60130b
...
@@ -52,6 +52,12 @@ fun Application.messageModule() {
...
@@ -52,6 +52,12 @@ fun Application.messageModule() {
call
.
respondStateCode
(
StateCode
.
Success
)
call
.
respondStateCode
(
StateCode
.
Success
)
}
}
miraiVerify
<
SendDTO
>(
"/quoteMessage"
)
{
it
.
session
.
messageQueue
.
quoteCache
[
it
.
target
]
?.
quoteReply
(
it
.
messageChain
.
toMessageChain
())
?:
throw
NoSuchElementException
()
call
.
respondStateCode
(
StateCode
.
Success
)
}
miraiVerify
<
SendImageDTO
>(
"sendImageMessage"
)
{
miraiVerify
<
SendImageDTO
>(
"sendImageMessage"
)
{
val
bot
=
it
.
session
.
bot
val
bot
=
it
.
session
.
bot
val
contact
=
when
{
val
contact
=
when
{
...
@@ -72,12 +78,14 @@ fun Application.messageModule() {
...
@@ -72,12 +78,14 @@ fun Application.messageModule() {
if
(!
SessionManager
.
containSession
(
sessionKey
))
throw
IllegalSessionException
if
(!
SessionManager
.
containSession
(
sessionKey
))
throw
IllegalSessionException
val
session
=
try
{
val
session
=
try
{
SessionManager
[
sessionKey
]
as
AuthedSession
SessionManager
[
sessionKey
]
as
AuthedSession
}
catch
(
e
:
TypeCastException
)
{
throw
NotVerifiedSessionException
}
}
catch
(
e
:
TypeCastException
)
{
throw
NotVerifiedSessionException
}
val
type
=
parts
.
value
(
"type"
)
val
type
=
parts
.
value
(
"type"
)
parts
.
file
(
"img"
)
?.
apply
{
parts
.
file
(
"img"
)
?.
apply
{
val
image
=
streamProvider
().
use
{
val
image
=
streamProvider
().
use
{
when
(
type
)
{
when
(
type
)
{
"group"
->
session
.
bot
.
groups
.
toList
().
random
().
uploadImage
(
it
)
"group"
->
session
.
bot
.
groups
.
toList
().
random
().
uploadImage
(
it
)
"friend"
->
session
.
bot
.
qqs
.
toList
().
random
().
uploadImage
(
it
)
"friend"
->
session
.
bot
.
qqs
.
toList
().
random
().
uploadImage
(
it
)
else
->
null
else
->
null
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/Json.kt
View file @
2b60130b
...
@@ -13,6 +13,7 @@ import kotlinx.serialization.*
...
@@ -13,6 +13,7 @@ import kotlinx.serialization.*
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.modules.SerializersModule
import
kotlinx.serialization.modules.SerializersModule
import
net.mamoe.mirai.api.http.data.common.*
import
net.mamoe.mirai.api.http.data.common.*
import
net.mamoe.mirai.message.data.MessageSource
// 解析失败时直接返回null,由路由判断响应400状态
// 解析失败时直接返回null,由路由判断响应400状态
@UseExperimental
(
ImplicitReflectionSerializer
::
class
)
@UseExperimental
(
ImplicitReflectionSerializer
::
class
)
...
@@ -50,6 +51,7 @@ object MiraiJson {
...
@@ -50,6 +51,7 @@ object MiraiJson {
UnKnownMessagePacketDTO
::
class
with
UnKnownMessagePacketDTO
.
serializer
()
UnKnownMessagePacketDTO
::
class
with
UnKnownMessagePacketDTO
.
serializer
()
}
}
polymorphic
(
MessageDTO
.
serializer
())
{
polymorphic
(
MessageDTO
.
serializer
())
{
MessageSourceDTO
::
class
with
MessageSourceDTO
.
serializer
()
AtDTO
::
class
with
AtDTO
.
serializer
()
AtDTO
::
class
with
AtDTO
.
serializer
()
AtAllDTO
::
class
with
AtAllDTO
.
serializer
()
AtAllDTO
::
class
with
AtAllDTO
.
serializer
()
FaceDTO
::
class
with
FaceDTO
.
serializer
()
FaceDTO
::
class
with
FaceDTO
.
serializer
()
...
...
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