From 28b2fad7b612e3b1ff4684da022788ba93a3cd77 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Fri, 5 Apr 2024 08:46:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0mj=20web=20socket=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/midjourney/demo/wss/Main.java | 39 -------------- .../framework/ai/image/MjWebSocketTests.java | 51 +++++++++++++++++++ 2 files changed, 51 insertions(+), 39 deletions(-) delete mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/demo/wss/Main.java create mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/MjWebSocketTests.java diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/demo/wss/Main.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/demo/wss/Main.java deleted file mode 100644 index 25a332702..000000000 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/demo/wss/Main.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.framework.ai.midjourney.demo.wss; - -import cn.iocoder.yudao.framework.ai.midjourney.demo.jad.DiscordAccount; -import cn.iocoder.yudao.framework.ai.midjourney.demo.wss.user.SpringUserWebSocketStarter; -import cn.iocoder.yudao.framework.ai.midjourney.demo.wss.user.UserMessageListener; - -import java.util.Scanner; - -/** - * author: fansili - * time: 2024/4/3 16:40 - */ -public class Main { - - public static void main(String[] args) { - String token = "NTY5MDY4NDAxNzEyOTU1Mzky.G4-Fu0.MzD-7ll-ElbXTTgDPHF-WS_UyhMAfbKN3WyyBc"; - - - DiscordHelper discordHelper = new DiscordHelper(); - DiscordAccount discordAccount = new DiscordAccount(); - discordAccount.setUserToken(token); - discordAccount.setGuildId("1221445697157468200"); - discordAccount.setChannelId("1221445862962630706"); - - - var messageListener = new UserMessageListener(); - var webSocketStarter = new SpringUserWebSocketStarter(discordHelper.getWss(), null, discordAccount, messageListener); - - try { - webSocketStarter.start(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - - Scanner scanner = new Scanner(System.in); - scanner.nextLine(); - } -} diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/MjWebSocketTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/MjWebSocketTests.java new file mode 100644 index 000000000..177b7c733 --- /dev/null +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/MjWebSocketTests.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.framework.ai.image; + +import cn.hutool.core.io.FileUtil; +import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig; +import cn.iocoder.yudao.framework.ai.midjourney.demo.wss.user.MjMessageListener; +import cn.iocoder.yudao.framework.ai.midjourney.demo.wss.user.MjWebSocketStarter; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +/** + * author: fansili + * time: 2024/4/3 16:40 + */ +public class MjWebSocketTests { + + private MidjourneyConfig midjourneyConfig; + + @Before + public void setup() { + String token = "OTcwNDc3NzQxMjUyMTY5NzI4.GJcVxa.VrzMii8dsHOJAPZn4Mw8GuEo7_nIUJij9JIHD4"; + Map requestTemplates = new HashMap<>(); + List files = FileUtil.loopFiles("/Users/fansili/projects/github/ruoyi-vue-pro/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/resources/http-body"); + for (File file : files) { + requestTemplates.put(file.getName().replace(".json", ""), FileUtil.readUtf8String(file)); + } + this.midjourneyConfig = new MidjourneyConfig(token, "1225414986084388926", "1225414986587832385", requestTemplates); + } + + @Test + public void startSocketTest() { + String wssUrl = "wss://gateway.discord.gg"; + var messageListener = new MjMessageListener(midjourneyConfig); + var webSocketStarter = new MjWebSocketStarter(wssUrl, null, midjourneyConfig, messageListener); + + try { + webSocketStarter.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + + Scanner scanner = new Scanner(System.in); + scanner.nextLine(); + } +}