diff --git a/CHANGELOG.md b/CHANGELOG.md index 408943426..e94d4b1e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/README.md b/README.md index 90d5c0417..bd8ccdcc1 100644 --- a/README.md +++ b/README.md @@ -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 开发插件 diff --git a/build.gradle.kts b/build.gradle.kts index 00b75dffe..fad5f5f46 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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() diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index a0b4b2f9b..1eec74a84 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,6 +3,7 @@ plugins { } repositories { + mavenLocal() jcenter() } diff --git a/docs/mirai.md b/docs/mirai.md index 6b04124f5..1ee200412 100644 --- a/docs/mirai.md +++ b/docs/mirai.md @@ -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` diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt index f6a416898..4fbdd140c 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt @@ -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 { + val event = MessageSendEvent.TempMessageSendEvent(this, message.asMessageChain()).broadcast() + if (event.isCancelled) { + throw EventCancelledException("cancelled by TempMessageSendEvent") + } + event.message.firstIsInstanceOrNull()?.source?.ensureSequenceIdAvailable() + lateinit var source: MessageSourceToTempImpl bot.network.run { check( diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/friend.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/friend.kt index fa4d5286f..09e622bd8 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/friend.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/friend.kt @@ -54,7 +54,7 @@ data class FriendDeleteEvent( * 一个账号请求添加机器人为好友的事件 */ @Suppress("DEPRECATION") -data class NewFriendRequestEvent( +data class NewFriendRequestEvent internal constructor( override val bot: Bot, /** * 事件唯一识别号 diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt index 0fc0e01e6..7aca80aa4 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt @@ -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 } /** diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt index 89597d4ca..ede07913d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt @@ -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 = "" + ) } diff --git a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/message/SubscribingGetTest.kt b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/message/SubscribingGetTest.kt index 1b17efdd1..9198dfd04 100644 --- a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/message/SubscribingGetTest.kt +++ b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/message/SubscribingGetTest.kt @@ -21,23 +21,6 @@ import kotlin.test.assertFailsWith internal class SubscribingGetTest { - @Test - fun testSyncFromEvent() { - runBlockingWithTimeout(30_000) { - suspendCancellableCoroutine { cont -> - launch { - syncFromEvent(20_000) { _: TestEvent -> - cont.resume(Unit) - } - } - launch { - delay(5_000) - TestEvent().broadcast() - } - } - } - } - @Test fun testSyncFromEventTimeout() { runBlockingWithTimeout(500) {