mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 03:22:36 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
23dd54b300
@ -143,7 +143,7 @@ internal class QQAndroidBot constructor(
|
||||
|
||||
@Suppress("DuplicatedCode")
|
||||
@OptIn(LowLevelAPI::class)
|
||||
override suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean) {
|
||||
override suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean, message: String) {
|
||||
checkGroupPermission(event.bot, event.group) { event::class.simpleName ?: "<anonymous class>" }
|
||||
check(event.responded.compareAndSet(false, true)) {
|
||||
"the request $this has already been responded"
|
||||
@ -159,7 +159,8 @@ internal class QQAndroidBot constructor(
|
||||
fromNick = event.fromNick,
|
||||
groupId = event.groupId,
|
||||
accept = false,
|
||||
blackList = blackList
|
||||
blackList = blackList,
|
||||
message = message
|
||||
)
|
||||
}
|
||||
|
||||
@ -755,7 +756,8 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
fromNick: String,
|
||||
groupId: Long,
|
||||
accept: Boolean?,
|
||||
blackList: Boolean
|
||||
blackList: Boolean,
|
||||
message: String
|
||||
) {
|
||||
network.apply {
|
||||
NewContact.SystemMsgNewGroup.Action(
|
||||
@ -765,7 +767,8 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
groupId = groupId,
|
||||
isInvited = false,
|
||||
accept = accept,
|
||||
blackList = blackList
|
||||
blackList = blackList,
|
||||
message = message
|
||||
).sendWithoutExpect()
|
||||
if (accept ?: return)
|
||||
groups[groupId].apply {
|
||||
|
@ -114,7 +114,7 @@ internal class FriendImpl(
|
||||
fileId = 0,
|
||||
fileMd5 = image.md5,
|
||||
fileSize = image.input.size.toInt(),
|
||||
fileName = image.md5.toUHexString("") + "." + ExternalImage.defaultFormatName,
|
||||
fileName = image.md5.toUHexString("") + "." + image.formatName,
|
||||
imgOriginal = 1
|
||||
)
|
||||
).sendAndExpect<LongConn.OffPicUp.Response>()
|
||||
|
@ -223,7 +223,8 @@ internal class NewContact {
|
||||
groupId: Long,
|
||||
isInvited: Boolean,
|
||||
accept: Boolean?,
|
||||
blackList: Boolean = false
|
||||
blackList: Boolean = false,
|
||||
message: String = ""
|
||||
) =
|
||||
buildOutgoingUniPacket(client) {
|
||||
writeProtoBuf(
|
||||
@ -236,7 +237,7 @@ internal class NewContact {
|
||||
false -> 12 // reject
|
||||
},
|
||||
groupCode = groupId,
|
||||
msg = "",
|
||||
msg = message,
|
||||
remark = "",
|
||||
blacklist = blackList
|
||||
),
|
||||
|
@ -294,7 +294,7 @@ abstract class Bot internal constructor(
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
@JvmSynthetic
|
||||
abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
|
||||
abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false, message: String = "")
|
||||
|
||||
/**
|
||||
* 忽略加群验证(需管理员权限)
|
||||
|
@ -355,7 +355,7 @@ data class MemberJoinRequestEvent internal constructor(
|
||||
suspend fun accept() = bot.acceptMemberJoinRequest(this)
|
||||
|
||||
@JvmSynthetic
|
||||
suspend fun reject(blackList: Boolean = false) = bot.rejectMemberJoinRequest(this, blackList)
|
||||
suspend fun reject(blackList: Boolean = false, message: String = "") = bot.rejectMemberJoinRequest(this, blackList, message)
|
||||
|
||||
@JvmSynthetic
|
||||
suspend fun ignore(blackList: Boolean = false) = bot.ignoreMemberJoinRequest(this, blackList)
|
||||
@ -368,8 +368,8 @@ data class MemberJoinRequestEvent internal constructor(
|
||||
@JavaFriendlyAPI
|
||||
@JvmOverloads
|
||||
@JvmName("reject")
|
||||
fun __rejectBlockingForJava__(blackList: Boolean = false) =
|
||||
runBlocking { bot.rejectMemberJoinRequest(this@MemberJoinRequestEvent, blackList) }
|
||||
fun __rejectBlockingForJava__(blackList: Boolean = false, message: String = "") =
|
||||
runBlocking { bot.rejectMemberJoinRequest(this@MemberJoinRequestEvent, blackList, message) }
|
||||
|
||||
@JavaFriendlyAPI
|
||||
@JvmOverloads
|
||||
|
@ -137,5 +137,5 @@ interface LowLevelBotAPIAccessor {
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
suspend fun _lowLevelSolveMemberJoinRequestEvent(eventId: Long, fromId: Long, fromNick: String, groupId: Long, accept: Boolean?, blackList: Boolean)
|
||||
suspend fun _lowLevelSolveMemberJoinRequestEvent(eventId: Long, fromId: Long, fromNick: String, groupId: Long, accept: Boolean?, blackList: Boolean, message: String = "")
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ expect interface Image : Message, MessageContent, CodableMessage {
|
||||
*
|
||||
* ### 格式
|
||||
* 群图片:
|
||||
* - [GROUP_IMAGE_ID_REGEX], 示例: `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai` (后缀一定为 `".mirai"`)
|
||||
* - [GROUP_IMAGE_ID_REGEX], 示例: `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.ext` (ext系扩展名)
|
||||
*
|
||||
* 好友图片:
|
||||
* - [FRIEND_IMAGE_ID_REGEX_1], 示例: `/f8f1ab55-bf8e-4236-b55e-955848d7069f`
|
||||
@ -125,7 +125,7 @@ abstract class FriendImage internal constructor() : AbstractImage() { // change
|
||||
/**
|
||||
* 群图片.
|
||||
*
|
||||
* @property imageId 形如 `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai` (后缀一定为 `".mirai"`)
|
||||
* @property imageId 形如 `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.ext` (ext系扩展名)
|
||||
* @see Image 查看更多说明
|
||||
*/
|
||||
// CustomFace
|
||||
@ -156,11 +156,11 @@ val FRIEND_IMAGE_ID_REGEX_2 = Regex("""/[0-9]*-[0-9]*-[0-9a-fA-F]{32}""")
|
||||
/**
|
||||
* 群图片 ID 正则表达式
|
||||
*
|
||||
* `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai`
|
||||
* `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.ext`
|
||||
*/
|
||||
@Suppress("RegExpRedundantEscape") // This is required on Android
|
||||
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX
|
||||
val GROUP_IMAGE_ID_REGEX = Regex("""\{[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\}\.mirai""")
|
||||
val GROUP_IMAGE_ID_REGEX = Regex("""\{[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\}\..{3,5}""")
|
||||
|
||||
/**
|
||||
* 通过 [Image.imageId] 构造一个 [Image] 以便发送.
|
||||
|
@ -11,15 +11,18 @@
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import kotlinx.io.core.readBytes
|
||||
import kotlinx.io.core.use
|
||||
import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.User
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.sendTo
|
||||
import net.mamoe.mirai.message.data.toUHexString
|
||||
import net.mamoe.mirai.utils.internal.DeferredReusableInput
|
||||
import net.mamoe.mirai.utils.internal.ReusableInput
|
||||
import kotlin.jvm.JvmField
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
|
||||
/**
|
||||
@ -35,6 +38,12 @@ class ExternalImage internal constructor(
|
||||
internal val input: ReusableInput
|
||||
) {
|
||||
internal val md5: ByteArray get() = this.input.md5
|
||||
val formatName: String by lazy {
|
||||
val hex = input.asInput().use {
|
||||
it.readBytes(8).toUHexString("")
|
||||
}
|
||||
return@lazy hex.detectFormatName()
|
||||
}
|
||||
|
||||
init {
|
||||
if (input !is DeferredReusableInput) {
|
||||
@ -67,6 +76,14 @@ class ExternalImage internal constructor(
|
||||
}
|
||||
|
||||
internal fun calculateImageResourceId(): String = generateImageId(md5)
|
||||
|
||||
private fun String.detectFormatName(): String = when {
|
||||
startsWith("FFD8") -> "jpg"
|
||||
startsWith("89504E47") -> "png"
|
||||
startsWith("47494638") -> "gif"
|
||||
startsWith("424D") -> "bmp"
|
||||
else -> defaultFormatName
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user