Throw SendMessageFailedException with new reason AT_ALL_LIMITED, fix #1948

This commit is contained in:
Him188 2022-04-02 13:24:30 +01:00
parent eba7698345
commit 2a8f7de23d
4 changed files with 18 additions and 7 deletions

View File

@ -538,6 +538,7 @@ public class net/mamoe/mirai/contact/SendMessageFailedException : java/lang/Runt
}
public final class net/mamoe/mirai/contact/SendMessageFailedException$Reason : java/lang/Enum {
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 MESSAGE_TOO_LARGE Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;

View File

@ -538,6 +538,7 @@ public class net/mamoe/mirai/contact/SendMessageFailedException : java/lang/Runt
}
public final class net/mamoe/mirai/contact/SendMessageFailedException$Reason : java/lang/Enum {
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 MESSAGE_TOO_LARGE Lnet/mamoe/mirai/contact/SendMessageFailedException$Reason;

View File

@ -1,22 +1,22 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("unused")
package net.mamoe.mirai.contact
import net.mamoe.mirai.message.data.AtAll
import net.mamoe.mirai.message.data.Message
import net.mamoe.mirai.message.data.messageChainOf
import net.mamoe.mirai.utils.DeprecatedSinceMirai
import net.mamoe.mirai.utils.MiraiInternalApi
import net.mamoe.mirai.utils.millisToHumanReadableString
import kotlin.time.ExperimentalTime
/**
* 发送消息时消息过长抛出的异常.
@ -43,7 +43,6 @@ public class MessageTooLargeException constructor(
*
* @see Group.sendMessage
*/
@OptIn(ExperimentalTime::class)
public class BotIsBeingMutedException @MiraiInternalApi constructor(
// this constructor is since 2.9.0-RC
public override val target: Group,
@ -90,5 +89,11 @@ public open class SendMessageFailedException @MiraiInternalApi constructor(
* 达到群每分钟发言次数限制
*/
GROUP_CHAT_LIMITED,
/**
* 达到每日发送 [AtAll] 的次数限制
* @since 2.11
*/
AT_ALL_LIMITED,
}
}

View File

@ -173,7 +173,11 @@ internal abstract class SendMessageHandler<C : Contact> {
val contact = contact
when (resp.resultType) {
120 -> if (contact is Group) throw BotIsBeingMutedException(contact, originalMessage)
121 -> if (AtAll in finalMessage) throw IllegalStateException("Send message to $contact failed, reached maximum AtAll times limit.")
121 -> if (AtAll in finalMessage) throw SendMessageFailedException(
contact,
SendMessageFailedException.Reason.AT_ALL_LIMITED,
originalMessage
)
299 -> if (contact is Group) throw SendMessageFailedException(
contact,
SendMessageFailedException.Reason.GROUP_CHAT_LIMITED,