Skip to content

Commit

Permalink
[core] nudge support for ANDROID_PAD, close #2771
Browse files Browse the repository at this point in the history
  • Loading branch information
StageGuard committed Aug 30, 2023
1 parent 684b003 commit ab5d08a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mirai-core-api/compatibility-validation/jvm/api/jvm.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions mirai-core/src/commonMain/kotlin/MiraiImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -88,6 +91,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 5,
appKey = "",
supportsQRLogin = true,
supportsNudge = false
)
protocols[MiraiProtocol.IPAD] = MiraiProtocolInternal(
apkId = "com.tencent.minihd.qq",
Expand All @@ -103,6 +107,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 12,
appKey = "",
supportsQRLogin = false,
supportsNudge = true
)
protocols[MiraiProtocol.MACOS] = MiraiProtocolInternal(
apkId = "com.tencent.qq",
Expand All @@ -118,6 +123,7 @@ internal class MiraiProtocolInternal(
ssoVersion = 7,
appKey = "",
supportsQRLogin = true,
supportsNudge = false
)
}

Expand All @@ -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
Expand Down

0 comments on commit ab5d08a

Please sign in to comment.