mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-10 02:07:01 +08:00
http api default at display
This commit is contained in:
parent
10e70ac370
commit
59c0af75f1
@ -413,13 +413,15 @@ Content-Type:multipart/form-data
|
||||
```json5
|
||||
{
|
||||
"type": "At",
|
||||
"target": 123456
|
||||
"target": 123456,
|
||||
"display": "@Mirai"
|
||||
}
|
||||
```
|
||||
|
||||
| 名字 | 类型 | 说明 |
|
||||
| ------ | ---- | -------- |
|
||||
| target | Long | 群员QQ号 |
|
||||
| 名字 | 类型 | 说明 |
|
||||
| ------- | ------ | ---------------------------------------------- |
|
||||
| target | Long | 群员QQ号 |
|
||||
| dispaly | String | At时显示的文字,发送消息时无效,自动使用群名片 |
|
||||
|
||||
#### AtAll
|
||||
|
||||
|
@ -11,6 +11,9 @@ package net.mamoe.mirai.api.http.data.common
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.message.FriendMessage
|
||||
import net.mamoe.mirai.message.GroupMessage
|
||||
import net.mamoe.mirai.message.MessagePacket
|
||||
@ -40,7 +43,7 @@ data class UnKnownMessagePacketDTO(val msg: String) : MessagePacketDTO()
|
||||
data class MessageSourceDTO(val uid: Long) : MessageDTO()
|
||||
@Serializable
|
||||
@SerialName("At")
|
||||
data class AtDTO(val target: Long, val display: String) : MessageDTO()
|
||||
data class AtDTO(val target: Long, val display: String = "") : MessageDTO()
|
||||
@Serializable
|
||||
@SerialName("AtAll")
|
||||
data class AtAllDTO(val target: Long = 0) : MessageDTO() // target为保留字段
|
||||
@ -83,8 +86,8 @@ suspend fun MessagePacket<*, *>.toDTO(): MessagePacketDTO = when (this) {
|
||||
else -> UnKnownMessagePacketDTO("UnKnown Message Packet")
|
||||
}.apply { messageChain = Array(message.size){ message[it].toDTO() }}
|
||||
|
||||
fun MessageChainDTO.toMessageChain() =
|
||||
MessageChain().apply { this@toMessageChain.forEach { add(it.toMessage()) } }
|
||||
fun MessageChainDTO.toMessageChain(contact: Contact) =
|
||||
MessageChain().apply { this@toMessageChain.forEach { add(it.toMessage(contact)) } }
|
||||
|
||||
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||
fun Message.toDTO() = when (this) {
|
||||
@ -99,8 +102,8 @@ fun Message.toDTO() = when (this) {
|
||||
}
|
||||
|
||||
@UseExperimental(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class)
|
||||
fun MessageDTO.toMessage() = when (this) {
|
||||
is AtDTO -> At(target, display)
|
||||
fun MessageDTO.toMessage(contact: Contact) = when (this) {
|
||||
is AtDTO -> At((contact as Group)[target])
|
||||
is AtAllDTO -> AtAll
|
||||
is FaceDTO -> Face(FaceId(faceId.toUByte()))
|
||||
is PlainDTO -> PlainText(text)
|
||||
|
@ -43,18 +43,23 @@ fun Application.messageModule() {
|
||||
}
|
||||
|
||||
miraiVerify<SendDTO>("/sendFriendMessage") {
|
||||
it.session.bot.getFriend(it.target).sendMessage(it.messageChain.toMessageChain())
|
||||
it.session.bot.getFriend(it.target).apply {
|
||||
sendMessage(it.messageChain.toMessageChain(this)) // this aka QQ
|
||||
}
|
||||
call.respondStateCode(StateCode.Success)
|
||||
}
|
||||
|
||||
miraiVerify<SendDTO>("/sendGroupMessage") {
|
||||
it.session.bot.getGroup(it.target).sendMessage(it.messageChain.toMessageChain())
|
||||
it.session.bot.getGroup(it.target).apply {
|
||||
sendMessage(it.messageChain.toMessageChain(this)) // this aka Group
|
||||
}
|
||||
call.respondStateCode(StateCode.Success)
|
||||
}
|
||||
|
||||
miraiVerify<SendDTO>("/quoteMessage") {
|
||||
it.session.messageQueue.quoteCache[it.target]?.quoteReply(it.messageChain.toMessageChain())
|
||||
?: throw NoSuchElementException()
|
||||
it.session.messageQueue.quoteCache[it.target]?.apply {
|
||||
quoteReply(it.messageChain.toMessageChain(group))
|
||||
} ?: throw NoSuchElementException()
|
||||
call.respondStateCode(StateCode.Success)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user