mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 22:30:47 +08:00
get group announce list
This commit is contained in:
parent
27194cba91
commit
220d293b7a
@ -72,6 +72,11 @@ kotlin {
|
||||
api(kotlinx("io", kotlinXIoVersion))
|
||||
api(kotlinx("coroutines-io", coroutinesIoVersion))
|
||||
api(kotlinx("coroutines-core", coroutinesVersion))
|
||||
|
||||
api(ktor("client-core", ktorVersion))
|
||||
|
||||
implementation(ktor("client-json",ktorVersion))
|
||||
implementation(ktor("client-serialization",ktorVersion))
|
||||
}
|
||||
}
|
||||
commonMain {
|
||||
@ -110,6 +115,7 @@ kotlin {
|
||||
runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
|
||||
api(kotlinx("serialization-runtime", serializationVersion))
|
||||
//api(kotlinx("serialization-protobuf", serializationVersion))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,12 @@
|
||||
|
||||
package net.mamoe.mirai.qqandroid
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.features.json.JsonFeature
|
||||
import io.ktor.client.features.json.serializer.KotlinxSerializer
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.formData
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import kotlinx.io.core.Closeable
|
||||
@ -35,6 +41,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.image.LongConn
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
|
||||
import net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
|
||||
import net.mamoe.mirai.utils.*
|
||||
import net.mamoe.mirai.utils.io.encodeToString
|
||||
import net.mamoe.mirai.utils.io.toUHexString
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
@ -559,6 +566,29 @@ internal class GroupImpl(
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
override suspend fun getAnnouncements(page: Int, amount: Int): GroupAnnouncementList {
|
||||
val data = bot.network.async {
|
||||
HttpClient { install(JsonFeature) { serializer = KotlinxSerializer() } }.post<GroupAnnouncementList> {
|
||||
url("https://web.qun.qq.com/cgi-bin/announce/list_announce")
|
||||
formData {
|
||||
append("qid", id)
|
||||
append("bkn", getBkn())
|
||||
append("ft", 23) //好像是一个用来识别应用的参数
|
||||
append("s", -page) // 第一页这里的参数应该是-1
|
||||
append("n", amount)
|
||||
append("format", "json")
|
||||
}
|
||||
header(
|
||||
"cookie",
|
||||
"uin=o${bot.selfQQ.id}; skey=${bot.client.wLoginSigInfo.sKey.data.encodeToString()}; p_uin=o${bot.selfQQ.id};"
|
||||
)
|
||||
}
|
||||
}
|
||||
return data.await()
|
||||
}
|
||||
|
||||
|
||||
@OptIn(MiraiExperimentalAPI::class)
|
||||
override fun Member(memberInfo: MemberInfo): Member {
|
||||
return MemberImpl(
|
||||
@ -719,4 +749,16 @@ internal class GroupImpl(
|
||||
if (this::class != other::class) return false
|
||||
return this.id == other.id && this.bot == other.bot
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取 获取群公告 所需的bkn参数
|
||||
* */
|
||||
fun getBkn(): Int {
|
||||
val str = bot.client.wLoginSigInfo.sKey.data.encodeToString()
|
||||
var magic = 5381
|
||||
for (i in str) {
|
||||
magic += magic.shl(5) + i.toInt()
|
||||
}
|
||||
return Int.MAX_VALUE.and(magic)
|
||||
}
|
||||
}
|
@ -602,6 +602,7 @@ internal class WtLogin {
|
||||
userA5 = UserA5(tlvMap119.getOrEmpty(0x10b), creationTime),
|
||||
userA8 = UserA8(tlvMap119.getOrEmpty(0x102), creationTime, expireTime)
|
||||
)
|
||||
//bot.network.logger.error(client.wLoginSigInfo.sKey.data.encodeToString())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,11 @@
|
||||
package net.mamoe.mirai.contact
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.SerialInfo
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.data.GroupAnnouncementList
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.event.events.MessageSendEvent.FriendMessageSendEvent
|
||||
@ -148,6 +152,13 @@ expect abstract class Group() : Contact, CoroutineScope {
|
||||
*/
|
||||
abstract operator fun contains(id: Long): Boolean
|
||||
|
||||
/**
|
||||
* 获取群公告列表
|
||||
*
|
||||
* */
|
||||
@MiraiExperimentalAPI
|
||||
abstract suspend fun getAnnouncements(page: Int = 1, amount: Int = 10):GroupAnnouncementList
|
||||
|
||||
/**
|
||||
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
|
||||
*/
|
||||
|
@ -0,0 +1,36 @@
|
||||
package net.mamoe.mirai.data
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* 群公告数据类
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Serializable
|
||||
data class GroupAnnouncementList(
|
||||
val feeds: List<GroupAnnouncement>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupAnnouncement(
|
||||
@SerialName("u") val sender: Long,
|
||||
val msg: GroupAnnouncementMsg,
|
||||
val settings: GroupAnnouncementSettings
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupAnnouncementMsg(
|
||||
val text: String,
|
||||
val text_face: String,
|
||||
val title: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupAnnouncementSettings(
|
||||
@SerialName("is_show_edit_card") val isShowEditCard: Int,
|
||||
@SerialName("remind_ts") val remindTs: Int,
|
||||
@SerialName("tip_window_type") val tipWindowType: Int,
|
||||
@SerialName("confirm_required") val confirmRequired: Int
|
||||
)
|
@ -11,6 +11,7 @@ package net.mamoe.mirai.contact
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.data.GroupAnnouncementList
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.event.events.MessageSendEvent.FriendMessageSendEvent
|
||||
@ -146,6 +147,14 @@ actual abstract class Group : Contact(), CoroutineScope {
|
||||
*/
|
||||
actual abstract fun getOrNull(id: Long): Member?
|
||||
|
||||
|
||||
/**
|
||||
* 获取群公告列表
|
||||
*
|
||||
* */
|
||||
@MiraiExperimentalAPI
|
||||
actual suspend abstract fun getAnnouncements(page: Int, amount: Int ):GroupAnnouncementList
|
||||
|
||||
/**
|
||||
* 检查此 id 的群成员是否存在
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user