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
f4020e4a
Commit
f4020e4a
authored
Feb 23, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Http api support recall
parent
0d7af4a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
15 deletions
+54
-15
mirai-api-http/README_CH.md
mirai-api-http/README_CH.md
+33
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
...ain/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
+8
-9
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
...tlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
+13
-6
No files found.
mirai-api-http/README_CH.md
View file @
f4020e4a
...
...
@@ -297,6 +297,39 @@ Content-Type:multipart/form-data
### 撤回消息
```
[POST] /recall
```
使用此方法撤回指定消息。对于bot发送的消息,又2分钟时间限制。对于撤回群聊中群员的消息,需要有相应权限
#### 请求
```
json5
{
"sessionKey": "YourSession",
"target": 987654321
}
```
| 名字 | 类型 | 可选 | 举例 | 说明 |
| ------------ | ------ | ----- | ----------- | -------------------------------- |
| sessionKey | String | false | YourSession | 已经激活的Session |
| target | Long | false | 987654321 | 需要撤回的消息的messageId |
#### 响应: 返回统一状态码
```
json5
{
"code": 0,
"msg": "success"
}
```
### 获取Bot收到的消息和事件
```
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
View file @
f4020e4a
...
...
@@ -13,7 +13,6 @@ import net.mamoe.mirai.api.http.data.common.EventDTO
import
net.mamoe.mirai.api.http.data.common.IgnoreEventDTO
import
net.mamoe.mirai.api.http.data.common.toDTO
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.message.GroupMessage
import
net.mamoe.mirai.message.MessagePacket
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.utils.firstKey
...
...
@@ -21,8 +20,8 @@ import java.util.concurrent.ConcurrentLinkedDeque
class
MessageQueue
:
ConcurrentLinkedDeque
<
BotEvent
>()
{
val
quoteC
acheSize
=
4096
val
quoteC
ache
=
LinkedHashMap
<
Long
,
MessagePacket
<
*
,
*
>>()
val
c
acheSize
=
4096
val
c
ache
=
LinkedHashMap
<
Long
,
MessagePacket
<
*
,
*
>>()
suspend
fun
fetch
(
size
:
Int
):
List
<
EventDTO
>
{
var
count
=
size
...
...
@@ -45,13 +44,13 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
return
ret
}
fun
cache
Quote
(
messageId
:
Long
)
=
quoteC
ache
[
messageId
]
?:
throw
NoSuchElementException
()
fun
cache
(
messageId
:
Long
)
=
c
ache
[
messageId
]
?:
throw
NoSuchElementException
()
private
fun
addQuoteCache
(
msg
:
MessagePacket
<
*
,
*
>)
{
quoteC
ache
[
msg
.
message
[
MessageSource
].
id
]
=
msg
if
(
quoteCache
.
size
>
quoteC
acheSize
)
{
quoteCache
.
remove
(
quoteC
ache
.
firstKey
())
fun
addQuoteCache
(
msg
:
MessagePacket
<
*
,
*
>)
{
c
ache
[
msg
.
message
[
MessageSource
].
id
]
=
msg
if
(
cache
.
size
>
c
acheSize
)
{
cache
.
remove
(
c
ache
.
firstKey
())
}
}
}
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
View file @
f4020e4a
...
...
@@ -29,6 +29,8 @@ import net.mamoe.mirai.api.http.data.common.VerifyDTO
import
net.mamoe.mirai.api.http.data.common.toMessageChain
import
net.mamoe.mirai.api.http.util.toJson
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.message.FriendMessage
import
net.mamoe.mirai.message.GroupMessage
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.*
import
net.mamoe.mirai.message.uploadImage
...
...
@@ -59,26 +61,30 @@ fun Application.messageModule() {
miraiVerify
<
SendDTO
>(
"/sendFriendMessage"
)
{
val
quote
=
it
.
quote
?.
let
{
q
->
it
.
session
.
messageQueue
.
cache
Quote
(
q
).
run
{
it
.
session
.
messageQueue
.
cache
(
q
).
run
{
this
[
MessageSource
].
quote
(
sender
)
}}
it
.
session
.
bot
.
getFriend
(
it
.
target
).
apply
{
val
receipt
=
sendMessage
(
quote
,
it
.
messageChain
.
toMessageChain
(
this
),
this
)
receipt
.
source
.
ensureSequenceIdAvailable
()
it
.
session
.
messageQueue
.
addQuoteCache
(
FriendMessage
(
bot
.
selfQQ
,
receipt
.
source
.
toChain
()))
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
}
}
miraiVerify
<
SendDTO
>(
"/sendGroupMessage"
)
{
val
quote
=
it
.
quote
?.
let
{
q
->
it
.
session
.
messageQueue
.
cache
Quote
(
q
).
run
{
it
.
session
.
messageQueue
.
cache
(
q
).
run
{
this
[
MessageSource
].
quote
(
sender
)
}}
it
.
session
.
bot
.
getGroup
(
it
.
target
).
apply
{
val
receipt
=
sendMessage
(
quote
,
it
.
messageChain
.
toMessageChain
(
this
),
this
)
receipt
.
source
.
ensureSequenceIdAvailable
()
it
.
session
.
messageQueue
.
addQuoteCache
(
GroupMessage
(
""
,
botPermission
,
botAsMember
,
receipt
.
source
.
toChain
()))
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
}
}
...
...
@@ -123,8 +129,10 @@ fun Application.messageModule() {
}
miraiVerify
<
RecallDTO
>(
"recall"
)
{
// TODO
call
.
respond
(
HttpStatusCode
.
NotFound
,
"未完成"
)
it
.
session
.
messageQueue
.
cache
(
it
.
target
).
apply
{
it
.
session
.
bot
.
recall
(
get
(
MessageSource
))
}
call
.
respondStateCode
(
StateCode
.
Success
)
}
}
}
...
...
@@ -156,6 +164,5 @@ private class SendRetDTO(
@Serializable
private
data class
RecallDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
sender
:
Long
val
target
:
Long
)
:
VerifyDTO
()
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