Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加get_status api,fix一个启动时可能遇到的错误 #154

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/mikuac/shiro/common/utils/RegexUtils.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,7 +17,7 @@ public class RegexUtils {
private RegexUtils() {
}

private static final Map<String, Pattern> cache = new HashMap<>();
private static final Map<String, Pattern> cache = new ConcurrentHashMap<>();

/**
* 正则匹配
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/mikuac/shiro/core/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActionData<GetStatusResp>>() {
}).getData() : null;
}
}
103 changes: 103 additions & 0 deletions src/main/java/com/mikuac/shiro/dto/action/response/GetStatusResp.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ public enum ActionPathEnum implements ActionPath {
/**
* 发送好友赞
*/
SEND_LIKE("send_like");
SEND_LIKE("send_like"),
/**
* 获取状态
*/
GET_STATUS("get_status"),
;

/**
* 请求路径
Expand Down