Compare commits

...

3 Commits

13 changed files with 125 additions and 19 deletions

3
.idea/gradle.xml generated
View File

@ -4,8 +4,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="" />
<option name="gradleHome" value="$USER_HOME$/.sdkman/candidates/gradle/current" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -21,5 +21,25 @@
<option name="name" value="maven" />
<option name="url" value="https://libraries.minecraft.net" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://maven.aliyun.com/repository/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven2" />
<option name="name" value="maven2" />
<option name="url" value="https://maven.aliyun.com/repository/central" />
</remote-repository>
<remote-repository>
<option name="id" value="maven3" />
<option name="name" value="maven3" />
<option name="url" value="https://maven.aliyun.com/repository/gradle-plugin" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenLocal" />
<option name="name" value="MavenLocal" />
<option name="url" value="file:/$MAVEN_REPOSITORY$" />
</remote-repository>
</component>
</project>

1
.idea/modules.xml generated
View File

@ -2,7 +2,6 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/MyBot.iml" filepath="$PROJECT_DIR$/.idea/modules/MyBot.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/MyBot.main.iml" filepath="$PROJECT_DIR$/.idea/modules/MyBot.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/mybot-api/MyBot.mybot-api.main.iml" filepath="$PROJECT_DIR$/.idea/modules/mybot-api/MyBot.mybot-api.main.iml" />
</modules>

View File

