1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-03-26 07:20:09 +08:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Him188 2020-02-19 18:37:35 +08:00
commit 385b36b09d
6 changed files with 64 additions and 26 deletions
mirai-api-http
README_CH.md
src/main/kotlin/net/mamoe/mirai/api/http
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical

View File

@ -16,6 +16,8 @@ fun main() {
}
```
## 认证相关
### 开始会话-认证(Authorize)
@ -141,6 +143,8 @@ fun main() {
> SessionKey与Bot 对应错误时将会返回状态码5指定对象不存在
## 消息相关
@ -261,10 +265,10 @@ fun main() {
### 发送图片消息通过URL
```
[POST] /sendGroupMessage
[POST] /sendImageMessage
```
使用此方法向指定群发送消息
使用此方法向指定对象(或好友)发送图片消息
#### 请求
@ -303,7 +307,7 @@ fun main() {
### 图片文件上传
```
[POST] /sendGroupMessage
[POST] /uploadImage
```
使用此方法上传图片文件至服务器并返回ImageId
@ -385,7 +389,7 @@ Content-Typemultipart/form-data
+ [x] At@消息
+ [x] AtAll@全体成员
+ [x] Face表情消息
+ [ ] Face表情消息
+ [x] Plain文字消息
+ [x] Image图片消息
+ [ ] XmlXml卡片消息
@ -414,10 +418,10 @@ Content-Typemultipart/form-data
}
```
| 名字 | 类型 | 说明 |
| ------- | ------ | ------------------------- |
| target | Long | 群员QQ号 |
| display | String | @时显示的文本如"@Mirai" |
| 名字 | 类型 | 说明 |
| ------- | ------ | ---------------------------------------------- |
| target | Long | 群员QQ号 |
| dispaly | String | At时显示的文字发送消息时无效自动使用群名片 |
#### AtAll
@ -517,6 +521,7 @@ Content-Typemultipart/form-data
```
### 获取群列表
使用此方法获取bot的群列表
@ -786,6 +791,8 @@ Content-Typemultipart/form-data
}
```
### 获取群设置
使用此方法获取群设置
@ -816,6 +823,7 @@ Content-Typemultipart/form-data
```
### 修改群员资料
使用此方法修改群员资料(需要有相关限权)
@ -856,6 +864,8 @@ Content-Typemultipart/form-data
}
```
### 获取群员资料
使用此方法获取群员资料

View File

@ -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)

View File

@ -18,6 +18,7 @@ import net.mamoe.mirai.api.http.AuthedSession
import net.mamoe.mirai.api.http.SessionManager
import net.mamoe.mirai.api.http.data.NoSuchBotException
import net.mamoe.mirai.api.http.data.StateCode
import net.mamoe.mirai.api.http.data.common.DTO
import net.mamoe.mirai.api.http.data.common.VerifyDTO
import kotlin.coroutines.EmptyCoroutineContext
@ -28,7 +29,7 @@ fun Application.authModule() {
if (it.authKey != SessionManager.authKey) {
call.respondStateCode(StateCode(1, "Auth Key错误"))
} else {
call.respondStateCode(StateCode(0, SessionManager.createTempSession().key))
call.respondDTO(AuthRetDTO(0, SessionManager.createTempSession().key))
}
}
@ -55,6 +56,9 @@ fun Application.authModule() {
}
}
@Serializable
private data class AuthRetDTO(val code: Int, val session: String) : DTO
@Serializable
private data class BindDTO(override val sessionKey: String, val qq: Long) : VerifyDTO()

View File

@ -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)
}

View File

@ -1,15 +1,10 @@
package net.mamoe.mirai.console.graphical
import com.jfoenix.controls.JFXDecorator
import javafx.scene.control.Button
import javafx.stage.Stage
import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
import net.mamoe.mirai.console.graphical.styleSheet.PrimaryStyleSheet
import net.mamoe.mirai.console.graphical.view.Decorator
import net.mamoe.mirai.console.graphical.view.PrimaryView
import tornadofx.App
import tornadofx.FX.Companion.primaryStage
import tornadofx.UIComponent
import tornadofx.find
import tornadofx.launch
@ -17,7 +12,7 @@ fun main(args: Array<String>) {
launch<MiraiGraphicalUI>(args)
}
class MiraiGraphicalUI: App(Decorator::class) {
class MiraiGraphicalUI : App(Decorator::class, PrimaryStyleSheet::class) {
override fun init() {
super.init()
@ -29,4 +24,4 @@ class MiraiGraphicalUI: App(Decorator::class) {
super.stop()
MiraiConsole.stop()
}
}
}

View File

@ -0,0 +1,21 @@
package net.mamoe.mirai.console.graphical.styleSheet
import tornadofx.*
class PrimaryStyleSheet : Stylesheet() {
companion object {
val jfxTitle by cssclass("jfx-decorator-buttons-container")
val container by cssclass("jfx-decorator-content-container")
}
init {
jfxTitle {
backgroundColor += c("00BCD4")
}
container {
borderColor += box(c("00BCD4"))
borderWidth += box(0.px, 4.px, 4.px, 4.px)
}
}
}