diff --git a/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcement.kt b/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcement.kt index 251835617..da9614735 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcement.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcement.kt @@ -24,15 +24,10 @@ import net.mamoe.mirai.contact.Group * @since 2.7 */ public sealed interface Announcement { - /** - * 标题 - */ - public val title: String - /** * 内容 */ - public val body: String + public val content: String /** * 附加参数. 可以通过 [AnnouncementParametersBuilder] 构建获得. diff --git a/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcements.kt b/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcements.kt index 8c093ad9e..92b037d20 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcements.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/announcement/Announcements.kt @@ -15,6 +15,7 @@ package net.mamoe.mirai.contact.announcement import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.toList import net.mamoe.kjbb.JvmBlockingBridge +import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.PermissionDeniedException import net.mamoe.mirai.utils.ExternalResource import net.mamoe.mirai.utils.NotStableForInheritance diff --git a/mirai-core-api/src/commonMain/kotlin/contact/announcement/OfflineAnnouncement.kt b/mirai-core-api/src/commonMain/kotlin/contact/announcement/OfflineAnnouncement.kt index afe1ead40..b30769c66 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/announcement/OfflineAnnouncement.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/announcement/OfflineAnnouncement.kt @@ -36,39 +36,35 @@ public sealed interface OfflineAnnouncement : Announcement { */ @JvmStatic public inline fun from(announcement: Announcement): OfflineAnnouncement = - announcement.safeCast() ?: announcement.run { create(title, body, parameters) } + announcement.safeCast() ?: announcement.run { create(content, parameters) } /** * 创建 [OfflineAnnouncement]. - * @param title 标题 - * @param body 公告内容 + * @param content 公告内容 * @param parameters 附加参数 */ @JvmStatic public fun create( - title: String, - body: String, + content: String, parameters: AnnouncementParameters = AnnouncementParameters.DEFAULT - ): OfflineAnnouncement = OfflineAnnouncementImpl(title, body, parameters) + ): OfflineAnnouncement = OfflineAnnouncementImpl(content, parameters) /** * 创建 [AnnouncementParameters] 并创建 [OfflineAnnouncement]. - * @param title 标题 - * @param body 公告内容 + * @param content 公告内容 * @param parameters 附加参数 * @see AnnouncementParametersBuilder - * */ + */ @JvmStatic public inline fun create( - title: String, - body: String, + content: String, parameters: AnnouncementParametersBuilder.() -> Unit - ): OfflineAnnouncement = create(title, body, buildAnnouncementParameters(parameters)) + ): OfflineAnnouncement = create(content, buildAnnouncementParameters(parameters)) internal object Serializer : KSerializer by OfflineAnnouncementImpl.serializer().map( resultantDescriptor = OfflineAnnouncementImpl.serializer().descriptor.copy(SERIAL_NAME), deserialize = { it }, - serialize = { it.safeCast() ?: create(title, body, parameters).cast() } + serialize = { it.safeCast() ?: create(content, parameters).cast() } ) } } @@ -76,9 +72,8 @@ public sealed interface OfflineAnnouncement : Announcement { @SerialName(OfflineAnnouncement.SERIAL_NAME) @Serializable private data class OfflineAnnouncementImpl( - override val title: String, - override val body: String, + override val content: String, override val parameters: AnnouncementParameters ) : OfflineAnnouncement { - override fun toString() = "OfflineAnnouncement(title='$title', body='$body', parameters=$parameters)" + override fun toString() = "OfflineAnnouncement(body='$content', parameters=$parameters)" } \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/contact/OnlineAnnouncementImpl.kt b/mirai-core/src/commonMain/kotlin/contact/OnlineAnnouncementImpl.kt index 9567aefe1..8fb901abd 100644 --- a/mirai-core/src/commonMain/kotlin/contact/OnlineAnnouncementImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/OnlineAnnouncementImpl.kt @@ -21,12 +21,11 @@ import net.mamoe.mirai.contact.announcement.OnlineAnnouncement */ //@SerialName(OnlineAnnouncementImpl.SERIAL_NAME) //@Serializable(OnlineAnnouncementImpl.Serializer::class) -internal class OnlineAnnouncementImpl constructor( +internal class OnlineAnnouncementImpl( override val group: Group, override val senderId: Long, override val sender: NormalMember?, - override val title: String, - override val body: String, + override val content: String, override val parameters: AnnouncementParameters, override val fid: String, override val isAllRead: Boolean, diff --git a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt index 94b6654fa..e7e0f1bf9 100644 --- a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt @@ -93,8 +93,7 @@ internal class AnnouncementsImpl( group = group, senderId = bot.id, sender = group.botAsMember, - title = title, - body = body, + content = content, parameters = parameters, fid = fid, isAllRead = false, @@ -181,26 +180,24 @@ internal object AnnouncementProtocol { } suspend fun getRawGroupAnnouncements( - bot: Bot, + bot: QQAndroidBot, groupId: Long, page: Int, amount: Int = 10 - ): Either = bot.asQQAndroidBot().run { - return bot.asQQAndroidBot().network.run { - Mirai.Http.post { - url("https://web.qun.qq.com/cgi-bin/announce/list_announce") - body = MultiPartFormDataContent(formData { - append("qid", groupId) - append("bkn", bot.bkn) - append("ft", 23) //好像是一个用来识别应用的参数 - append("s", if (page == 1) 0 else -(page * amount + 1)) // 第一页这里的参数应该是-1 - append("n", amount) - append("ni", if (page == 1) 1 else 0) - append("format", "json") - }) - cookie("uin", "o${bot.id}") - cookie("skey", sKey) - } + ): Either { + return Mirai.Http.post { + url("https://web.qun.qq.com/cgi-bin/announce/list_announce") + body = MultiPartFormDataContent(formData { + append("qid", groupId) + append("bkn", bot.bkn) + append("ft", 23) //好像是一个用来识别应用的参数 + append("s", if (page == 1) 0 else -(page * amount + 1)) // 第一页这里的参数应该是-1 + append("n", amount) + append("ni", if (page == 1) 1 else 0) + append("format", "json") + }) + cookie("uin", "o${bot.id}") + cookie("skey", bot.sKey) }.loadSafelyAs(GroupAnnouncementList.serializer()) } @@ -245,10 +242,7 @@ internal object AnnouncementProtocol { fun Announcement.toGroupAnnouncement(senderId: Long): GroupAnnouncement { return GroupAnnouncement( sender = senderId, - msg = GroupAnnouncementMsg( - title = title, - text = body - ), + msg = GroupAnnouncementMsg(text = content), type = if (parameters.sendToNewMember) 20 else 6, settings = GroupAnnouncementSettings( isShowEditCard = if (parameters.isShowEditCard) 1 else 0, @@ -266,8 +260,7 @@ internal object AnnouncementProtocol { group = group, senderId = sender, sender = group[sender], - title = msg.title ?: "", - body = msg.text, + content = msg.text, parameters = buildAnnouncementParameters { isPinned = pinned == 1 sendToNewMember = type == 20 diff --git a/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt b/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt index bb4437649..08f32cd23 100644 --- a/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt +++ b/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt @@ -63,7 +63,7 @@ internal class GroupAnnouncementImage @MiraiInternalApi constructor( internal data class GroupAnnouncementMsg( val text: String, val text_face: String? = null, - val title: String? = null +// val title: String? = null // no title any more )