@ -14,7 +14,7 @@ allprojects {
apply(plugin = "java-library")
val groupName by extra("cn.wzpmc")
val projectArtifactId by extra("my-bot")
val projectVersion by extra("1.0.5")
val projectVersion by extra("1.0.6-SNAPSHOT")
repositories {
mavenCentral()
maven("https://libraries.minecraft.net")

View File

@ -6,8 +6,6 @@ import com.alibaba.fastjson2.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
/**
* 群成员信息
*
@ -63,19 +61,19 @@ public class GroupMemberInformation {
*/
private String area;
/**
* 加群时间
* 加群时间时间戳
*
* @since 2024/8/24 19:30 v0.0.6-dev
*/
@JSONField(name = "join_time")
private Date joinTime;
private Long joinTime;
/**
* 最后发言时间
* 最后发言时间时间戳
*
* @since 2024/8/24 19:30 v0.0.6-dev
*/
@JSONField(name = "last_sent_time")
private Date lastSentTime;
private Long lastSentTime;
/**
* 成员等级
*
@ -101,12 +99,12 @@ public class GroupMemberInformation {
*/
private String title;
/**
* 专属头衔过期时间
* 专属头衔过期时间时间戳
*
* @since 2024/8/24 19:30 v0.0.6-dev
*/
@JSONField(name = "title_expire_time")
private Date titleExpireTime;
private Long titleExpireTime;
/**
* 是否允许修改群名片
*

View File

@ -21,6 +21,7 @@ public interface JsonMessagePart {
* @author wzp
* @since 2024/7/31 上午2:40 v0.0.1-dev
*/
@JSONField(serialize = false, deserialize = false)
PartType getPartType();
@JSONField(name = "type")

View File

@ -140,7 +140,13 @@ public enum PartType {
*
* @since 2024/8/25 15:20 v1.0.0
*/
MARKDOWN(MarkdownMessage.class);
MARKDOWN(MarkdownMessage.class),
/**
* 未知消息类型
*
* @since 2024/11/17 17:23 v1.0.5
*/
UNKNOWN(UnknownPart.class);
public final Class<? extends JsonMessagePart> clazz;
PartType(Class<? extends JsonMessagePart> clazz) {

View File

@ -0,0 +1,47 @@
package cn.wzpmc.message.json.parts;
import cn.wzpmc.message.json.JsonMessagePart;
import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 未知消息类型
*
* @author wzp
* @version 1.0.5
* @since 2024/11/17 17:22
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UnknownPart implements JsonMessagePart {
/**
* 类型文本
*
* @since 2024/11/17 17:32 v1.0.5
*/
private String type;
/**
* 消息数据
*
* @since 2024/11/17 17:33 v1.0.5
*/
private JSONObject data;
@Override
public PartType getPartType() {
return PartType.UNKNOWN;
}
@Override
public String getStringPartType() {
return type;
}
@Override
public JSONObject getData() {
return data;
}
}

View File

@ -3,6 +3,7 @@ package cn.wzpmc.utils;
import cn.wzpmc.message.json.JsonMessagePart;
import cn.wzpmc.message.json.parts.At;
import cn.wzpmc.message.json.parts.PartType;
import cn.wzpmc.message.json.parts.UnknownPart;
import cn.wzpmc.message.json.parts.music.MusicType;
import cn.wzpmc.message.json.parts.node.CustomNode;
import cn.wzpmc.message.json.parts.node.SingleNode;
@ -111,9 +112,18 @@ public class CqCodeUtils {
* @since 2024/8/26 14:40 v1.0.0
*/
public static JsonMessagePart parsePart(JSONObject jsonObject) throws InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
PartType type = jsonObject.getObject("type", PartType.class);
PartType type = PartType.UNKNOWN;
PartType resolvedType = jsonObject.getObject("type", PartType.class);
if (resolvedType != null) {
type = resolvedType;
}
Class<? extends JsonMessagePart> clazz = type.clazz;
JSONObject dataObject = jsonObject.getJSONObject("data");
if (type.equals(PartType.UNKNOWN)) {
String stringType = jsonObject.getString("type");
log.warn("发现无法解析的json消息数据数据类型{},数据内容:{}", stringType, dataObject);
return new UnknownPart(stringType, dataObject);
}
if (type.equals(PartType.AT)) {
String string = dataObject.getString("qq");
if (string.equalsIgnoreCase("all")) {

View File

@ -47,7 +47,7 @@ public class WebSocketConnectionHandler {
public void connect(URI websocket) {
log.info("正在连接websocket");
Bootstrap bootstrap = new Bootstrap();
WebSocketClientHandshaker clientHandshaker = WebSocketClientHandshakerFactory.newHandshaker(websocket, WebSocketVersion.V13, null, false, new DefaultHttpHeaders());
WebSocketClientHandshaker clientHandshaker = WebSocketClientHandshakerFactory.newHandshaker(websocket, WebSocketVersion.V13, null, false, new DefaultHttpHeaders(), 65536 * 100);
this.handshakePacketHandler = new HandshakePacketHandler(clientHandshaker);
this.packetHandler = new PacketHandler(this.bot);
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).handler(new WebSocketChannelInitializer(this.packetHandler, this.handshakePacketHandler));

View File

@ -12,6 +12,7 @@ import cn.wzpmc.events.notice.notify.NotifyEvent;
import cn.wzpmc.events.request.RequestEvent;
import cn.wzpmc.message.StringMessage;
import cn.wzpmc.message.json.JsonMessage;
import cn.wzpmc.message.json.JsonMessagePart;
import cn.wzpmc.user.Friend;
import cn.wzpmc.user.IBot;
import cn.wzpmc.user.IUser;
@ -20,10 +21,7 @@ import cn.wzpmc.utils.json.action.ActionReader;
import cn.wzpmc.utils.json.action.ActionWriter;
import cn.wzpmc.utils.json.event.*;
import cn.wzpmc.utils.json.honor.HonorWriter;
import cn.wzpmc.utils.json.message.JsonMessageReader;
import cn.wzpmc.utils.json.message.JsonMessageWriter;
import cn.wzpmc.utils.json.message.StringMessageReader;
import cn.wzpmc.utils.json.message.StringMessageWriter;
import cn.wzpmc.utils.json.message.*;
import cn.wzpmc.utils.json.user.FriendUserReader;
import cn.wzpmc.utils.json.user.GroupUserReader;
import cn.wzpmc.utils.json.user.IBotReader;
@ -49,6 +47,7 @@ public class JsonUtils {
JSON.register(Actions.class, new ActionWriter());
JSON.register(HonorType.class, new HonorWriter());
JSON.register(StringMessage.class, new StringMessageWriter());
JSON.register(JsonMessagePart.class, new JsonMessagePartWriter());
}
/**

View File

@ -0,0 +1,25 @@
package cn.wzpmc.utils.json.message;
import cn.wzpmc.message.json.JsonMessagePart;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;
import java.lang.reflect.Type;
/**
* @author wzp
* @since 2025/2/1 04:19
* @version 1.0.5
**/
public class JsonMessagePartWriter implements ObjectWriter<JsonMessagePart> {
@Override
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
if (object instanceof JsonMessagePart) {
System.out.println(object);
JSONObject from = JSONObject.from(object);
from.put("type", ((JsonMessagePart) object).getStringPartType());
jsonWriter.write(from);
}
}
}

View File

@ -34,7 +34,7 @@ public class JsonMessageWriter implements ObjectWriter<JsonMessage> {
ObjectWriter<?> objectWriter = creator.createObjectWriter(StringMessage.class);
objectWriter.write(jsonWriter, messagePart);
} else {
jsonWriter.writeAny(messagePart);
new JsonMessagePartWriter().write(jsonWriter, messagePart);
}
if (i != size - 1) {
jsonWriter.writeComma();