[core] nudge support for ANDROID_PAD, close #2771

This commit is contained in:
StageGuard 2023-08-30 10:46:03 +08:00
parent 684b003764
commit ab5d08afb1
No known key found for this signature in database
GPG Key ID: F6FF8760A883492B
5 changed files with 21 additions and 2 deletions

View File

@ -5732,6 +5732,7 @@ public final class net/mamoe/mirai/utils/BotConfiguration$MiraiProtocol : java/l
public static final field ANDROID_WATCH Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public static final field IPAD Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public static final field MACOS Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public final fun isNudgeSupported ()Z
public final fun isQRLoginSupported ()Z
public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public static fun values ()[Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;

View File

@ -5732,6 +5732,7 @@ public final class net/mamoe/mirai/utils/BotConfiguration$MiraiProtocol : java/l
public static final field ANDROID_WATCH Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public static final field IPAD Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public static final field MACOS Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public final fun isNudgeSupported ()Z
public final fun isQRLoginSupported ()Z
public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
public static fun values ()[Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;

View File

@ -262,6 +262,13 @@ public open class BotConfiguration : AbstractBotConfiguration() { // open for Ja
*/
public val isQRLoginSupported: Boolean get() = data.isQRLoginSupported
/**
* 当前协议是否支持[戳一戳][Bot.nudge]
*
* @since 2.16.0
*/
public val isNudgeSupported: Boolean get() = data.isNudgeSupported
private inline val data: InternalProtocolDataExchange.InternalProtocolData
get() = InternalProtocolDataExchange.instance.of(
this
@ -585,6 +592,7 @@ public interface InternalProtocolDataExchange {
@MiraiInternalApi
public interface InternalProtocolData {
public val isQRLoginSupported: Boolean
public val isNudgeSupported: Boolean
public val mainVersion: String
public val buildVersion: String
public val sdkVersion: String

View File

@ -644,8 +644,10 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
}
override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
if ((bot.configuration.protocol != BotConfiguration.MiraiProtocol.ANDROID_PHONE) && (bot.configuration.protocol != BotConfiguration.MiraiProtocol.IPAD)) {
throw UnsupportedOperationException("nudge is supported only with protocol ANDROID_PHONE or IPAD")
if (!bot.configuration.protocol.isNudgeSupported) {
throw UnsupportedOperationException("nudge is supported only with protocol ${
MiraiProtocolInternal.protocols.filter { it.value.supportsNudge }.map { it.key }
}")
}
bot.asQQAndroidBot()

View File

@ -29,6 +29,7 @@ internal class MiraiProtocolInternal(
var ssoVersion: Int,
var appKey: String,
var supportsQRLogin: Boolean,
var supportsNudge: Boolean
// don't change property signatures, used externally.
) : InternalProtocolDataExchange.InternalProtocolData {
@ -56,6 +57,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 20,
appKey = "0S200MNJT807V3GE",
supportsQRLogin = false,
supportsNudge = true
)
//Updated from MiraiGo (2023/6/18)
protocols[MiraiProtocol.ANDROID_PAD] = MiraiProtocolInternal(
@ -72,6 +74,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 20,
appKey = "0S200MNJT807V3GE",
supportsQRLogin = false,
supportsNudge = true
)
//Updated from MiraiGo (2023/3/24)
protocols[MiraiProtocol.ANDROID_WATCH] = MiraiProtocolInternal(
@ -88,6 +91,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 5,
appKey = "",
supportsQRLogin = true,
supportsNudge = false
)
protocols[MiraiProtocol.IPAD] = MiraiProtocolInternal(
apkId = "com.tencent.minihd.qq",
@ -103,6 +107,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 12,
appKey = "",
supportsQRLogin = false,
supportsNudge = true
)
protocols[MiraiProtocol.MACOS] = MiraiProtocolInternal(
apkId = "com.tencent.qq",
@ -118,6 +123,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 7,
appKey = "",
supportsQRLogin = true,
supportsNudge = false
)
}
@ -134,6 +140,7 @@ internal class MiraiProtocolInternal(
override val isQRLoginSupported: Boolean get() = supportsQRLogin
override val isNudgeSupported: Boolean get() = supportsNudge
override val mainVersion: String get() = ver
override val buildVersion: String get() = buildVer
override val sdkVersion: String get() = sdkVer