Skip to content

Commit

Permalink
✨ Added get_version_info api for go-cqhttp extend #234
Browse files Browse the repository at this point in the history
Co-authored-by: xinmu <2510136957@email.com>
  • Loading branch information
XM2510136957 and xinmu authored Aug 1, 2024
1 parent e366238 commit bc95115
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@file:Suppress("SpellCheckingInspection")

group = "com.mikuac"
version = "2.2.9"
version = "2.3.0"

plugins {
signing
Expand Down Expand Up @@ -97,4 +97,4 @@ signing {
val signingPassword = System.getenv("GPG_PASSPHRASE")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications["maven"])
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/mikuac/shiro/action/GoCQHTTPExtend.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,10 @@ public interface GoCQHTTPExtend {
* @return result {@link ActionList} of {@link GroupMemberInfoResp}
*/
ActionList<GroupMemberInfoResp> getGroupMemberList(long groupId, boolean noCache);

/**
* 获取版本信息
* @return result {@link ActionList} of {@link VersionInfoResp}
*/
public ActionData<VersionInfoResp> getVersionInfo();
}
30 changes: 30 additions & 0 deletions src/main/java/com/mikuac/shiro/common/utils/ShiroUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mikuac.shiro.common.utils;

import com.alibaba.fastjson2.JSON;
import com.mikuac.shiro.core.Bot;
import com.mikuac.shiro.dto.event.message.MessageEvent;
import com.mikuac.shiro.enums.MsgTypeEnum;
import com.mikuac.shiro.model.ArrayMsg;
Expand Down Expand Up @@ -330,6 +331,35 @@ public static List<Map<String, Object>> generateForwardMsg(String uin, String na
return nodes;
}

/**
* 兼容 Lagrange
* 生成自定义合并转发消息
*
* @param contents 消息列表,每个元素视为一个消息节点 Object 可为 List<ArrayMsg> 或 CQCode
* @return 消息结构
*/
@SuppressWarnings("Duplicates")
public static List<Map<String, Object>> generateForwardMsg(Bot bot, List<?> contents) {
List<Map<String, Object>> nodes = new ArrayList();
contents.forEach((msg) -> {
Map<String, Object> node = new HashMap();
node.put("type", "node");
Map<String, Object> data = new HashMap();
data.put("name", bot.getLoginInfo().getData().getNickname());
String appName = bot.getVersionInfo().getData().getAppName();
//兼容Lagrange
if (appName.equals("Lagrange.OneBot")){
data.put("uin", String.valueOf(bot.getSelfId()));
}else {
data.put("uin", bot.getSelfId());
}
data.put("content", msg);
node.put("data", data);
nodes.add(node);
});
return nodes;
}

/**
* 兼容 Shamrock
* 生成引用消息和自定义消息混合合并转发
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/mikuac/shiro/core/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,19 @@ public ActionList<GroupMemberInfoResp> getGroupMemberList(long groupId, boolean
}.getType()) : null;
}

/**
* https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF
* 获取版本信息
* @return result {@link ActionData} of {@link VersionInfoResp}
*/
@Override
public ActionData<VersionInfoResp> getVersionInfo() {

JSONObject result = actionHandler.action(session, ActionPathEnum.GET_VERSION_INFO, null);
return result != null ? result.to(new TypeReference<ActionData<VersionInfoResp>>() {
}.getType()) : null;
}

/**
* 获取群荣誉信息
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mikuac.shiro.dto.action.response;

import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;

@Data
public class VersionInfoResp {

@JSONField(name = "app_name")
private String appName;

@JSONField(name = "app_version")
private String appVersion;

@JSONField(name = "protocol_version")
private String protocolVersion;

@JSONField(name = "version")
private String version;
}
6 changes: 5 additions & 1 deletion src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ public enum ActionPathEnum implements ActionPath {
/**
* 获取收藏表情
*/
FETCH_CUSTOM_FACE("fetch_custom_face");
FETCH_CUSTOM_FACE("fetch_custom_face"),
/**
* 获取版本信息
*/
GET_VERSION_INFO("get_version_info");

/**
* 请求路径
Expand Down

0 comments on commit bc95115

Please sign in to comment.