mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 22:30:47 +08:00
send announcement
This commit is contained in:
parent
aa61e9441a
commit
e57215a603
@ -579,9 +579,9 @@ internal class GroupImpl(
|
||||
append("qid", id)
|
||||
append("bkn", getBkn())
|
||||
append("ft", 23) //好像是一个用来识别应用的参数
|
||||
append("s", if (page ==1) 0 else -(page*amount+1)) // 第一页这里的参数应该是-1
|
||||
append("s", if (page == 1) 0 else -(page * amount + 1)) // 第一页这里的参数应该是-1
|
||||
append("n", amount)
|
||||
append("ni",if (page ==1) 1 else 0)
|
||||
append("ni", if (page == 1) 1 else 0)
|
||||
append("format", "json")
|
||||
})
|
||||
headers {
|
||||
@ -594,12 +594,43 @@ internal class GroupImpl(
|
||||
}
|
||||
|
||||
val rep = data.await()
|
||||
bot.network.logger.error(rep)
|
||||
|
||||
return json.parse(GroupAnnouncementList.serializer(), rep)
|
||||
// bot.network.logger.error(rep)
|
||||
return json.parse(GroupAnnouncementList.serializer(), rep)
|
||||
}
|
||||
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
override suspend fun sendAnnouncement(announcement: GroupAnnouncement) {
|
||||
val json = Json(JsonConfiguration.Stable)
|
||||
bot.network.launch {
|
||||
HttpClient().post<String> {
|
||||
url("https://web.qun.qq.com/cgi-bin/announce/add_qun_notice")
|
||||
body = MultiPartFormDataContent(formData {
|
||||
append("qid", id)
|
||||
append("bkn", getBkn())
|
||||
append("text", announcement.msg.text)
|
||||
append("pinned", announcement.pinned)
|
||||
append("settings", json.stringify(GroupAnnouncementSettings.serializer(), announcement.settings?:GroupAnnouncementSettings()))
|
||||
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()}; "
|
||||
)
|
||||
}
|
||||
}.also {
|
||||
val jsonObj = json.parseJson(it)
|
||||
if (jsonObj.jsonObject["ec"]?.int ?:1 != 0){
|
||||
throw IllegalStateException("Send Announcement fail group:$id msg:${jsonObj.jsonObject["em"]} content:${announcement.msg.text}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(MiraiExperimentalAPI::class)
|
||||
override fun Member(memberInfo: MemberInfo): Member {
|
||||
return MemberImpl(
|
||||
@ -761,10 +792,10 @@ internal class GroupImpl(
|
||||
return this.id == other.id && this.bot == other.bot
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取 获取群公告 所需的bkn参数
|
||||
* */
|
||||
fun getBkn(): Int {
|
||||
/**
|
||||
* 获取 获取群公告 所需的bkn参数
|
||||
* */
|
||||
private fun getBkn(): Int {
|
||||
val str = bot.client.wLoginSigInfo.sKey.data.encodeToString()
|
||||
var magic = 5381
|
||||
for (i in str) {
|
||||
|
@ -602,7 +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())
|
||||
//bot.network.logger.error(client.wLoginSigInfo.psKeyMap["qun.qq.com"]?.data?.encodeToString())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import kotlinx.serialization.SerialInfo
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.data.GroupAnnouncement
|
||||
import net.mamoe.mirai.data.GroupAnnouncementList
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.event.events.*
|
||||
@ -159,6 +160,13 @@ expect abstract class Group() : Contact, CoroutineScope {
|
||||
@MiraiExperimentalAPI
|
||||
abstract suspend fun getAnnouncements(page: Int = 1, amount: Int = 10):GroupAnnouncementList?
|
||||
|
||||
/**
|
||||
* 发送群公告
|
||||
*
|
||||
* */
|
||||
@MiraiExperimentalAPI
|
||||
abstract suspend fun sendAnnouncement(announcement: GroupAnnouncement)
|
||||
|
||||
/**
|
||||
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
|
||||
*/
|
||||
|
@ -7,34 +7,39 @@ import kotlinx.serialization.Serializable
|
||||
* 群公告数据类
|
||||
* getGroupAnnouncementList时,如果page=1,那么你可以在inst里拿到一些置顶公告
|
||||
*
|
||||
* 发公告时只需要填写text,
|
||||
*
|
||||
*/
|
||||
@Serializable
|
||||
data class GroupAnnouncementList(
|
||||
val ec: Int, //状态码 0 是正常的
|
||||
@SerialName("em") val msg:String, //信息
|
||||
val feeds: List<GroupAnnouncement>?, //群公告列表
|
||||
val inst: List<GroupAnnouncement>? //置顶列表?
|
||||
@SerialName("em") val msg: String, //信息
|
||||
val feeds: List<GroupAnnouncement>? = null, //群公告列表
|
||||
val inst: List<GroupAnnouncement>? = null //置顶列表?
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupAnnouncement(
|
||||
@SerialName("u") val sender: Long,
|
||||
@SerialName("u") val sender: Long = 0,
|
||||
val msg: GroupAnnouncementMsg,
|
||||
val settings: GroupAnnouncementSettings
|
||||
val settings: GroupAnnouncementSettings? = null,
|
||||
@SerialName("pubt") val time: Long = 0,
|
||||
@SerialName("read_num") val readNum: Int = 0,
|
||||
@SerialName("is_read") val isRead: Int = 0,
|
||||
val pinned: Int = 0
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupAnnouncementMsg(
|
||||
val text: String,
|
||||
val text_face: String,
|
||||
val title: String
|
||||
val text_face: String? = null,
|
||||
val title: String? = null
|
||||
)
|
||||
|
||||
@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
|
||||
@SerialName("is_show_edit_card") val isShowEditCard: Int = 0,
|
||||
@SerialName("remind_ts") val remindTs: Int = 0,
|
||||
@SerialName("tip_window_type") val tipWindowType: Int = 0,
|
||||
@SerialName("confirm_required") val confirmRequired: Int = 0
|
||||
)
|
@ -11,6 +11,7 @@ package net.mamoe.mirai.contact
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.data.GroupAnnouncement
|
||||
import net.mamoe.mirai.data.GroupAnnouncementList
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.event.events.*
|
||||
@ -153,7 +154,14 @@ actual abstract class Group : Contact(), CoroutineScope {
|
||||
*
|
||||
* */
|
||||
@MiraiExperimentalAPI
|
||||
actual suspend abstract fun getAnnouncements(page: Int, amount: Int ):GroupAnnouncementList?
|
||||
actual suspend abstract fun getAnnouncements(page: Int, amount: Int): GroupAnnouncementList?
|
||||
|
||||
|
||||
/**
|
||||
* 发送群公告
|
||||
* */
|
||||
@MiraiExperimentalAPI
|
||||
actual suspend abstract fun sendAnnouncement(announcement: GroupAnnouncement)
|
||||
|
||||
/**
|
||||
* 检查此 id 的群成员是否存在
|
||||
|
Loading…
Reference in New Issue
Block a user