From ca213c19aaeacf108c9f3543513c9988b495f4f8 Mon Sep 17 00:00:00 2001 From: StageGuard <1355416608@qq.com> Date: Wed, 21 Jun 2023 19:13:14 +0800 Subject: [PATCH] add friend relation change events --- docs/api/EventType.md | 43 +++++++++++++++++++ .../http/adapter/internal/convertor/event.kt | 3 ++ .../api/http/adapter/internal/dto/event.kt | 13 ++++++ 3 files changed, 59 insertions(+) diff --git a/docs/api/EventType.md b/docs/api/EventType.md index 3046b65d..6ed271c2 100644 --- a/docs/api/EventType.md +++ b/docs/api/EventType.md @@ -145,6 +145,49 @@ +### 添加好友 + +```json5 +{ + "type": "FriendAddEvent", + "friend": { + "id": 123123, + "nickname": "nick", + "remark": "remark" + }, + "stranger": true +} +``` + +| 名字 | 类型 | 说明 | +|----------| ------ |-------------------------------------------------------------------------------| +| id | Long | 好友 QQ 号码 | +| nickname | String | 好友昵称(值不确定) | +| remark | String | 好友备注 | +| stranger | String | 是否为陌生人添加,若为 `true` 对应为 `StrangerRelationChangeEvent.Friended` 的 mirai 事件,否则为 `FriendAddEvent` | + + +### 好友删除 + +```json5 +{ + "type": "FriendDeleteEvent", + "friend": { + "id": 123123, + "nickname": "nick", + "remark": "remark" + } +} +``` + +| 名字 | 类型 | 说明 | +| ---------------- | ------ | --------------------------------------------- | +| id | Long | 好友 QQ 号码 | +| nickname | String | 好友昵称(值不确定) | +| remark | String | 好友备注 | + + + ## 群事件 diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/convertor/event.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/convertor/event.kt index e1f6a97a..4a193833 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/convertor/event.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/convertor/event.kt @@ -121,6 +121,9 @@ internal suspend fun BotEvent.convertBotEvent() = when (this) { member = if (sender.user != null && sender.user is Member) { MemberDTO(sender.user as Member) } else { null }, args = args.toDTO { it != UnknownMessageDTO } ) + is FriendAddEvent -> FriendAddEventDTO(QQDTO(friend), false) + is FriendDeleteEvent -> FriendDeleteEventDTO(QQDTO(friend)) + is StrangerRelationChangeEvent.Friended -> FriendAddEventDTO(QQDTO(friend), true) else -> { if(MahContextHolder.debug) { MahContextHolder.debugLog.debug { "Unknown event: ${this.javaClass.simpleName}" } diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/dto/event.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/dto/event.kt index 1490725f..63a422de 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/dto/event.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/dto/event.kt @@ -268,6 +268,19 @@ internal data class FriendInputStatusChangedEventDTO( val inputting: Boolean, ) : BotEventDTO() +@Serializable +@SerialName("FriendAddEvent") +internal data class FriendAddEventDTO( + val friend: QQDTO, + val stranger: Boolean +) : BotEventDTO() + +@Serializable +@SerialName("FriendDeleteEvent") +internal data class FriendDeleteEventDTO( + val friend: QQDTO +) : BotEventDTO() + @Serializable @SerialName("FriendNickChangedEvent") internal data class FriendNickChangedEventDTO(