Throw specific SendMessageFailedException when reaching group chat limit, close #1220

This commit is contained in:
Him188 2021-11-26 17:54:21 +00:00
parent a989ea9db1
commit 74fc5a5037
4 changed files with 12 additions and 0 deletions

View File

@ -539,6 +539,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 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;
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

@ -539,6 +539,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 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;
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

@ -85,5 +85,10 @@ public open class SendMessageFailedException @MiraiInternalApi constructor(
* 机器人被禁言
*/
BOT_MUTED,
/**
* 达到群每分钟发言次数限制
*/
GROUP_CHAT_LIMITED,
}
}

View File

@ -174,6 +174,11 @@ internal abstract class SendMessageHandler<C : 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.")
299 -> if (contact is Group) throw SendMessageFailedException(
contact,
SendMessageFailedException.Reason.GROUP_CHAT_LIMITED,
originalMessage
)
}
}
check(resp is MessageSvcPbSendMsg.Response.SUCCESS) {