Skip to content

Commit

Permalink
Update starter/TesterServerConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
kosaka-bun committed Jan 4, 2025
1 parent 0cd14fe commit 5efeab9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package de.honoka.qqrobot.framework.impl.tester.config;

import de.honoka.qqrobot.framework.config.TesterProperties;
import de.honoka.qqrobot.framework.impl.tester.server.TesterServer;
import de.honoka.qqrobot.framework.impl.tester.server.TesterServerConnection;
import jakarta.annotation.Resource;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
Expand All @@ -24,11 +22,6 @@ public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}

@Bean
public TesterServerConnection testerServerConnection(TesterServer server) {
return new TesterServerConnection(server);
}

@Override
public void addResourceHandlers(@NotNull ResourceHandlerRegistry registry) {
registry.addResourceHandler(TesterProperties.WEB_PREFIX + "/**")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.honoka.qqrobot.framework.impl.tester.server;

import de.honoka.qqrobot.framework.api.RobotFramework;
import de.honoka.qqrobot.framework.config.TesterProperties;
import de.honoka.qqrobot.framework.impl.tester.TesterFramework;
import de.honoka.sdk.util.concurrent.ThreadPoolUtils;
import jakarta.annotation.Resource;
import lombok.Getter;
Expand All @@ -26,7 +26,7 @@ public class TesterServer {

@Lazy
@Resource
private RobotFramework framework;
private TesterFramework framework;

@Resource
private TesterProperties testerProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,38 @@
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import de.honoka.qqrobot.framework.AbstractRobotFramework;
import de.honoka.qqrobot.framework.config.TesterProperties;
import de.honoka.qqrobot.framework.impl.tester.TesterFramework;
import de.honoka.qqrobot.framework.impl.tester.model.TesterMessage;
import de.honoka.qqrobot.framework.impl.tester.model.TesterMessageType;
import de.honoka.qqrobot.framework.impl.tester.model.TesterRobotMessage;
import jakarta.annotation.Resource;
import jakarta.websocket.OnClose;
import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;
import lombok.Getter;
import org.springframework.stereotype.Component;

import java.util.Objects;

@ServerEndpoint(TesterProperties.WEB_PREFIX + "/server")
@Getter
@ServerEndpoint(TesterProperties.WEB_PREFIX + "/server")
@Component
public class TesterServerConnection {

private static TesterServer testerServer;

private Session session;

private JSONObject data;

@SuppressWarnings("unused")
public TesterServerConnection() {}

public TesterServerConnection(TesterServer server) {
testerServer = server;

@Resource
public void setTesterServer(TesterServer testerServer) {
TesterServerConnection.testerServer = testerServer;
}

public void sendMessage(TesterMessage message) {
try {
this.session.getBasicRemote().sendText(JSONUtil.toJsonStr(message));
Expand Down Expand Up @@ -148,7 +149,6 @@ private TesterMessage queryOnline(TesterMessage message) {
return res;
}

@SuppressWarnings("unchecked")
private void onGroupMessage(TesterMessage message) {
//收到消息,发送回执
JSONObject resData = new JSONObject();
Expand All @@ -175,15 +175,14 @@ private void onGroupMessage(TesterMessage message) {
}
});
//处理消息
AbstractRobotFramework<TesterRobotMessage> framework = (AbstractRobotFramework<TesterRobotMessage>) testerServer.getFramework();
TesterFramework framework = testerServer.getFramework();
framework.getFrameworkCallback().onGroupMsg(
testerServer.getTesterProperties().getGroupNumber(),
data.getLong("qq"),
framework.typedTransform(TesterRobotMessage.of(content))
);
}

@SuppressWarnings("unchecked")
private void onPrivateMessage(TesterMessage message) {
//收到消息,发送回执
JSONObject resData = new JSONObject();
Expand All @@ -195,7 +194,7 @@ private void onPrivateMessage(TesterMessage message) {
);
//处理消息
JSONArray content = message.getData().getJSONArray("content");
AbstractRobotFramework<TesterRobotMessage> framework = (AbstractRobotFramework<TesterRobotMessage>) testerServer.getFramework();
TesterFramework framework = testerServer.getFramework();
framework.getFrameworkCallback().onPrivateMsg(
data.getLong("qq"),
framework.typedTransform(TesterRobotMessage.of(content))
Expand Down

0 comments on commit 5efeab9

Please sign in to comment.