Skip to content

Commit ab5d08a

Browse files
committed
[core] nudge support for ANDROID_PAD, close #2771
1 parent 684b003 commit ab5d08a

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

mirai-core-api/compatibility-validation/android/api/android.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,6 +5732,7 @@ public final class net/mamoe/mirai/utils/BotConfiguration$MiraiProtocol : java/l
57325732
public static final field ANDROID_WATCH Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
57335733
public static final field IPAD Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
57345734
public static final field MACOS Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
5735+
public final fun isNudgeSupported ()Z
57355736
public final fun isQRLoginSupported ()Z
57365737
public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
57375738
public static fun values ()[Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;

mirai-core-api/compatibility-validation/jvm/api/jvm.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,6 +5732,7 @@ public final class net/mamoe/mirai/utils/BotConfiguration$MiraiProtocol : java/l
57325732
public static final field ANDROID_WATCH Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
57335733
public static final field IPAD Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
57345734
public static final field MACOS Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
5735+
public final fun isNudgeSupported ()Z
57355736
public final fun isQRLoginSupported ()Z
57365737
public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;
57375738
public static fun values ()[Lnet/mamoe/mirai/utils/BotConfiguration$MiraiProtocol;

mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ public open class BotConfiguration : AbstractBotConfiguration() { // open for Ja
262262
*/
263263
public val isQRLoginSupported: Boolean get() = data.isQRLoginSupported
264264

265+
/**
266+
* 当前协议是否支持[戳一戳][Bot.nudge]
267+
*
268+
* @since 2.16.0
269+
*/
270+
public val isNudgeSupported: Boolean get() = data.isNudgeSupported
271+
265272
private inline val data: InternalProtocolDataExchange.InternalProtocolData
266273
get() = InternalProtocolDataExchange.instance.of(
267274
this
@@ -585,6 +592,7 @@ public interface InternalProtocolDataExchange {
585592
@MiraiInternalApi
586593
public interface InternalProtocolData {
587594
public val isQRLoginSupported: Boolean
595+
public val isNudgeSupported: Boolean
588596
public val mainVersion: String
589597
public val buildVersion: String
590598
public val sdkVersion: String

mirai-core/src/commonMain/kotlin/MiraiImpl.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,10 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
644644
}
645645

646646
override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
647-
if ((bot.configuration.protocol != BotConfiguration.MiraiProtocol.ANDROID_PHONE) && (bot.configuration.protocol != BotConfiguration.MiraiProtocol.IPAD)) {
648-
throw UnsupportedOperationException("nudge is supported only with protocol ANDROID_PHONE or IPAD")
647+
if (!bot.configuration.protocol.isNudgeSupported) {
648+
throw UnsupportedOperationException("nudge is supported only with protocol ${
649+
MiraiProtocolInternal.protocols.filter { it.value.supportsNudge }.map { it.key }
650+
}")
649651
}
650652
bot.asQQAndroidBot()
651653

mirai-core/src/commonMain/kotlin/utils/MiraiProtocolInternal.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ internal class MiraiProtocolInternal(
2929
var ssoVersion: Int,
3030
var appKey: String,
3131
var supportsQRLogin: Boolean,
32+
var supportsNudge: Boolean
3233

3334
// don't change property signatures, used externally.
3435
) : InternalProtocolDataExchange.InternalProtocolData {
@@ -56,6 +57,7 @@ internal class MiraiProtocolInternal(
5657
ssoVersion = 20,
5758
appKey = "0S200MNJT807V3GE",
5859
supportsQRLogin = false,
60+
supportsNudge = true
5961
)
6062
//Updated from MiraiGo (2023/6/18)
6163
protocols[MiraiProtocol.ANDROID_PAD] = MiraiProtocolInternal(
@@ -72,6 +74,7 @@ internal class MiraiProtocolInternal(
7274
ssoVersion = 20,
7375
appKey = "0S200MNJT807V3GE",
7476
supportsQRLogin = false,
77+
supportsNudge = true
7578
)
7679
//Updated from MiraiGo (2023/3/24)
7780
protocols[MiraiProtocol.ANDROID_WATCH] = MiraiProtocolInternal(
@@ -88,6 +91,7 @@ internal class MiraiProtocolInternal(
8891
ssoVersion = 5,
8992
appKey = "",
9093
supportsQRLogin = true,
94+
supportsNudge = false
9195
)
9296
protocols[MiraiProtocol.IPAD] = MiraiProtocolInternal(
9397
apkId = "com.tencent.minihd.qq",
@@ -103,6 +107,7 @@ internal class MiraiProtocolInternal(
103107
ssoVersion = 12,
104108
appKey = "",
105109
supportsQRLogin = false,
110+
supportsNudge = true
106111
)
107112
protocols[MiraiProtocol.MACOS] = MiraiProtocolInternal(
108113
apkId = "com.tencent.qq",
@@ -118,6 +123,7 @@ internal class MiraiProtocolInternal(
118123
ssoVersion = 7,
119124
appKey = "",
120125
supportsQRLogin = true,
126+
supportsNudge = false
121127
)
122128
}
123129

@@ -134,6 +140,7 @@ internal class MiraiProtocolInternal(
134140

135141

136142
override val isQRLoginSupported: Boolean get() = supportsQRLogin
143+
override val isNudgeSupported: Boolean get() = supportsNudge
137144
override val mainVersion: String get() = ver
138145
override val buildVersion: String get() = buildVer
139146
override val sdkVersion: String get() = sdkVer

0 commit comments

Comments
 (0)