mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9d0b30618c
@ -116,11 +116,13 @@
|
||||
弃用 (兼容到 `1.2.0`):
|
||||
- `MessagePacket`
|
||||
- `MessagePacketBase`
|
||||
|
||||
进行如下更名:
|
||||
- `ContactMessage` -> `MessageEvent`
|
||||
- `FriendMessage` -> `FriendMessageEvent`
|
||||
- `GroupMessage` -> `GroupMessageEvent`
|
||||
- `TempMessage` -> `TempMessageEvent`
|
||||
|
||||
暂未决定是否提供 `UserMessageEvent` 作为 `TempMessageEvent` 和 `FriendMessageEvent` 的公共父类.
|
||||
|
||||
- 优化扩展函数结构, 统一放置在 `MessageEventExtensions`, 以使 `MessageEvent` 结构清晰.
|
||||
@ -212,7 +214,7 @@
|
||||
|
||||
新架构为:
|
||||
- 弃用 `QQ` 命名 (二进制兼容到 1.0.0)
|
||||
- 新增 `User` 继承 `Contact`, 作为 `Member` 和 `Friend`
|
||||
- 新增 `User` 继承 `Contact`, 作为 `Member` 和 `Friend` 的父类
|
||||
- `Member` 继承 `User`
|
||||
- `Friend` 继承 `User`
|
||||
|
||||
|
@ -77,13 +77,9 @@ mirai 既可以作为项目中的 QQ 协议支持库, 也可以作为单独的
|
||||
|
||||
## 开始
|
||||
|
||||
[Mirai-core 1.0.0 Milestone](https://github.com/mamoe/mirai/milestone/2) 已经完成, mirai 正在进行进一步的稳定性和性能优化, 并计划发布第一个正式版本.
|
||||
|
||||
在 1.0.0 将会删除全部过时的 API, 目前的 API 也可能会改变.
|
||||
|
||||
### 开发者
|
||||
|
||||
**阅读文档**: [docs/mirai.md](docs/mirai.md)
|
||||
#### **开发文档**: [docs/mirai.md](docs/mirai.md)
|
||||
|
||||
#### 使用 mirai 作为服务器,为 mirai 开发插件
|
||||
|
||||
|
@ -56,6 +56,7 @@ allprojects {
|
||||
version = Versions.Mirai.version
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
// maven(url = "https://mirrors.huaweicloud.com/repository/maven")
|
||||
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
jcenter()
|
||||
|
@ -3,6 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# mirai
|
||||
欢迎来到 mirai 文档.
|
||||
|
||||
本文档基于 mirai 1.0-RC2-1, 最后修改时间为 2020/5/16
|
||||
本文档基于 mirai 1.0.0, 最后修改时间为 2020/5/22
|
||||
|
||||
## 声明
|
||||
1. mirai 为完全免费的开源项目,使用 AGPLv3 开源协议. mirai 项目维护者和贡献者 (下文简称 '我们') 不通过任何方式收取费用。所有人都可以免费获取并使用这个项目。
|
||||
@ -31,18 +31,17 @@ mirai 项目整体由 核心 (`mirai-core`) 与 控制台(`mirai-console`) 组
|
||||
|
||||
|
||||
- [`mirai-console`](https://github.com/mamoe/mirai-console) 是基于 `mirai-core` 的, 支持插件加载, 指令系统, 和配置等的**控制台框架**.
|
||||
**注意: 此模块正在重写, 短时间内可能不可用**
|
||||
**注意: 此模块正在重写, 短时间内不可用**
|
||||
console 由 '后端' 和 '前端' 组成.
|
||||
`mirai-console` 即为后端, 包含所有开发时需要用到的功能.
|
||||
可用的前端:
|
||||
- 纯命令行: `mirai-console` 内置纯命令行前端.
|
||||
- 基于 JavaFX 的图形端: [`mirai-console-graphical`](https://github.com/mamoe/mirai-console/tree/master/mirai-console-graphical)
|
||||
- Unix 友好的终端: [`mirai-console-terminal`](https://github.com/mamoe/mirai-console/tree/master/mirai-console-terminal)
|
||||
|
||||
- [`MiraiAndroid`](https://github.com/mzdluo123/MiraiAndroid) 是`mirai-console`的Android前端程序,支持大部分mirai-console功能以及多种脚本api
|
||||
[`backend/mirai-console`](https://github.com/mamoe/mirai-console/tree/reborn/backend/mirai-console) 为唯一的后端, 包含所有开发时需要用到的功能.
|
||||
可用的官方(由 mirai 所属 [mamoe](https://github.com/mamoe) 组成员维护)前端:
|
||||
- 纯命令行: [`frontend/mirai-console-pure`](https://github.com/mamoe/mirai-console/tree/reborn/frontend/mirai-console-pure)
|
||||
- 基于 JavaFX 的图形端: [`frontend/mirai-console-graphical`](https://github.com/mamoe/mirai-console/tree/reborn/frontend/mirai-console-graphical)
|
||||
- Unix 友好的终端: [`frontend/mirai-console-terminal`](https://github.com/mamoe/mirai-console/tree/reborn/frontend/mirai-console-terminal)
|
||||
- Android APP: [`MiraiAndroid`](https://github.com/mzdluo123/MiraiAndroid) 额外支持多种脚本 API
|
||||
|
||||
|
||||
**注意**: `mirai-core` (将)于 2020 年 6 月发布的 `1.0.0` 版本正式进入稳定更新阶段,
|
||||
**注意**: `mirai-core` 于 2020 年 5 月发布的 `1.0.0` 版本正式进入稳定更新阶段,
|
||||
**而 `mirai-console` 仍处于快速迭代阶段, 任何 API 都有可能在不经过警告的情况下改动, 任何 API 都不具有任何稳定性.**
|
||||
|
||||
## `mirai-core`
|
||||
|
@ -18,16 +18,13 @@ import net.mamoe.mirai.LowLevelAPI
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.event.broadcast
|
||||
import net.mamoe.mirai.event.events.MemberCardChangeEvent
|
||||
import net.mamoe.mirai.event.events.MemberLeaveEvent
|
||||
import net.mamoe.mirai.event.events.MemberSpecialTitleChangeEvent
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.asMessageChain
|
||||
import net.mamoe.mirai.message.data.isContentNotEmpty
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.qqandroid.QQAndroidBot
|
||||
import net.mamoe.mirai.qqandroid.message.MessageSourceToTempImpl
|
||||
import net.mamoe.mirai.qqandroid.message.ensureSequenceIdAvailable
|
||||
import net.mamoe.mirai.qqandroid.message.firstIsInstanceOrNull
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.jce.StTroopMemberInfo
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.TroopManagement
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvcPbSendMsg
|
||||
@ -66,6 +63,12 @@ internal class MemberImpl constructor(
|
||||
}
|
||||
|
||||
private suspend fun sendMessageImpl(message: Message): MessageReceipt<Member> {
|
||||
val event = MessageSendEvent.TempMessageSendEvent(this, message.asMessageChain()).broadcast()
|
||||
if (event.isCancelled) {
|
||||
throw EventCancelledException("cancelled by TempMessageSendEvent")
|
||||
}
|
||||
event.message.firstIsInstanceOrNull<QuoteReply>()?.source?.ensureSequenceIdAvailable()
|
||||
|
||||
lateinit var source: MessageSourceToTempImpl
|
||||
bot.network.run {
|
||||
check(
|
||||
|
@ -54,7 +54,7 @@ data class FriendDeleteEvent(
|
||||
* 一个账号请求添加机器人为好友的事件
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
data class NewFriendRequestEvent(
|
||||
data class NewFriendRequestEvent internal constructor(
|
||||
override val bot: Bot,
|
||||
/**
|
||||
* 事件唯一识别号
|
||||
|
@ -46,7 +46,10 @@ sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractEvent() {
|
||||
var message: MessageChain
|
||||
) : MessageSendEvent(), CancellableEvent
|
||||
|
||||
// TODO: 2020/4/30 添加临时会话消息发送事件
|
||||
data class TempMessageSendEvent(
|
||||
override val target: Member,
|
||||
var message: MessageChain
|
||||
) : MessageSendEvent(), CancellableEvent
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ import kotlinx.coroutines.Job
|
||||
import net.mamoe.mirai.contact.Friend
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.data.*
|
||||
import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent
|
||||
import net.mamoe.mirai.event.events.MemberJoinRequestEvent
|
||||
import net.mamoe.mirai.event.events.NewFriendRequestEvent
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.WeakRef
|
||||
|
||||
@ -113,4 +116,60 @@ interface LowLevelBotAPIAccessor {
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
suspend fun _lowLevelGetGroupActiveData(groupId: Long): GroupActiveData
|
||||
|
||||
|
||||
/**
|
||||
* 构造一个账号请求添加机器人为好友的事件
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
fun _lowLevelGetNewFriendRequestEvent(
|
||||
eventId: Long,
|
||||
fromId: Long,
|
||||
groupId: Long
|
||||
) = NewFriendRequestEvent(
|
||||
bot = this as Bot,
|
||||
eventId = eventId,
|
||||
message = "",
|
||||
fromId = fromId,
|
||||
fromGroupId = groupId,
|
||||
fromNick = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* 构造被邀请加入一个群请求事件
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
fun _lowLevelGetBotInvitedJoinGroupRequestEvent(
|
||||
eventId: Long,
|
||||
groupId: Long,
|
||||
invitorId: Long
|
||||
) = BotInvitedJoinGroupRequestEvent(
|
||||
bot = this as Bot,
|
||||
eventId = eventId,
|
||||
invitorId = invitorId,
|
||||
groupId = groupId,
|
||||
groupName = "",
|
||||
invitorNick = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* 构造账号请求加入群事件
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
fun _lowLevelGetMemberJoinRequestEvent(
|
||||
eventId: Long,
|
||||
groupId: Long,
|
||||
fromId: Long
|
||||
) = MemberJoinRequestEvent(
|
||||
bot = this as Bot,
|
||||
eventId = eventId,
|
||||
fromId = fromId,
|
||||
groupId = groupId,
|
||||
groupName = "",
|
||||
fromNick = "",
|
||||
message = ""
|
||||
)
|
||||
}
|
||||
|
@ -21,23 +21,6 @@ import kotlin.test.assertFailsWith
|
||||
|
||||
internal class SubscribingGetTest {
|
||||
|
||||
@Test
|
||||
fun testSyncFromEvent() {
|
||||
runBlockingWithTimeout(30_000) {
|
||||
suspendCancellableCoroutine<Unit> { cont ->
|
||||
launch {
|
||||
syncFromEvent(20_000) { _: TestEvent ->
|
||||
cont.resume(Unit)
|
||||
}
|
||||
}
|
||||
launch {
|
||||
delay(5_000)
|
||||
TestEvent().broadcast()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSyncFromEventTimeout() {
|
||||
runBlockingWithTimeout(500) {
|
||||
|
Loading…
Reference in New Issue
Block a user