[core] Show specific reason for error 46 while sending message. Close #2127

This commit is contained in:
Him188 2022-10-31 10:40:26 +00:00
parent 4abcb7fb4e
commit 573f08955c
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
4 changed files with 23 additions and 1 deletions

View File

@ -563,6 +563,7 @@ public final class net/mamoe/mirai/contact/Platform$Companion {
}
public class net/mamoe/mirai/contact/SendMessageFailedException : java/lang/RuntimeException {
public synthetic fun <init> (Lnet/mamoe/mirai/contact/Contact;Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;Lnet/mamoe/mirai/message/data/Message;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getOriginalMessage ()Lnet/mamoe/mirai/message/data/Message;
public final fun getReason ()Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public fun getTarget ()Lnet/mamoe/mirai/contact/Contact;
@ -572,6 +573,7 @@ public final class net/mamoe/mirai/contact/SendMessageFailedException$Reason : j
public static final field AT_ALL_LIMITED Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field BOT_MUTED Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field GROUP_CHAT_LIMITED Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field LIMITED_MESSAGING Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field MESSAGE_TOO_LARGE Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static fun values ()[Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;

View File

@ -563,6 +563,7 @@ public final class net/mamoe/mirai/contact/Platform$Companion {
}
public class net/mamoe/mirai/contact/SendMessageFailedException : java/lang/RuntimeException {
public synthetic fun <init> (Lnet/mamoe/mirai/contact/Contact;Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;Lnet/mamoe/mirai/message/data/Message;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getOriginalMessage ()Lnet/mamoe/mirai/message/data/Message;
public final fun getReason ()Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public fun getTarget ()Lnet/mamoe/mirai/contact/Contact;
@ -572,6 +573,7 @@ public final class net/mamoe/mirai/contact/SendMessageFailedException$Reason : j
public static final field AT_ALL_LIMITED Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field BOT_MUTED Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field GROUP_CHAT_LIMITED Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field LIMITED_MESSAGING Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static final field MESSAGE_TOO_LARGE Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static fun valueOf (Ljava/lang/String;)Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;
public static fun values ()[Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;

View File

@ -74,8 +74,12 @@ public open class SendMessageFailedException @MiraiInternalApi constructor(
public open val target: Contact,
public val reason: Reason,
public val originalMessage: Message,
/**
* @since 2.14
*/
tips: String? = null,
) : RuntimeException(
"Failed sending message to $target, reason=$reason"
"Failed sending message to $target, reason=$reason. Tips: $tips"
) {
public enum class Reason {
/**
@ -98,5 +102,12 @@ public open class SendMessageFailedException @MiraiInternalApi constructor(
* @since 2.11
*/
AT_ALL_LIMITED,
/**
* 被服务器限制发送消息, 属于冻结的一种
*
* @since 2.14
*/
LIMITED_MESSAGING,
}
}

View File

@ -145,6 +145,13 @@ internal class GeneralMessageSenderProtocol : MessageProtocol(PRIORITY_GENERAL_S
SendMessageFailedException.Reason.GROUP_CHAT_LIMITED,
originalMessage
)
// #2127
46 -> throw SendMessageFailedException(
contact,
SendMessageFailedException.Reason.LIMITED_MESSAGING,
originalMessage,
tips = "问题原因可能是账号被多次举报或被服务器认为不安全. 可尝试访问 https://accounts.qq.com/safe/message/unlock?lock_info=5_5 解冻."
)
}
}
check(resp is MessageSvcPbSendMsg.Response.SUCCESS) {