mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 02:20:14 +08:00
delete announcement
This commit is contained in:
parent
e57215a603
commit
4e7b3b0048
@ -21,6 +21,7 @@ import kotlinx.serialization.MissingFieldException
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonConfiguration
|
import kotlinx.serialization.json.JsonConfiguration
|
||||||
import kotlinx.serialization.json.int
|
import kotlinx.serialization.json.int
|
||||||
|
import kotlinx.serialization.json.long
|
||||||
import net.mamoe.mirai.LowLevelAPI
|
import net.mamoe.mirai.LowLevelAPI
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
import net.mamoe.mirai.data.*
|
import net.mamoe.mirai.data.*
|
||||||
@ -600,9 +601,9 @@ internal class GroupImpl(
|
|||||||
|
|
||||||
|
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
override suspend fun sendAnnouncement(announcement: GroupAnnouncement) {
|
override suspend fun sendAnnouncement(announcement: GroupAnnouncement): String {
|
||||||
val json = Json(JsonConfiguration.Stable)
|
val json = Json(JsonConfiguration.Stable)
|
||||||
bot.network.launch {
|
val rep = bot.network.async {
|
||||||
HttpClient().post<String> {
|
HttpClient().post<String> {
|
||||||
url("https://web.qun.qq.com/cgi-bin/announce/add_qun_notice")
|
url("https://web.qun.qq.com/cgi-bin/announce/add_qun_notice")
|
||||||
body = MultiPartFormDataContent(formData {
|
body = MultiPartFormDataContent(formData {
|
||||||
@ -610,7 +611,13 @@ internal class GroupImpl(
|
|||||||
append("bkn", getBkn())
|
append("bkn", getBkn())
|
||||||
append("text", announcement.msg.text)
|
append("text", announcement.msg.text)
|
||||||
append("pinned", announcement.pinned)
|
append("pinned", announcement.pinned)
|
||||||
append("settings", json.stringify(GroupAnnouncementSettings.serializer(), announcement.settings?:GroupAnnouncementSettings()))
|
append(
|
||||||
|
"settings",
|
||||||
|
json.stringify(
|
||||||
|
GroupAnnouncementSettings.serializer(),
|
||||||
|
announcement.settings ?: GroupAnnouncementSettings()
|
||||||
|
)
|
||||||
|
)
|
||||||
append("format", "json")
|
append("format", "json")
|
||||||
})
|
})
|
||||||
headers {
|
headers {
|
||||||
@ -622,13 +629,41 @@ internal class GroupImpl(
|
|||||||
" p_skey=${bot.client.wLoginSigInfo.psKeyMap["qun.qq.com"]?.data?.encodeToString()}; "
|
" p_skey=${bot.client.wLoginSigInfo.psKeyMap["qun.qq.com"]?.data?.encodeToString()}; "
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.also {
|
}
|
||||||
val jsonObj = json.parseJson(it)
|
}
|
||||||
if (jsonObj.jsonObject["ec"]?.int ?:1 != 0){
|
val jsonObj = json.parseJson(rep.await())
|
||||||
throw IllegalStateException("Send Announcement fail group:$id msg:${jsonObj.jsonObject["em"]} content:${announcement.msg.text}")
|
return jsonObj.jsonObject["new_fid"]?.primitive?.content
|
||||||
|
?: throw throw IllegalStateException("Send Announcement fail group:$id msg:${jsonObj.jsonObject["em"]} content:${announcement.msg.text}")
|
||||||
|
}
|
||||||
|
|
||||||
|
@MiraiExperimentalAPI
|
||||||
|
override suspend fun deleteAnnouncement(fid: String) {
|
||||||
|
val json = Json(JsonConfiguration.Stable)
|
||||||
|
val rep = bot.network.async {
|
||||||
|
HttpClient().post<String> {
|
||||||
|
url("https://web.qun.qq.com/cgi-bin/announce/del_feed")
|
||||||
|
body = MultiPartFormDataContent(formData {
|
||||||
|
append("qid", id)
|
||||||
|
append("bkn", getBkn())
|
||||||
|
append("fid", fid)
|
||||||
|
append("format", "json")
|
||||||
|
})
|
||||||
|
headers {
|
||||||
|
append(
|
||||||
|
"cookie",
|
||||||
|
"uin=o${bot.selfQQ.id};" +
|
||||||
|
" skey=${bot.client.wLoginSigInfo.sKey.data.encodeToString()};" +
|
||||||
|
" p_uin=o${bot.selfQQ.id};" +
|
||||||
|
" p_skey=${bot.client.wLoginSigInfo.psKeyMap["qun.qq.com"]?.data?.encodeToString()}; "
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val data = rep.await()
|
||||||
|
val jsonObj = json.parseJson(data)
|
||||||
|
if (jsonObj.jsonObject["ec"]?.int ?: 1 != 0){
|
||||||
|
throw throw IllegalStateException("delete Announcement fail group:$id msg:${jsonObj.jsonObject["em"]} fid:$fid")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(MiraiExperimentalAPI::class)
|
@OptIn(MiraiExperimentalAPI::class)
|
||||||
|
@ -158,14 +158,23 @@ expect abstract class Group() : Contact, CoroutineScope {
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
abstract suspend fun getAnnouncements(page: Int = 1, amount: Int = 10):GroupAnnouncementList?
|
abstract suspend fun getAnnouncements(page: Int = 1, amount: Int = 10): GroupAnnouncementList?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送群公告
|
* 发送群公告
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
abstract suspend fun sendAnnouncement(announcement: GroupAnnouncement)
|
abstract suspend fun sendAnnouncement(announcement: GroupAnnouncement): String
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除群公告
|
||||||
|
* fid可以通过发送公告的返回值得到或者获取列表得到
|
||||||
|
* */
|
||||||
|
|
||||||
|
@MiraiExperimentalAPI
|
||||||
|
abstract suspend fun deleteAnnouncement(fid: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
|
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
|
||||||
|
@ -26,7 +26,8 @@ data class GroupAnnouncement(
|
|||||||
@SerialName("pubt") val time: Long = 0,
|
@SerialName("pubt") val time: Long = 0,
|
||||||
@SerialName("read_num") val readNum: Int = 0,
|
@SerialName("read_num") val readNum: Int = 0,
|
||||||
@SerialName("is_read") val isRead: Int = 0,
|
@SerialName("is_read") val isRead: Int = 0,
|
||||||
val pinned: Int = 0
|
val pinned: Int = 0,
|
||||||
|
val fid:String? = null //公告的id
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -156,12 +156,18 @@ actual abstract class Group : Contact(), CoroutineScope {
|
|||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
actual suspend abstract fun getAnnouncements(page: Int, amount: Int): GroupAnnouncementList?
|
actual suspend abstract fun getAnnouncements(page: Int, amount: Int): GroupAnnouncementList?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除群公告
|
||||||
|
* fid可以通过发送公告的返回值得到或者获取列表得到
|
||||||
|
* */
|
||||||
|
@MiraiExperimentalAPI
|
||||||
|
actual abstract suspend fun deleteAnnouncement(fid: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送群公告
|
* 发送群公告
|
||||||
* */
|
* */
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
actual suspend abstract fun sendAnnouncement(announcement: GroupAnnouncement)
|
actual suspend abstract fun sendAnnouncement(announcement: GroupAnnouncement):String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查此 id 的群成员是否存在
|
* 检查此 id 的群成员是否存在
|
||||||
|
Loading…
Reference in New Issue
Block a user