diff --git a/src/main/java/com/mikuac/shiro/common/utils/RegexUtils.java b/src/main/java/com/mikuac/shiro/common/utils/RegexUtils.java index 62ca533..54af19e 100644 --- a/src/main/java/com/mikuac/shiro/common/utils/RegexUtils.java +++ b/src/main/java/com/mikuac/shiro/common/utils/RegexUtils.java @@ -1,8 +1,8 @@ package com.mikuac.shiro.common.utils; -import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,7 +17,7 @@ public class RegexUtils { private RegexUtils() { } - private static final Map cache = new HashMap<>(); + private static final Map cache = new ConcurrentHashMap<>(); /** * 正则匹配 diff --git a/src/main/java/com/mikuac/shiro/core/Bot.java b/src/main/java/com/mikuac/shiro/core/Bot.java index 5ba03d0..58dfc96 100644 --- a/src/main/java/com/mikuac/shiro/core/Bot.java +++ b/src/main/java/com/mikuac/shiro/core/Bot.java @@ -1130,4 +1130,14 @@ public ActionRaw sendLike(long userId, int times) { return result != null ? result.to(ActionRaw.class) : null; } + /** + * 获取状态 + * + * @return result {@link GetStatusResp} + */ + public GetStatusResp getStatus() { + JSONObject result = actionHandler.action(session, ActionPathEnum.GET_STATUS, null); + return result != null ? result.to(new TypeReference>() { + }).getData() : null; + } } diff --git a/src/main/java/com/mikuac/shiro/dto/action/response/GetStatusResp.java b/src/main/java/com/mikuac/shiro/dto/action/response/GetStatusResp.java new file mode 100644 index 0000000..650d41d --- /dev/null +++ b/src/main/java/com/mikuac/shiro/dto/action/response/GetStatusResp.java @@ -0,0 +1,103 @@ +package com.mikuac.shiro.dto.action.response; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; + +/** + * @author Neo + * @date 2023/7/26 + */ +@Data +public class GetStatusResp { + + /** + * 原 CQHTTP 字段, 恒定为 true + */ + @JSONField(name = "app_initialized") + private Boolean appInitialized; + + /** + * 原 CQHTTP 字段, 恒定为 true + */ + @JSONField(name = "app_enabled") + private Boolean appEnabled; + + /** + * 原 CQHTTP 字段 + */ + @JSONField(name = "plugins_good") + private Boolean pluginsGood; + + /** + * 原 CQHTTP 字段, 恒定为 true + */ + @JSONField(name = "app_good") + private Boolean appGood; + + /** + * 表示BOT是否在线 + */ + private Boolean online; + + /** + * 同 online + */ + private Boolean good; + + /** + * 运行统计 + */ + private Statistics stat; + + @Data + public static class Statistics { + + /** + * 收到的数据包总数 + */ + @JSONField(name = "packet_received") + private Long packetReceived; + + /** + * 发送的数据包总数 + */ + @JSONField(name = "packet_sent") + private Long packetSent; + + /** + * 数据包丢失总数 + */ + @JSONField(name = "packet_lost") + private Integer packetLost; + + /** + * 接受信息总数 + */ + @JSONField(name = "message_received") + private Long messageReceived; + + /** + * 发送信息总数 + */ + @JSONField(name = "message_sent") + private Long messageSent; + + /** + * TCP 链接断开次数 + */ + @JSONField(name = "disconnect_times") + private Integer disconnectTimes; + + /** + * 账号掉线次数 + */ + @JSONField(name = "lost_times") + private Integer lostTimes; + + /** + * 最后一条消息时间 + */ + @JSONField(name = "last_message_time") + private Long lastMessageTime; + } +} diff --git a/src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java b/src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java index 4b5db9d..09099dc 100644 --- a/src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java +++ b/src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java @@ -261,7 +261,12 @@ public enum ActionPathEnum implements ActionPath { /** * 发送好友赞 */ - SEND_LIKE("send_like"); + SEND_LIKE("send_like"), + /** + * 获取状态 + */ + GET_STATUS("get_status"), + ; /** * 请求路径