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
cd73d7f5
Commit
cd73d7f5
authored
Feb 23, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Http api friendly quote
parent
a52655e2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
15 deletions
+36
-15
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
...ain/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
+7
-4
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
...tlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
+29
-11
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
View file @
cd73d7f5
...
@@ -14,6 +14,7 @@ import net.mamoe.mirai.api.http.data.common.IgnoreEventDTO
...
@@ -14,6 +14,7 @@ import net.mamoe.mirai.api.http.data.common.IgnoreEventDTO
import
net.mamoe.mirai.api.http.data.common.toDTO
import
net.mamoe.mirai.api.http.data.common.toDTO
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.message.GroupMessage
import
net.mamoe.mirai.message.GroupMessage
import
net.mamoe.mirai.message.MessagePacket
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.utils.firstKey
import
net.mamoe.mirai.utils.firstKey
import
java.util.concurrent.ConcurrentLinkedDeque
import
java.util.concurrent.ConcurrentLinkedDeque
...
@@ -21,7 +22,7 @@ import java.util.concurrent.ConcurrentLinkedDeque
...
@@ -21,7 +22,7 @@ import java.util.concurrent.ConcurrentLinkedDeque
class
MessageQueue
:
ConcurrentLinkedDeque
<
BotEvent
>()
{
class
MessageQueue
:
ConcurrentLinkedDeque
<
BotEvent
>()
{
val
quoteCacheSize
=
4096
val
quoteCacheSize
=
4096
val
quoteCache
=
LinkedHashMap
<
Long
,
GroupMessage
>()
val
quoteCache
=
LinkedHashMap
<
Long
,
MessagePacket
<
*
,
*
>
>()
suspend
fun
fetch
(
size
:
Int
):
List
<
EventDTO
>
{
suspend
fun
fetch
(
size
:
Int
):
List
<
EventDTO
>
{
var
count
=
size
var
count
=
size
...
@@ -37,15 +38,17 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
...
@@ -37,15 +38,17 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
}
}
}
}
// TODO: 等FriendMessage支持quote
if
(
event
is
MessagePacket
<
*
,
*
>)
{
if
(
event
is
GroupMessage
)
{
addQuoteCache
(
event
)
addQuoteCache
(
event
)
}
}
}
}
return
ret
return
ret
}
}
private
fun
addQuoteCache
(
msg
:
GroupMessage
)
{
fun
cacheQuote
(
messageId
:
Long
)
=
quoteCache
[
messageId
]
?:
throw
NoSuchElementException
()
private
fun
addQuoteCache
(
msg
:
MessagePacket
<
*
,
*
>)
{
quoteCache
[
msg
.
message
[
MessageSource
].
id
]
=
msg
quoteCache
[
msg
.
message
[
MessageSource
].
id
]
=
msg
if
(
quoteCache
.
size
>
quoteCacheSize
)
{
if
(
quoteCache
.
size
>
quoteCacheSize
)
{
quoteCache
.
remove
(
quoteCache
.
firstKey
())
quoteCache
.
remove
(
quoteCache
.
firstKey
())
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
View file @
cd73d7f5
...
@@ -28,7 +28,9 @@ import net.mamoe.mirai.api.http.data.common.MessageChainDTO
...
@@ -28,7 +28,9 @@ import net.mamoe.mirai.api.http.data.common.MessageChainDTO
import
net.mamoe.mirai.api.http.data.common.VerifyDTO
import
net.mamoe.mirai.api.http.data.common.VerifyDTO
import
net.mamoe.mirai.api.http.data.common.toMessageChain
import
net.mamoe.mirai.api.http.data.common.toMessageChain
import
net.mamoe.mirai.api.http.util.toJson
import
net.mamoe.mirai.api.http.util.toJson
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.*
import
net.mamoe.mirai.message.uploadImage
import
net.mamoe.mirai.message.uploadImage
import
java.net.URL
import
java.net.URL
...
@@ -42,30 +44,45 @@ fun Application.messageModule() {
...
@@ -42,30 +44,45 @@ fun Application.messageModule() {
call
.
respondJson
(
fetch
.
toJson
())
call
.
respondJson
(
fetch
.
toJson
())
}
}
suspend
fun
<
C
:
Contact
>
sendMessage
(
quote
:
QuoteReplyToSend
?,
messageChain
:
MessageChain
,
target
:
C
):
MessageReceipt
<
out
Contact
>
{
val
send
=
if
(
quote
==
null
)
{
messageChain
}
else
{
(
quote
+
messageChain
).
toChain
()
}
return
target
.
sendMessage
(
send
)
}
miraiVerify
<
SendDTO
>(
"/sendFriendMessage"
)
{
miraiVerify
<
SendDTO
>(
"/sendFriendMessage"
)
{
val
quote
=
it
.
quote
?.
let
{
q
->
it
.
session
.
messageQueue
.
cacheQuote
(
q
).
run
{
this
[
MessageSource
].
quote
(
sender
)
}}
it
.
session
.
bot
.
getFriend
(
it
.
target
).
apply
{
it
.
session
.
bot
.
getFriend
(
it
.
target
).
apply
{
val
receipt
=
sendMessage
(
it
.
messageChain
.
toMessageChain
(
this
))
// this aka QQ
val
receipt
=
sendMessage
(
quote
,
it
.
messageChain
.
toMessageChain
(
this
),
this
)
receipt
.
source
.
ensureSequenceIdAvailable
()
receipt
.
source
.
ensureSequenceIdAvailable
()
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
}
}
}
}
miraiVerify
<
SendDTO
>(
"/sendGroupMessage"
)
{
miraiVerify
<
SendDTO
>(
"/sendGroupMessage"
)
{
val
quote
=
it
.
quote
?.
let
{
q
->
it
.
session
.
messageQueue
.
cacheQuote
(
q
).
run
{
this
[
MessageSource
].
quote
(
sender
)
}}
it
.
session
.
bot
.
getGroup
(
it
.
target
).
apply
{
it
.
session
.
bot
.
getGroup
(
it
.
target
).
apply
{
val
receipt
=
sendMessage
(
it
.
messageChain
.
toMessageChain
(
this
))
// this aka Group
val
receipt
=
sendMessage
(
quote
,
it
.
messageChain
.
toMessageChain
(
this
),
this
)
receipt
.
source
.
ensureSequenceIdAvailable
()
receipt
.
source
.
ensureSequenceIdAvailable
()
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
}
}
}
}
miraiVerify
<
SendDTO
>(
"/sendQuoteMessage"
)
{
it
.
session
.
messageQueue
.
quoteCache
[
it
.
target
]
?.
apply
{
val
receipt
=
quoteReply
(
it
.
messageChain
.
toMessageChain
(
group
))
receipt
.
source
.
ensureSequenceIdAvailable
()
call
.
respondDTO
(
SendRetDTO
(
messageId
=
receipt
.
source
.
id
))
}
?:
throw
NoSuchElementException
()
}
miraiVerify
<
SendImageDTO
>(
"sendImageMessage"
)
{
miraiVerify
<
SendImageDTO
>(
"sendImageMessage"
)
{
val
bot
=
it
.
session
.
bot
val
bot
=
it
.
session
.
bot
val
contact
=
when
{
val
contact
=
when
{
...
@@ -115,6 +132,7 @@ fun Application.messageModule() {
...
@@ -115,6 +132,7 @@ fun Application.messageModule() {
@Serializable
@Serializable
private
data class
SendDTO
(
private
data class
SendDTO
(
override
val
sessionKey
:
String
,
override
val
sessionKey
:
String
,
val
quote
:
Long
?
=
null
,
val
target
:
Long
,
val
target
:
Long
,
val
messageChain
:
MessageChainDTO
val
messageChain
:
MessageChainDTO
)
:
VerifyDTO
()
)
:
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