Remove parameter title of Announcement

This commit is contained in:
Him188 2021-07-05 14:59:55 +08:00
parent 4a2b510a70
commit b319e2bc5c
6 changed files with 34 additions and 51 deletions

View File

@ -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] 构建获得.

View File

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

View File

@ -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<OfflineAnnouncement> by OfflineAnnouncementImpl.serializer().map(
resultantDescriptor = OfflineAnnouncementImpl.serializer().descriptor.copy(SERIAL_NAME),
deserialize = { it },
serialize = { it.safeCast<OfflineAnnouncementImpl>() ?: create(title, body, parameters).cast() }
serialize = { it.safeCast<OfflineAnnouncementImpl>() ?: 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)"
}

View File

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

View File

@ -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<DeserializationFailure, GroupAnnouncementList> = bot.asQQAndroidBot().run {
return bot.asQQAndroidBot().network.run {
Mirai.Http.post<String> {
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<DeserializationFailure, GroupAnnouncementList> {
return Mirai.Http.post<String> {
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

View File

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