├── .gitignore ├── LICENSE ├── README.md ├── midjourney-bot-api-java ├── README.en.md ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── qjc │ │ └── midjourney │ │ ├── MidjourneyJavaApplication.java │ │ ├── config │ │ ├── CallBackConfig.java │ │ ├── DiscordClientInitializer.java │ │ ├── DiscordConfig.java │ │ └── MidjourneyBotConfiguration.java │ │ ├── controller │ │ ├── GptTurboDto.java │ │ ├── GptTurboModel.java │ │ ├── MidjourneyController.java │ │ ├── Result.java │ │ └── TestController.java │ │ ├── dto │ │ └── RequestTrigger.java │ │ ├── enums │ │ └── Scene.java │ │ ├── event │ │ └── DiscordEventHandler.java │ │ ├── request │ │ ├── CallBackData.java │ │ ├── ReqMaxUpscaleData.java │ │ ├── ReqMaxUpscaleDiscord.java │ │ ├── ReqReSetUpscaleData.java │ │ ├── ReqReSetUpscaleDiscord.java │ │ ├── ReqUpscaleData.java │ │ ├── ReqUpscaleDiscord.java │ │ ├── ReqVariationData.java │ │ ├── ReqVariationDiscord.java │ │ ├── RequestMidjourneyApplicationCommand.java │ │ ├── RequestMidjourneyData.java │ │ ├── RequestMidjourneyDto.java │ │ ├── RequestMidjourneyOptions.java │ │ └── RequestMidjourneyOptionss.java │ │ ├── result │ │ └── ResponseData.java │ │ └── service │ │ ├── DiscordInteractionService.java │ │ ├── MidjourneyService.java │ │ └── impl │ │ ├── ChatServiceImpl.java │ │ ├── DiscordInteractionServiceImpl.java │ │ └── MidjourneyServiceImpl.java │ └── resources │ └── application.yml └── source ├── application.yml ├── image.png ├── service.sh ├── 小程序码.jpg └── 赞赏码.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | *.class 24 | *.log 25 | *.ctxt 26 | *.mtj.tmp/ 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.rar 32 | *.iml 33 | *.mvn 34 | *mvnw 35 | .classpath 36 | .project 37 | .settings 38 | target 39 | build 40 | .idea 41 | .gradle 42 | HELP.md 43 | LICENSE -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | - 使用SpringBoot 3.x+JDK17实现 midjourney接入功能 2 | - 最近发现很多人不知道如何接入midjourney绘图,因此我开发了这个中间件 3 | 4 | ## 开源不易 5 | 6 | 7 | 8 | ​ 9 | 10 | 老板打赏赞赏码 11 | 12 | ## 项目背景介绍 13 | 14 | ### 需求产生 15 | 16 | 由于接入midjourney绘图,官方没有提供API接口,很多人问我怎么接入midjourney绘图,我通过文章查找以及抓取生成图片的接口,使用官方接口请求生成图片,通过Discord机器人监听频道获取信息,进行生成图片。实现了较简单的功能: 17 | 18 | ### 功能列表: 19 | 20 | 1. GPT翻译。 21 | 2. generate:生成图片。 22 | 3. upscale:选中对应的图片变大。 23 | 4. variation:选中其中的一张图,生成四张相似的。 24 | 5. reset:按照你的提示词重新生成。 25 | 6. maxUpscale:后只有一张图返回,此时你是使用这张图再生成四张类似的。 26 | 27 | 28 | 29 | ### 配置信息 application.yml 30 | 31 | ``` 32 | discord: 33 | user-token: 用户token 34 | bot-token: 机器人token 35 | server-id: 服务id 36 | channel-id: 频道id 37 | call-back: 38 | url: 回调地址 39 | 40 | chatgpt: 41 | token: 用户token chagpt的可以不填写此处用来翻译,也可以自己翻译好,之所以没有整合到一块,考虑着通用模块 42 | ``` 43 | 44 | ### 获取配置信息 45 | 46 | 请看这篇文章 47 | 48 | https://www.yuque.com/xiaoqi-vgsag/bn9t8h/wzg5kluuzzgd22m7?singleDoc# 《web服务接入discord midjourney》 49 | 50 | 51 | 52 | ### 项目流程图 53 | 54 | ![image.png](https://gitee.com/qi_jianchun/midjourney-bot-api/raw/master/source/image.png) 55 | 56 | 57 | 58 | ## 安装部署 59 | 60 | 以下方案针对于Linux服务器: 61 | 62 | 安装JDK17环境 此处可以不按照我的方式来 63 | 64 | ``` 65 | cd /usr/local 66 | wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz 67 | tar -zxvf jdk-17_linux-x64_bin.tar.gz #解压 68 | mv jdk-17_linux-x64_bin jdk17 #修改名称 69 | ------------------------------------------------------ 70 | #配置jdk环境变量 71 | #/etc/profile文件的改变会涉及到系统的环境,也就是有关Linux环境变量的东西 72 | #所以,我们要将jdk配置到/etc/profile,才可以在任何一个目录访问jdk 73 | 74 | vim /etc/profile 75 | 76 | #按i进入编辑,在profile文件尾部添加如下内容 77 | export JAVA_HOME=/usr/local/jdk17 #jdk安装目录 78 | 79 | export JRE_HOME=${JAVA_HOME}/jre 80 | 81 | export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH 82 | 83 | export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin 84 | 85 | export PATH=$PATH:${JAVA_PATH} 86 | 87 | --------------------------------------------------------------- 88 | #Esc --> :wq 89 | #保存并退出编辑 90 | #通过命令source /etc/profile让profile文件立即生效 91 | source /etc/profile #环境完成 92 | 93 | java -version #显示版本号说明成功 94 | ``` 95 | 96 | 上传jar包 97 | 98 | ``` 99 | 100 | cd /usr/local/ 101 | mkdir project 102 | cd project 103 | 将 jar包上传 source下的service.sh与application.yml 放在同级目录 104 | vim application.yml 进行将那些记录的token 频道 卸载yml即可 105 | 106 | sh service.sh start 107 | ``` 108 | 109 | 扫码体验mj 110 | 111 | 赞赏码 -------------------------------------------------------------------------------- /midjourney-bot-api-java/README.en.md: -------------------------------------------------------------------------------- 1 | # midjourney-bot-api-java 2 | 3 | #### Description 4 | {**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} 5 | 6 | #### Software Architecture 7 | Software architecture description 8 | 9 | #### Installation 10 | 11 | 1. xxxx 12 | 2. xxxx 13 | 3. xxxx 14 | 15 | #### Instructions 16 | 17 | 1. xxxx 18 | 2. xxxx 19 | 3. xxxx 20 | 21 | #### Contribution 22 | 23 | 1. Fork the repository 24 | 2. Create Feat_xxx branch 25 | 3. Commit your code 26 | 4. Create Pull Request 27 | 28 | 29 | #### Gitee Feature 30 | 31 | 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md 32 | 2. Gitee blog [blog.gitee.com](https://blog.gitee.com) 33 | 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) 34 | 4. The most valuable open source project [GVP](https://gitee.com/gvp) 35 | 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 36 | 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) 37 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/README.md: -------------------------------------------------------------------------------- 1 | - 使用SpringBoot 3.x+JDK17实现 midjourney接入功能 2 | - 最近发现很多人不知道如何接入midjourney绘图,因此我开发了这个中间件 3 | 4 | ## 项目背景介绍 5 | 6 | ### 需求产生 7 | 8 | 由于接入midjourney绘图,官方没有提供API接口,很多人问我怎么接入midjourney绘图,我通过文章查找以及抓取生成图片的接口,使用官方接口请求生成图片,通过Discord机器人监听频道获取信息,进行生成图片。实现了较简单的功能: 9 | 10 | ### 功能列表: 11 | 12 | 1. GPT翻译。 13 | 2. generate:生成图片。 14 | 3. upscale:选中对应的图片变大。 15 | 4. variation:选中其中的一张图,生成四张相似的。 16 | 5. reset:按照你的提示词重新生成。 17 | 6. maxUpscale:后只有一张图返回,此时你是使用这张图再生成四张类似的。 18 | 19 | 20 | 21 | ### 配置信息 application.yml 22 | 23 | ``` 24 | discord: 25 | user-token: 用户token 26 | bot-token: 机器人token 27 | server-id: 服务id 28 | channel-id: 频道id 29 | call-back: 30 | url: 回调地址 31 | 32 | chatgpt: 33 | token: 用户token chagpt的可以不填写此处用来翻译,也可以自己翻译好,之所以没有整合到一块,考虑着通用模块 34 | ``` 35 | 36 | ### 获取配置信息 37 | 38 | 请看这篇文章 39 | 40 | https://www.yuque.com/xiaoqi-vgsag/bn9t8h/wzg5kluuzzgd22m7?singleDoc# 《web服务接入discord midjourney》 41 | 42 | 43 | 44 | ### 项目流程图 45 | 46 | ![image.png](https://cdn.nlark.com/yuque/0/2023/png/21704577/1683654109570-3baee4f8-2fd0-4fbf-a544-ef29bd281927.png) 47 | 48 | 49 | 50 | ## 安装部署 51 | 52 | 以下方案针对于Linux服务器: 53 | 54 | - 安装JDK17环境 此处可以不按照我的方式来 55 | 56 | 下载 *wget h*ttps://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz 57 | 58 | 安装jdk环境 参考 https://note.youdao.com/s/btPICkAZ 59 | 60 | 然后sh service.sh start 61 | 62 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.0.6 9 | 10 | 11 | com.qjc 12 | midjourney-bot-api-java 13 | 0.0.1-SNAPSHOT 14 | midjourney-bot-api-java 15 | midjourney-bot-api-java 16 | 17 | 17 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-configuration-processor 27 | true 28 | 29 | 30 | 35 | 36 | net.dv8tion 37 | JDA 38 | 5.0.0-alpha.12 39 | 40 | 41 | com.alibaba 42 | fastjson 43 | 2.0.25 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-webflux 48 | 49 | 50 | org.apache.commons 51 | commons-pool2 52 | 53 | 54 | org.apache.commons 55 | commons-lang3 56 | 57 | 58 | org.apache.httpcomponents 59 | httpclient 60 | 4.5.13 61 | 62 | 63 | org.projectlombok 64 | lombok 65 | true 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-starter-test 70 | test 71 | 72 | 73 | jakarta.validation 74 | jakarta.validation-api 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-maven-plugin 83 | 84 | 85 | 86 | org.projectlombok 87 | lombok 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/MidjourneyJavaApplication.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MidjourneyJavaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MidjourneyJavaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/config/CallBackConfig.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | /** 7 | * The type CallBackConfig config. 8 | * 9 | * @author qjch 10 | * @email 1071643762@qq.com 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = "call-back") 14 | @Data 15 | public class CallBackConfig { 16 | private String url; 17 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/config/DiscordClientInitializer.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.config; 2 | 3 | import com.qjc.midjourney.event.DiscordEventHandler; 4 | import jakarta.annotation.PostConstruct; 5 | import net.dv8tion.jda.api.JDA; 6 | import net.dv8tion.jda.api.JDABuilder; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.security.auth.login.LoginException; 11 | 12 | @Component 13 | public class DiscordClientInitializer { 14 | private final DiscordConfig discordConfig; 15 | private JDA jda; 16 | private DiscordEventHandler discordEventHandler; 17 | 18 | @Autowired 19 | public DiscordClientInitializer(DiscordConfig discordConfig,DiscordEventHandler discordEventHandler) { 20 | this.discordConfig = discordConfig; 21 | this.discordEventHandler = discordEventHandler; 22 | } 23 | 24 | @PostConstruct 25 | public void init() throws LoginException { 26 | jda = JDABuilder 27 | .createDefault(discordConfig.getBotToken()) 28 | .addEventListeners(discordEventHandler).build(); 29 | } 30 | 31 | public JDA getJda() { 32 | return jda; 33 | } 34 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/config/DiscordConfig.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * The type DiscordConfig config. 9 | * 10 | * @author qjch 11 | * @email 1071643762@qq.com 12 | */ 13 | @Configuration 14 | @ConfigurationProperties(prefix = "discord") 15 | @Data 16 | public class DiscordConfig { 17 | private String userToken; 18 | private String botToken; 19 | private String serverId; 20 | private String channelId; 21 | } 22 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/config/MidjourneyBotConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @Data 9 | public class MidjourneyBotConfiguration { 10 | 11 | private final DiscordConfig discordConfig; 12 | 13 | private final CallBackConfig callBackConfig; 14 | 15 | @Autowired 16 | public MidjourneyBotConfiguration(DiscordConfig discordConfig, CallBackConfig callBackConfig) { 17 | this.discordConfig = discordConfig; 18 | this.callBackConfig = callBackConfig; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/controller/GptTurboDto.java: -------------------------------------------------------------------------------- 1 | 2 | package com.qjc.midjourney.controller; 3 | 4 | 5 | import jakarta.validation.constraints.NotEmpty; 6 | import lombok.Getter; 7 | import lombok.Setter; 8 | import lombok.ToString; 9 | 10 | import java.util.List; 11 | 12 | 13 | @Getter 14 | @Setter 15 | @ToString 16 | public class GptTurboDto { 17 | 18 | @NotEmpty(message = "消息数据不能为空") 19 | private List messages; 20 | 21 | 22 | public static GptTurboModel convertToGptTurboModel(GptTurboDto item) { 23 | if (item == null) { 24 | return null; 25 | } 26 | GptTurboModel result = new GptTurboModel(); 27 | result.setMessages(item.getMessages()); 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/controller/GptTurboModel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author 明明不是下雨天 3 | */ 4 | package com.qjc.midjourney.controller; 5 | 6 | import lombok.Data; 7 | import lombok.experimental.Accessors; 8 | 9 | import java.util.List; 10 | 11 | 12 | /** 13 | * The type Gpt alpha model. 14 | */ 15 | @Data 16 | @Accessors(chain = true) 17 | public class GptTurboModel { 18 | 19 | 20 | /** 21 | * The Model. 22 | */ 23 | private String model = "gpt-3.5-turbo"; 24 | 25 | /** 26 | * The Top p. 27 | */ 28 | private Double top_p = 0.9; 29 | 30 | /** 31 | * The Stream. 32 | */ 33 | private boolean stream = false; 34 | 35 | /** 36 | * The Messages. 37 | */ 38 | private List messages; 39 | 40 | /** 41 | * The Max tokens. 42 | */ 43 | private Integer max_tokens = 2048; 44 | 45 | 46 | /** 47 | * The type Messages. 48 | * 49 | * @author bdth 50 | * @email 2074055628 @qq.om 51 | */ 52 | @Data 53 | public static class Messages { 54 | 55 | /** 56 | * The Role. 57 | */ 58 | private String role; 59 | 60 | /** 61 | * The Content. 62 | */ 63 | private String content; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/controller/MidjourneyController.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.controller; 2 | 3 | import com.qjc.midjourney.dto.RequestTrigger; 4 | import com.qjc.midjourney.result.ResponseData; 5 | import com.qjc.midjourney.service.MidjourneyService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | @RestController 15 | @RequestMapping("/midjourney") 16 | public class MidjourneyController { 17 | 18 | private final MidjourneyService midjourneyService; 19 | 20 | @Autowired 21 | public MidjourneyController(MidjourneyService midjourneyService) { 22 | this.midjourneyService = midjourneyService; 23 | } 24 | 25 | @PostMapping 26 | public ResponseEntity midjourneyBot(@RequestBody RequestTrigger requestTrigger) { 27 | try { 28 | midjourneyService.executeAction(requestTrigger); 29 | return ResponseEntity.ok(ResponseData.builder() 30 | .message("success") 31 | .build()); 32 | } catch (Exception e) { 33 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ResponseData.builder() 34 | .message(e.getMessage()) 35 | .build()); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/controller/Result.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.controller; 2 | 3 | 4 | import java.io.Serializable; 5 | import java.util.Iterator; 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | 10 | /** 11 | * The type Result. 12 | * 13 | * @email 1071643762 @qq.om 14 | */ 15 | @SuppressWarnings("all") 16 | public class Result extends LinkedHashMap implements Serializable { 17 | 18 | 19 | /** 20 | * The constant serialVersionUID. 21 | * 22 | * @email 1071643762 @qq.om 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | 26 | /** 27 | * The constant CODE_SUCCESS. 28 | * 29 | * @email 1071643762 @qq.om 30 | */ 31 | public static final int CODE_SUCCESS = 200; 32 | 33 | /** 34 | * The constant CODE_ERROR. 35 | * 36 | * @email 2074055628 @qq.om 37 | */ 38 | public static final int CODE_ERROR = 500; 39 | 40 | 41 | /** 42 | * Instantiates a new Result. 43 | * 44 | * @email 1071643762 @qq.om 45 | */ 46 | public Result() { 47 | } 48 | 49 | /** 50 | * Instantiates a new Result. 51 | * 52 | * @param code the code 53 | * @param msg the msg 54 | * @param data the data 55 | * @email 1071643762 @qq.om 56 | */ 57 | public Result(int code, String msg, Object data) { 58 | this.setCode(code); 59 | this.setMsg(msg); 60 | this.setData(data); 61 | } 62 | 63 | 64 | /** 65 | * Instantiates a new Result. 66 | * 67 | * @param map the map 68 | * @author bdth 69 | * @email 1071643762 @qq.om 70 | */ 71 | public Result(Map map) { 72 | this.setMap(map); 73 | } 74 | 75 | /** 76 | * Gets code. 77 | * 78 | * @return the code 79 | * @author bdth 80 | * @email 1071643762 @qq.om 81 | */ 82 | public Integer getCode() { 83 | return (Integer) this.get("code"); 84 | } 85 | 86 | /** 87 | * Gets msg. 88 | * 89 | * @return the msg 90 | * @author bdth 91 | * @email 1071643762 @qq.om 92 | */ 93 | public String getMsg() { 94 | return (String) this.get("msg"); 95 | } 96 | 97 | 98 | /** 99 | * Gets data. 100 | * 101 | * @return the data 102 | * @email 1071643762 @qq.om 103 | */ 104 | public Object getData() { 105 | return this.get("data"); 106 | } 107 | 108 | 109 | /** 110 | * Sets code. 111 | * 112 | * @param code the code 113 | * @return the code 114 | * @email 1071643762 @qq.om 115 | */ 116 | public Result setCode(int code) { 117 | this.put("code", code); 118 | return this; 119 | } 120 | 121 | 122 | /** 123 | * Sets msg. 124 | * 125 | * @param msg the msg 126 | * @return the msg 127 | * @email 1071643762 @qq.om 128 | */ 129 | public Result setMsg(String msg) { 130 | this.put("msg", msg); 131 | return this; 132 | } 133 | 134 | 135 | /** 136 | * Sets data. 137 | * 138 | * @param data the data 139 | * @return the data 140 | * @email 1071643762 @qq.om 141 | */ 142 | public Result setData(Object data) { 143 | this.put("data", data); 144 | return this; 145 | } 146 | 147 | /** 148 | * Set result. 149 | * 150 | * @param key the key 151 | * @param data the data 152 | * @return the result 153 | * @email 1071643762 @qq.om 154 | */ 155 | public Result set(String key, Object data) { 156 | this.put(key, data); 157 | return this; 158 | } 159 | 160 | 161 | /** 162 | * Sets map. 163 | * 164 | * @param map the map 165 | * @return the map 166 | * @email 1071643762 @qq.om 167 | */ 168 | public Result setMap(Map map) { 169 | Iterator var2 = map.keySet().iterator(); 170 | 171 | while (var2.hasNext()) { 172 | String key = (String) var2.next(); 173 | this.put(key, map.get(key)); 174 | } 175 | 176 | return this; 177 | } 178 | 179 | /** 180 | * Ok result. 181 | * 182 | * @return the result 183 | * @author bdth 184 | * @email 1071643762 @qq.om 185 | */ 186 | public static Result ok() { 187 | return new Result(CODE_SUCCESS, "操作成功", (Object) null); 188 | } 189 | 190 | 191 | /** 192 | * Ok result. 193 | * 194 | * @param msg the msg 195 | * @return the result 196 | * @email 1071643762 @qq.om 197 | */ 198 | public static Result ok(String msg) { 199 | return new Result(CODE_SUCCESS, msg, (Object) null); 200 | } 201 | 202 | 203 | /** 204 | * Code result. 205 | * 206 | * @param code the code 207 | * @return the result 208 | * @email 1071643762 @qq.om 209 | */ 210 | public static Result code(int code) { 211 | return new Result(code, (String) null, (Object) null); 212 | } 213 | 214 | 215 | /** 216 | * Data result. 217 | * 218 | * @param data the data 219 | * @return the result 220 | * @email 1071643762 @qq.om 221 | */ 222 | public static Result data(Object data) { 223 | return new Result(CODE_SUCCESS, "ok", data); 224 | } 225 | 226 | 227 | /** 228 | * Error result. 229 | * 230 | * @return the result 231 | * @author bdth 232 | * @email 1071643762 @qq.om 233 | */ 234 | public static Result error() { 235 | return new Result(CODE_ERROR, "操作失败", (Object) null); 236 | } 237 | 238 | 239 | /** 240 | * Error result. 241 | * 242 | * @return the result 243 | * @email 1071643762 @qq.om 244 | */ 245 | public static Result error(final String msg, final Integer code) { 246 | return new Result(code, msg, (Object) null); 247 | } 248 | 249 | 250 | /** 251 | * Error result. 252 | * 253 | * @param msg the msg 254 | * @return the result 255 | * @email 1071643762 @qq.om 256 | */ 257 | public static Result error(String msg) { 258 | return new Result(CODE_ERROR, msg, (Object) null); 259 | } 260 | 261 | 262 | /** 263 | * Build result. 264 | * 265 | * @param code the code 266 | * @param msg the msg 267 | * @param data the data 268 | * @return the result 269 | * @email 1071643762 @qq.om 270 | */ 271 | public static Result build(int code, String msg, Object data) { 272 | return new Result(code, msg, data); 273 | } 274 | 275 | 276 | /** 277 | * To string string. 278 | * 279 | * @return the string 280 | * @email 1071643762 @qq.om 281 | */ 282 | public String toString() { 283 | return "{\"code\": " + this.getCode() + ", \"msg\": " + this.transValue(this.getMsg()) + ", \"data\": " + this.transValue(this.getData()) + "}"; 284 | } 285 | 286 | 287 | /** 288 | * Trans value string. 289 | * 290 | * @param value the value 291 | * @return the string 292 | * @email 1071643762 @qq.om 293 | */ 294 | private String transValue(Object value) { 295 | return value instanceof String ? "\"" + value + "\"" : String.valueOf(value); 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.controller; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson2.JSONObject; 5 | import com.qjc.midjourney.service.impl.ChatServiceImpl; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.validation.annotation.Validated; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @author qjc 19 | * @description TODO 20 | * @date 2023-05-06 18:02 21 | */ 22 | @RestController 23 | @RequestMapping("/test") 24 | @Slf4j 25 | public class TestController { 26 | /** 27 | * The Gpt service. 28 | */ 29 | @Autowired 30 | private ChatServiceImpl chatServiceimpl; 31 | 32 | @PostMapping("/test") 33 | public JSONObject jsonObject (@RequestBody JSONObject jsonObject){ 34 | log.info("/test"+jsonObject.toString()); 35 | return jsonObject; 36 | 37 | } 38 | 39 | /** 40 | * Completions result. 41 | * 42 | * @param dto the dto 43 | * @return the result 44 | */ 45 | 46 | @PostMapping(value = "/chat/completions", name = "GPT-Turbo 3.5", produces = MediaType.APPLICATION_JSON_VALUE) 47 | public Result completions(@Validated @RequestBody final GptTurboDto dto) { 48 | log.info("==================>"+dto.toString()); 49 | try { 50 | final GptTurboModel model = GptTurboDto.convertToGptTurboModel(dto); 51 | List messages = model.getMessages(); 52 | int listSize = messages.size(); 53 | int startIndex = listSize > 5 ? listSize - 5 : 0; 54 | List lastFiveMessages = messages.subList(startIndex, listSize); 55 | model.setMessages(lastFiveMessages); 56 | log.info("List===================>"+ JSON.toJSONString(lastFiveMessages)); 57 | return Result.data(chatServiceimpl.build(model, "chat/completions")); 58 | } catch (Exception e) { 59 | log.error("Failed to fetch GPT3.5 model API /chat/completions"+e.getMessage()+dto.toString()); 60 | return Result.error(e.getMessage()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/dto/RequestTrigger.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | @Accessors(chain = true) 14 | public class RequestTrigger { 15 | private String type; 16 | private String discordMsgId; 17 | private String msgHash; 18 | private String prompt; 19 | private int index; 20 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/enums/Scene.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.enums; 2 | /** 3 | * The type Scene . 4 | * 5 | * @author qjch 6 | * @email 1071643762@qq.com 7 | */ 8 | public enum Scene { 9 | FIRST_TRIGGER, 10 | GENERATE_END, 11 | GENERATE_EDIT_ERROR 12 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/event/DiscordEventHandler.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.event; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.qjc.midjourney.config.DiscordConfig; 5 | import com.qjc.midjourney.config.MidjourneyBotConfiguration; 6 | import com.qjc.midjourney.enums.Scene; 7 | import lombok.extern.slf4j.Slf4j; 8 | import net.dv8tion.jda.api.MessageBuilder; 9 | import net.dv8tion.jda.api.OnlineStatus; 10 | import net.dv8tion.jda.api.Permission; 11 | import net.dv8tion.jda.api.entities.*; 12 | 13 | import net.dv8tion.jda.api.events.message.MessageReceivedEvent; 14 | import net.dv8tion.jda.api.events.message.MessageUpdateEvent; 15 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Component; 18 | import org.springframework.web.reactive.function.client.WebClient; 19 | 20 | import java.time.LocalDateTime; 21 | import java.time.format.DateTimeFormatter; 22 | import java.util.EnumSet; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | /** 27 | * The type DiscordEventHandler event trigger . 28 | * 29 | * @author qjch 30 | * @email 1071643762@qq.com 31 | */ 32 | @Component 33 | @Slf4j 34 | public class DiscordEventHandler extends ListenerAdapter { 35 | 36 | private final MidjourneyBotConfiguration midjourneyBotConfiguration; 37 | private final WebClient webClient; 38 | 39 | @Autowired 40 | public DiscordEventHandler(MidjourneyBotConfiguration midjourneyBotConfiguration, WebClient.Builder webClientBuilder) { 41 | this.midjourneyBotConfiguration = midjourneyBotConfiguration; 42 | this.webClient = webClientBuilder.build(); 43 | } 44 | 45 | @Override 46 | public void onMessageReceived(MessageReceivedEvent event) { 47 | Message message = event.getMessage(); 48 | MessageChannel channel = event.getChannel(); 49 | User author = event.getAuthor(); 50 | 51 | if (!channel.getId().equals(midjourneyBotConfiguration.getDiscordConfig().getChannelId()) || 52 | author.getId().equals(event.getJDA().getSelfUser().getId())) { 53 | return; 54 | } 55 | 56 | if (message.getContentRaw().contains("(Waiting to start)") && !message.getContentRaw().contains("Rerolling **")) { 57 | trigger(message.getContentRaw(), Scene.FIRST_TRIGGER); 58 | return; 59 | } 60 | 61 | for (Message.Attachment attachment : message.getAttachments()) { 62 | if (attachment.isImage()) { 63 | replay(attachment); 64 | return; 65 | } 66 | } 67 | } 68 | private void test(){ 69 | /* JSONObject jsonObject =new JSONObject(); 70 | jsonObject.put("id", attachment.getId()); 71 | jsonObject.put("url", attachment.getUrl()); 72 | jsonObject.put("proxyUrl", attachment.getProxyUrl()); 73 | jsonObject.put("fileName", attachment.getFileName()); 74 | jsonObject.put("contentType", attachment.getContentType()); 75 | jsonObject.put("description", attachment.getDescription()); 76 | jsonObject.put("size", attachment.getSize()); 77 | jsonObject.put("height", attachment.getHeight()); 78 | jsonObject.put("width", attachment.getWidth());*/ 79 | } 80 | 81 | @Override 82 | public void onMessageUpdate(MessageUpdateEvent event) { 83 | Message message = event.getMessage(); 84 | MessageChannel channel = event.getChannel(); 85 | User author = event.getAuthor(); 86 | 87 | if (!channel.getId().equals(midjourneyBotConfiguration.getDiscordConfig() 88 | .getChannelId()) || author.getId().equals(event.getJDA().getSelfUser().getId())) { 89 | return; 90 | } 91 | 92 | if (message.getContentRaw().contains("(Stopped)")) { 93 | trigger(message.getContentRaw(), Scene.GENERATE_EDIT_ERROR); 94 | } 95 | } 96 | 97 | private void replay(Message.Attachment attachment ) { 98 | /* //获取服务器(公会)信息 99 | Guild guild = message.getGuild(); 100 | String guildId = guild.getId(); 101 | String guildName = guild.getName(); 102 | 103 | System.out.println("guildId = " + guildId);//输出服务器(公会)id 104 | System.out.println("guildName = " + guildName);//输出服务器(公会)名称 105 | 106 | //获取频道信息 107 | MessageChannel channel = message.getChannel(); 108 | String channelId = channel.getId(); 109 | String channelName = channel.getName(); 110 | ChannelType channelType = channel.getType(); 111 | System.out.println("channelId = " + channelId);//输出频道id 112 | System.out.println("channelName = " + channelName);//输出频道名称 113 | System.out.println("channelType = " + channelType);//输出频道类型 114 | 115 | //获取发消息人 116 | Member member = message.getMember(); 117 | String memberId = member.getId(); 118 | String memberNickname = member.getNickname(); 119 | String memberEffectiveName = member.getEffectiveName(); 120 | List memberRoles = member.getRoles(); 121 | EnumSet memberPermissions = member.getPermissions(); 122 | OnlineStatus memberOnlineStatus = member.getOnlineStatus(); 123 | System.out.println("memberId = " + memberId);//输出发送消息人的id 124 | System.out.println("memberNickname = " + memberNickname);//输出发送消息人的昵称 125 | System.out.println("memberEffectiveName = " + memberEffectiveName);//输出发送消息人的有效名称 126 | System.out.println("memberRoles = " + memberRoles);//输出发送消息人的角色列表 127 | System.out.println("memberPermissions = " + memberPermissions);//输出发送消息人的权限列表 128 | System.out.println("memberOnlineStatus = " + memberOnlineStatus);//输出发送消息人的在线状态 129 | 130 | //获取消息信息 131 | String messageId = message.getId(); 132 | String messageContentRaw = message.getContentRaw(); 133 | MessageType messageType = message.getType(); 134 | System.out.println("messageId = " + messageId);//输出消息id 135 | System.out.println("messageContentRaw = " + messageContentRaw);//输出消息内容 136 | System.out.println("messageType = " + messageType);//输出消息类型*/ 137 | //截取 文件名称 hrldaiz_Cute_Magical_Flying_Dogs_fantasy_art_drawn_by_Disney_co_450bfebf-ff51-4ed3-83ec-273c665f4414.png 138 | String fileName = attachment.getFileName(); 139 | String[] keys = fileName.split("_", -1); 140 | 141 | com.alibaba.fastjson.JSONObject jsonObject =new JSONObject(); 142 | jsonObject.put("id", attachment.getId()); 143 | jsonObject.put("url", attachment.getUrl()); 144 | jsonObject.put("proxyUrl", attachment.getProxyUrl()); 145 | jsonObject.put("fileName", attachment.getFileName()); 146 | jsonObject.put("contentType", attachment.getContentType()); 147 | jsonObject.put("description", attachment.getDescription()); 148 | jsonObject.put("size", attachment.getSize()); 149 | jsonObject.put("height", attachment.getHeight()); 150 | jsonObject.put("width", attachment.getWidth()); 151 | 152 | String images = keys[keys.length - 1]; 153 | String msgHash = images.split("\\.")[0]; 154 | jsonObject.put("msgHash",msgHash); 155 | 156 | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 157 | LocalDateTime time = LocalDateTime.now(); 158 | String localTime = df.format(time); 159 | jsonObject.put("date",localTime); 160 | 161 | //拼接路径,数据库中可以直接保存该路径,返回前端,前端即可访问 162 | log.info("MessageMetadataRegistry:"+jsonObject.toJSONString()); 163 | Map body = new HashMap<>(); 164 | body.put("discord", jsonObject); 165 | body.put("type", Scene.GENERATE_END); 166 | request(body); 167 | } 168 | 169 | 170 | 171 | 172 | 173 | private void trigger(String content, Scene scene) { 174 | Map body = new HashMap<>(); 175 | body.put("content", content); 176 | body.put("type", scene); 177 | request(body); 178 | } 179 | 180 | private void request(Map params) { 181 | webClient.post() 182 | .uri(midjourneyBotConfiguration.getCallBackConfig().getUrl()) 183 | .bodyValue(params) 184 | .retrieve() 185 | .bodyToMono(String.class) 186 | .subscribe(response -> log.info("Upscale response: " + response), 187 | error -> log.error("Error: " + error.getMessage())); 188 | } 189 | 190 | 191 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/CallBackData.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | import net.dv8tion.jda.api.entities.Guild; 9 | import net.dv8tion.jda.api.entities.Member; 10 | import net.dv8tion.jda.api.entities.MessageChannel; 11 | import net.dv8tion.jda.api.entities.MessageType; 12 | 13 | /** 14 | * @author qjc 15 | * @description TODO 16 | * @date 2023-05-06 17:17 17 | */ 18 | 19 | @Data 20 | 21 | @Builder 22 | @Accessors(chain = true) 23 | public class CallBackData { 24 | 25 | /* private CallBackGuild callBackGuild; 26 | 27 | private CallBackMessageChannel callBackMessageChannel; 28 | 29 | private CallBackMember callBackMember; 30 | 31 | private CallBackMessageType callBackMessageType; 32 | 33 | private CallBackAttachment callBackAttachment;*/ 34 | 35 | } 36 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqMaxUpscaleData.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | @Data 8 | 9 | public class ReqMaxUpscaleData { 10 | @Builder.Default 11 | private int componentType = 2; 12 | private String customId; 13 | 14 | public ReqMaxUpscaleData(String messageHash) { 15 | this.customId = String.format("MJ::JOB::variation::1::%s::SOLO", messageHash); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqMaxUpscaleDiscord.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | @Accessors(chain = true) 14 | public class ReqMaxUpscaleDiscord { 15 | @Builder.Default 16 | private int type = 3; 17 | private String guildId; 18 | private String channelId; 19 | @Builder.Default 20 | private int messageFlags = 0; 21 | private String messageId; 22 | @Builder.Default 23 | private String applicationId = "936929561302675456"; 24 | @Builder.Default 25 | private String sessionId = "1f3dbdf09efdf93d81a3a6420882c92c"; 26 | private ReqMaxUpscaleData data; 27 | 28 | 29 | 30 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqReSetUpscaleData.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | @Data 8 | public class ReqReSetUpscaleData { 9 | @Builder.Default 10 | private int componentType = 2; 11 | private String customId; 12 | 13 | public ReqReSetUpscaleData(String messageHash) { 14 | this.customId = String.format("MJ::JOB::reroll::0::%s::SOLO", messageHash); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqReSetUpscaleDiscord.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | @Accessors(chain = true) 14 | public class ReqReSetUpscaleDiscord { 15 | @Builder.Default 16 | private int type = 3; 17 | private String guildId; 18 | private String channelId; 19 | @Builder.Default 20 | private int messageFlags = 0; 21 | private String messageId; 22 | @Builder.Default 23 | private String applicationId = "936929561302675456"; 24 | @Builder.Default 25 | private String sessionId = "45bc04dd4da37141a5f73dfbfaf5bdcf"; 26 | private ReqReSetUpscaleData data; 27 | 28 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqUpscaleData.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @Builder 11 | @Accessors(chain = true) 12 | public class ReqUpscaleData { 13 | @Builder.Default 14 | private int componentType = 2; 15 | private String customId; 16 | 17 | public ReqUpscaleData(int index, String messageHash) { 18 | this.customId = String.format("MJ::JOB::upsample::%d::%s", index, messageHash); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqUpscaleDiscord.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | @Accessors(chain = true) 14 | public class ReqUpscaleDiscord { 15 | @Builder.Default 16 | private int type = 3; 17 | private String guildId; 18 | private String channelId; 19 | @Builder.Default 20 | private int messageFlags = 0; 21 | private String messageId; 22 | @Builder.Default 23 | private String applicationId = "936929561302675456"; 24 | @Builder.Default 25 | private String sessionId = "45bc04dd4da37141a5f73dfbfaf5bdcf"; 26 | private ReqUpscaleData data; 27 | 28 | 29 | 30 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqVariationData.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ReqVariationData { 7 | private int componentType = 2; 8 | private String customId; 9 | public ReqVariationData(int index, String messageHash) { 10 | this.customId = String.format("MJ::JOB::variation::%d::%s", index, messageHash); 11 | } 12 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/ReqVariationDiscord.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | @Accessors(chain = true) 14 | public class ReqVariationDiscord { 15 | @Builder.Default 16 | private int type = 3; 17 | private String guildId; 18 | private String channelId; 19 | @Builder.Default 20 | private int messageFlags = 0; 21 | private String messageId; 22 | @Builder.Default 23 | private String applicationId = "936929561302675456"; 24 | @Builder.Default 25 | private String sessionId = "45bc04dd4da37141a5f73dfbfaf5bdcf"; 26 | private ReqVariationData data; 27 | 28 | 29 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/RequestMidjourneyApplicationCommand.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Auto-generated: 2023-04-25 9:7:8 13 | * 14 | * @author json.cn (i@json.cn) 15 | * @website http://www.json.cn/java2pojo/ 16 | */ 17 | 18 | @Data 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @Builder 22 | @Accessors(chain = true) 23 | public class RequestMidjourneyApplicationCommand { 24 | @Builder.Default 25 | private String id = "938956540159881230"; 26 | @Builder.Default 27 | private String application_id = "936929561302675456"; 28 | @Builder.Default 29 | private String version = "1077969938624553050"; 30 | @Builder.Default 31 | private String default_member_permissions = null; 32 | @Builder.Default 33 | private int type = 1; 34 | @Builder.Default 35 | private boolean nsfw = false; 36 | @Builder.Default 37 | private String name = "imagine"; 38 | @Builder.Default 39 | private String description = "Create images with Midjourney"; 40 | @Builder.Default 41 | private boolean dm_permission = true; 42 | private List options; 43 | 44 | 45 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/RequestMidjourneyData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 json.cn 3 | */ 4 | package com.qjc.midjourney.request; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | import lombok.experimental.Accessors; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Auto-generated: 2023-04-25 9:7:8 16 | * 17 | * @author json.cn (i@json.cn) 18 | * @website http://www.json.cn/java2pojo/ 19 | */ 20 | @Data 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | @Builder 24 | @Accessors(chain = true) 25 | public class RequestMidjourneyData { 26 | @Builder.Default 27 | private String version = "1077969938624553050"; 28 | @Builder.Default 29 | private String id = "938956540159881230"; 30 | @Builder.Default 31 | private String name = "imagine"; 32 | @Builder.Default 33 | private int type = 1; 34 | private List options; 35 | private RequestMidjourneyApplicationCommand application_command; 36 | private List attachments; 37 | 38 | 39 | 40 | 41 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/RequestMidjourneyDto.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 json.cn 3 | */ 4 | package com.qjc.midjourney.request; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | import lombok.experimental.Accessors; 11 | 12 | @Data 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | @Builder 16 | @Accessors(chain = true) 17 | public class RequestMidjourneyDto { 18 | @Builder.Default 19 | private int type = 2; 20 | @Builder.Default 21 | private String application_id = "936929561302675456"; 22 | private String guild_id; 23 | private String channel_id; 24 | @Builder.Default 25 | private String session_id = "9c4055428e13bcbf2248a6b36084c5f3"; 26 | private RequestMidjourneyData data; 27 | 28 | 29 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/RequestMidjourneyOptions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 json.cn 3 | */ 4 | package com.qjc.midjourney.request; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | import lombok.experimental.Accessors; 11 | 12 | /** 13 | * Auto-generated: 2023-04-25 9:7:8 14 | * 15 | * @author json.cn (i@json.cn) 16 | * @website http://www.json.cn/java2pojo/ 17 | */ 18 | 19 | @Data 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | @Builder 23 | @Accessors(chain = true) 24 | public class RequestMidjourneyOptions { 25 | @Builder.Default 26 | private int type = 3; 27 | @Builder.Default 28 | private String name = "prompt"; 29 | private String value ; 30 | 31 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/request/RequestMidjourneyOptionss.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.request; /** 2 | * Copyright 2023 json.cn 3 | */ 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | import lombok.experimental.Accessors; 10 | 11 | /** 12 | * Copyright 2023 json.cn 13 | */ 14 | 15 | 16 | @Data 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @Builder 20 | @Accessors(chain = true) 21 | public class RequestMidjourneyOptionss { 22 | @Builder.Default 23 | private int type = 3; 24 | @Builder.Default 25 | private String name = "prompt"; 26 | @Builder.Default 27 | private String description = "The prompt to imagine"; 28 | @Builder.Default 29 | private boolean required = true; 30 | 31 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/result/ResponseData.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.result; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | @Accessors(chain = true) 14 | public class ResponseData { 15 | private String message; 16 | private String error; 17 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/service/DiscordInteractionService.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.service; 2 | 3 | import org.springframework.web.reactive.function.client.WebClient; 4 | 5 | /** 6 | * @author qjc 7 | * @description TODO 8 | * @date 2023-05-06 15:59 9 | */ 10 | public interface DiscordInteractionService { 11 | 12 | public void generateImage(String prompt); 13 | 14 | public void upscale(int index, String messageId, String messageHash); 15 | 16 | public void variate(int index, String messageId, String messageHash); 17 | 18 | public void maxUpscale(String messageId, String messageHash); 19 | 20 | 21 | public void reSet(String messageId, String messageHash); 22 | } 23 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/service/MidjourneyService.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.service; 2 | 3 | import com.qjc.midjourney.dto.RequestTrigger; 4 | 5 | /** 6 | * @author qjc 7 | * @description TODO 8 | * @date 2023-05-06 15:37 9 | */ 10 | public interface MidjourneyService { 11 | public void executeAction(RequestTrigger requestTrigger) throws Exception; 12 | } 13 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/service/impl/ChatServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.service.impl; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.reactive.function.BodyInserters; 8 | import org.springframework.web.reactive.function.client.WebClient; 9 | 10 | import java.time.Duration; 11 | import java.util.concurrent.TimeoutException; 12 | 13 | 14 | /** 15 | * The type Gpt service. 16 | * 17 | * @author bdth 18 | */ 19 | @Service 20 | 21 | 22 | @Slf4j 23 | public class ChatServiceImpl { 24 | 25 | 26 | @Value("${chatgpt.token}") 27 | private String token; 28 | 29 | 30 | /** 31 | * The constant openUrl. 32 | */ 33 | private static final String openUrl = "https://api.openai.com/v1/"; 34 | 35 | 36 | 37 | 38 | 39 | /** 40 | * Http string. 41 | * 42 | * @param body the body 43 | * @return the string 44 | */ 45 | public JSONObject build(final Object body, final String url) { 46 | 47 | final WebClient.Builder webClient = WebClient.builder(); 48 | 49 | log.info("=================>WebClient start http:"); 50 | 51 | try { 52 | webClient 53 | .baseUrl(openUrl) 54 | .defaultHeader("Authorization", "Bearer " +token); 55 | return JSONObject.parseObject( 56 | webClient.build() 57 | .post() 58 | .uri(url) 59 | .body(BodyInserters.fromValue(body)) 60 | .retrieve() 61 | .bodyToMono(String.class) 62 | .timeout(Duration.ofSeconds(60)) 63 | .onErrorMap(TimeoutException.class, e -> new Exception()) 64 | .block() 65 | ); 66 | } catch (Exception e) { 67 | e.printStackTrace(); 68 | } 69 | return new JSONObject(); 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/service/impl/DiscordInteractionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.service.impl; 2 | 3 | import com.qjc.midjourney.config.MidjourneyBotConfiguration; 4 | import com.qjc.midjourney.request.*; 5 | import com.qjc.midjourney.service.DiscordInteractionService; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.client.WebClient; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Arrays; 15 | 16 | /** 17 | * @author qjc 18 | * @description TODO 19 | * @date 2023-05-06 16:00 20 | * @email 1071643762@qq.com 21 | */ 22 | @Service 23 | @Slf4j 24 | public class DiscordInteractionServiceImpl implements DiscordInteractionService { 25 | private static final String DISCORD_API_URL = "https://discord.com/api/v9/interactions"; 26 | private final WebClient webClient; 27 | 28 | private final MidjourneyBotConfiguration midjourneyBotConfiguration; 29 | @Autowired 30 | public DiscordInteractionServiceImpl(MidjourneyBotConfiguration midjourneyBotConfiguration, 31 | WebClient.Builder webClientBuilder) { 32 | this.webClient = webClientBuilder.build(); 33 | this.midjourneyBotConfiguration= midjourneyBotConfiguration; 34 | } 35 | 36 | /** 37 | * Call GenerateImage service 38 | * @param prompt 39 | */ 40 | @Override 41 | public void generateImage(String prompt) { 42 | sendRequest(RequestMidjourneyDto.builder() 43 | .guild_id(midjourneyBotConfiguration.getDiscordConfig().getServerId()) 44 | .channel_id(midjourneyBotConfiguration.getDiscordConfig().getChannelId()) 45 | .data(RequestMidjourneyData.builder() 46 | .options(Arrays.asList(RequestMidjourneyOptions.builder() 47 | .value(prompt) 48 | .build())) 49 | .application_command(RequestMidjourneyApplicationCommand.builder() 50 | .options(Arrays.asList(RequestMidjourneyOptionss.builder().build())) 51 | .build()) 52 | .build()) 53 | .build()); 54 | 55 | } 56 | 57 | 58 | /** 59 | * Call ImageUpscale service 60 | * @param 61 | */ 62 | public void upscale(int index, String messageId, String messageHash) { 63 | sendRequest( ReqUpscaleDiscord.builder() 64 | .guildId(midjourneyBotConfiguration.getDiscordConfig().getServerId()) 65 | .channelId(midjourneyBotConfiguration.getDiscordConfig().getChannelId()) 66 | .messageId(messageId) 67 | .data(new ReqUpscaleData(index,messageHash)) 68 | .build()); 69 | } 70 | 71 | /** 72 | * Call ImageVariation service 73 | * @param index 74 | * @param messageId 75 | * @param messageHash 76 | */ 77 | @Override 78 | public void variate(int index, String messageId, String messageHash) { 79 | sendRequest(ReqVariationDiscord.builder() 80 | .guildId(midjourneyBotConfiguration.getDiscordConfig().getServerId()) 81 | .channelId(midjourneyBotConfiguration.getDiscordConfig().getChannelId()) 82 | .messageId(messageId) 83 | .data(new ReqVariationData(index,messageHash)) 84 | .build() 85 | ); 86 | } 87 | 88 | @Override 89 | public void maxUpscale(String messageId, String messageHash) { 90 | sendRequest(ReqMaxUpscaleDiscord.builder() 91 | .guildId(midjourneyBotConfiguration.getDiscordConfig().getServerId()) 92 | .channelId(midjourneyBotConfiguration.getDiscordConfig().getChannelId()) 93 | .messageId(messageId) 94 | .data(new ReqMaxUpscaleData(messageHash)) 95 | .build()); 96 | } 97 | 98 | @Override 99 | public void reSet(String messageId, String messageHash) { 100 | sendRequest(ReqReSetUpscaleDiscord.builder() 101 | .guildId(midjourneyBotConfiguration.getDiscordConfig().getServerId()) 102 | .channelId(midjourneyBotConfiguration.getDiscordConfig().getChannelId()) 103 | .messageId(messageId) 104 | .data(new ReqReSetUpscaleData(messageHash)) 105 | .build()); 106 | } 107 | 108 | 109 | 110 | 111 | /** 112 | * request DISCORD_API_URL 113 | * @param requestBody 114 | */ 115 | private void sendRequest(Object requestBody) { 116 | webClient.post() 117 | .uri(DISCORD_API_URL) 118 | .contentType(MediaType.APPLICATION_JSON) 119 | .header("Authorization", midjourneyBotConfiguration.getDiscordConfig().getUserToken()) 120 | .body(BodyInserters.fromValue(requestBody)) 121 | .retrieve() 122 | .bodyToMono(String.class) 123 | .subscribe(response -> log.info("Upscale response: " + response), 124 | error -> log.error("Error: " + error.getMessage())); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/java/com/qjc/midjourney/service/impl/MidjourneyServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qjc.midjourney.service.impl; 2 | 3 | import com.qjc.midjourney.dto.RequestTrigger; 4 | import com.qjc.midjourney.service.DiscordInteractionService; 5 | import com.qjc.midjourney.service.MidjourneyService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class MidjourneyServiceImpl implements MidjourneyService { 11 | 12 | @Autowired 13 | private DiscordInteractionService discordInteractionService; 14 | public void executeAction(RequestTrigger requestTrigger) throws Exception { 15 | String type = requestTrigger.getType(); 16 | switch (type) { 17 | case "generate": 18 | // Call GenerateImage service 19 | discordInteractionService.generateImage(requestTrigger.getPrompt()); 20 | break; 21 | case "upscale": 22 | // Call ImageUpscale service 23 | discordInteractionService.upscale(requestTrigger.getIndex(), 24 | requestTrigger.getDiscordMsgId(), 25 | requestTrigger.getMsgHash()); 26 | break; 27 | case "variation": 28 | // Call ImageVariation service 29 | discordInteractionService.variate(requestTrigger.getIndex(), 30 | requestTrigger.getDiscordMsgId(), 31 | requestTrigger.getMsgHash()); 32 | break; 33 | case "maxUpscale": 34 | // Call ImageMaxUpscale service 35 | discordInteractionService.maxUpscale( requestTrigger.getDiscordMsgId(), 36 | requestTrigger.getMsgHash()); 37 | break; 38 | case "reset": 39 | // Call ImageReset service 40 | discordInteractionService.reSet(requestTrigger.getDiscordMsgId(), 41 | requestTrigger.getMsgHash()); 42 | break; 43 | default: 44 | throw new Exception("Invalid type"); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /midjourney-bot-api-java/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8899 3 | 4 | discord: 5 | user-token: '用户token' 6 | bot-token: '机器人token' 7 | server-id: '服务id' 8 | channel-id: '频道id' 9 | call-back: 10 | url: '回调地址' 11 | 12 | chatgpt: 13 | token: '用户token chagpt的可以不填写' 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /source/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8899 3 | 4 | discord: 5 | user-token: '用户token' 6 | bot-token: '机器人token' 7 | server-id: '服务id' 8 | channel-id: '频道id' 9 | call-back: 10 | url: '回调地址' 11 | 12 | chatgpt: 13 | token: '用户token chagpt的可以不填写' 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /source/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qjc1024join/midjourney-bot-api/deac0e74151adc36b38fdcbe4f960266edf13669/source/image.png -------------------------------------------------------------------------------- /source/service.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## java env 3 | export JAVA_HOME=/usr/local/jdk17 4 | export JRE_HOME=$JAVA_HOME/jre 5 | 6 | API_NAME=midjourney-bot-api-java-0.0.1-SNAPSHOT 7 | JAR_NAME=$API_NAME\.jar 8 | #PID 代表是PID文件 9 | PID=$API_NAME\.pid 10 | 11 | #使用说明,用来提示输入参数 12 | usage() { 13 | echo "Usage: sh to.sh [start|stop|restart|status]" 14 | exit 1 15 | } 16 | 17 | #检查程序是否在运行 18 | is_exist(){ 19 | pid=`ps -ef|grep $JAR_NAME|grep -v grep|awk '{print $2}' ` 20 | #如果不存在返回1,存在返回0 21 | if [ -z "${pid}" ]; then 22 | return 1 23 | else 24 | return 0 25 | fi 26 | } 27 | 28 | #启动方法 29 | start(){ 30 | is_exist 31 | if [ $? -eq "0" ]; then 32 | echo ">>> ${JAR_NAME} is already running PID=${pid} <<<" 33 | else 34 | nohup $JAVA_HOME/bin/java -Xms512M -Xmx512M -Xmn256M -Xss512K -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M -jar $JAR_NAME --spring.config.location=application.yml >/usr/local/log/log.log & 35 | echo $! > $PID 36 | echo ">>> start $JAR_NAME successed PID=$! <<<" 37 | fi 38 | } 39 | 40 | #停止方法 41 | stop(){ 42 | #is_exist 43 | pidf=$(cat $PID) 44 | #echo "$pidf" 45 | echo ">>> api PID = $pidf begin kill $pidf <<<" 46 | kill $pidf 47 | rm -rf $PID 48 | sleep 2 49 | is_exist 50 | if [ $? -eq "0" ]; then 51 | echo ">>> api 2 PID = $pid begin kill -9 $pid <<<" 52 | kill -9 $pid 53 | sleep 2 54 | echo ">>> $JAR_NAME process stopped <<<" 55 | else 56 | echo ">>> ${JAR_NAME} is not running <<<" 57 | fi 58 | } 59 | 60 | #输出运行状态 61 | status(){ 62 | is_exist 63 | if [ $? -eq "0" ]; then 64 | echo ">>> ${JAR_NAME} is running PID is ${pid} <<<" 65 | else 66 | echo ">>> ${JAR_NAME} is not running <<<" 67 | fi 68 | } 69 | 70 | #重启 71 | restart(){ 72 | stop 73 | start 74 | } 75 | 76 | #根据输入参数,选择执行对应方法,不输入则执行使用说明 77 | case "$1" in 78 | "start") 79 | start 80 | ;; 81 | "stop") 82 | stop 83 | ;; 84 | "status") 85 | status 86 | ;; 87 | "restart") 88 | restart 89 | ;; 90 | *) 91 | usage 92 | ;; 93 | esac 94 | exit 0 95 | -------------------------------------------------------------------------------- /source/小程序码.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qjc1024join/midjourney-bot-api/deac0e74151adc36b38fdcbe4f960266edf13669/source/小程序码.jpg -------------------------------------------------------------------------------- /source/赞赏码.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qjc1024join/midjourney-bot-api/deac0e74151adc36b38fdcbe4f960266edf13669/source/赞赏码.jpg --------------------------------------------------------------------------------