From 815550145e9bf3b71a97606e9cda03a3c23b9b13 Mon Sep 17 00:00:00 2001 From: BaimoQilin Date: Fri, 14 Jun 2024 21:36:57 +0800 Subject: [PATCH] feat: Basic UI --- codes/Demo/pom.xml | 54 ++++++++ .../main/java/org/cubegpt/54672e99/Main.java | 30 +++++ codes/Demo/src/main/resources/config.yml | 1 + codes/Demo/src/main/resources/plugin.yml | 10 ++ codes/Demo/target/Demo-1.0-SNAPSHOT.jar | Bin 0 -> 3224 bytes codes/Demo/target/classes/config.yml | 1 + .../classes/org/cubegpt/54672e99/Main.class | Bin 0 -> 919 bytes codes/Demo/target/classes/plugin.yml | 10 ++ .../Demo/target/maven-archiver/pom.properties | 3 + .../compile/default-compile/createdFiles.lst | 1 + .../compile/default-compile/inputFiles.lst | 1 + .../classes/org/cubegpt/188eba63/Main.class | Bin 0 -> 841 bytes .../classes/org/cubegpt/_188eba63/Main.class | Bin 1157 -> 0 bytes core.py | 4 + ui.py | 126 +++++++++++++++++- 15 files changed, 235 insertions(+), 6 deletions(-) create mode 100644 codes/Demo/pom.xml create mode 100644 codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java create mode 100644 codes/Demo/src/main/resources/config.yml create mode 100644 codes/Demo/src/main/resources/plugin.yml create mode 100644 codes/Demo/target/Demo-1.0-SNAPSHOT.jar create mode 100644 codes/Demo/target/classes/config.yml create mode 100644 codes/Demo/target/classes/org/cubegpt/54672e99/Main.class create mode 100644 codes/Demo/target/classes/plugin.yml create mode 100644 codes/Demo/target/maven-archiver/pom.properties create mode 100644 codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 codes/ExamplePlugin4/target/classes/org/cubegpt/188eba63/Main.class delete mode 100644 codes/ExamplePlugin4/target/classes/org/cubegpt/_188eba63/Main.class diff --git a/codes/Demo/pom.xml b/codes/Demo/pom.xml new file mode 100644 index 0000000..c6ee47c --- /dev/null +++ b/codes/Demo/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.cubegpt + Demo + 1.0-SNAPSHOT + jar + + + + org.bukkit + bukkit + 1.13.2-R0.1-SNAPSHOT + provided + + + + + src/main/java + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + lib/ + org.cubegpt._54672e99.Main + + + + + + + \ No newline at end of file diff --git a/codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java b/codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java new file mode 100644 index 0000000..b11ee5a --- /dev/null +++ b/codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java @@ -0,0 +1,30 @@ +package org.cubegpt._54672e99; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.event.Listener; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Main extends JavaPlugin implements Listener { + + @Override + public void onEnable() { + getServer().getPluginManager().registerEvents(this, this); + Bukkit.getConsoleSender().sendMessage("Plugin enabled!"); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + event.getPlayer().sendMessage("hello"); + } + + @Override + public void onDisable() { + Bukkit.getConsoleSender().sendMessage("Plugin disabled!"); + } +} \ No newline at end of file diff --git a/codes/Demo/src/main/resources/config.yml b/codes/Demo/src/main/resources/config.yml new file mode 100644 index 0000000..cb441b6 --- /dev/null +++ b/codes/Demo/src/main/resources/config.yml @@ -0,0 +1 @@ +greeting-message: 'hello' \ No newline at end of file diff --git a/codes/Demo/src/main/resources/plugin.yml b/codes/Demo/src/main/resources/plugin.yml new file mode 100644 index 0000000..4d3dd41 --- /dev/null +++ b/codes/Demo/src/main/resources/plugin.yml @@ -0,0 +1,10 @@ +name: Demo +version: 1.0 +main: org.cubegpt._54672e99.Main +api-version: 1.13 +author: CubeGPT +dependencies: [] +commands: + demo: + description: Sends a greeting message to everyone. + usage: / \ No newline at end of file diff --git a/codes/Demo/target/Demo-1.0-SNAPSHOT.jar b/codes/Demo/target/Demo-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..f106aaa303e49e5ff95de342b6a0f206416c7494 GIT binary patch literal 3224 zcma)93p~^78~?eK+Z0*Dx`>95YiLfwm=0#cP@|LF*2vi0Nogc<*_g3pN{^6W8%US%r$=;}WcTBKH+IL?TdR|G9))itWKOb3;SP8TC8hRih;YK(EB z2l-%zP?w2(s?bCKs69K+ODhXpQJCL*`|Q|p^5ud?8#<4_ZUG{H{5_%y_7SpU<(p1>}o`Tc9hEL=9NM683}TK^<+~omxaay%jKPxufLm z5=8V_!Fa>JjX~el{=a8iRtBPp-jvVVF5P4wc;P6)4QA}^q`?Ws1#qMI9P%Wog?f`Q z>K0hl`^}i17Obio&eEy~Z{2Fva{vB50pR;&payH~zRe2&iK_r$3rN8Z^H*0np~1R% z`lz{)UHtv&b_c8^P|)3-u;Ra(_MM)Rv$N}uydih6=#+7_R0rHmH2=^5j>QT}dFf;R z&Y|+cT(!(_qSjEKr-h34j8-sd?9q<-jFMediwg^@oFy7Gqr|$!+BIpY=rg0;bc@-A zM>BMhGKbqy(+|tF=@M{*)&9}dyD@}M1}4Z%J-Te1tf=ND-{%m2t*ZVTuiu}f9PR6W zG}Jd-l3}Aod}5vXfjH^pm+GRGsT7oXIc3&2!P&0%9K#nORZo$Xsy~Ic$7`K*NX0Z& z{PwCe%;??%kPOcauyl)dnKlfG7EkR_Z5^MSmY1w-C^$c95Y=R#vrRnm`G>6RR9K6P zlL@|ock|o0Um%g|?5R=Xz2(iO*sQ94m1`5)@Z3CUZ#xurJyND_U2Wbk)L4;1*I7qp z#;=6#*MtTMeIlVmQQG8DPU5&Z) z{|-i>k@|!nS70+ob96U*YjNpVQ`O-szvl)k=M!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/Demo/target/classes/config.yml b/codes/Demo/target/classes/config.yml new file mode 100644 index 0000000..cb441b6 --- /dev/null +++ b/codes/Demo/target/classes/config.yml @@ -0,0 +1 @@ +greeting-message: 'hello' \ No newline at end of file diff --git a/codes/Demo/target/classes/org/cubegpt/54672e99/Main.class b/codes/Demo/target/classes/org/cubegpt/54672e99/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..1ed5168bad9eac44c64057c7c84aae9506b4d49c GIT binary patch literal 919 zcmb7CZEF)j5T1=Omz>eGRjV;-ul*E3av)Wy6+tv2<&1*# zUvZ%vXfoI?zNh(oF07x*JQm77;S25`&~{kb4zwzi$_*E&tRINXqC&%<^;jrjpD;K# zyfb0Ye5NCG-~xkQi6ps-{jo9HwBaIyPj8jMOv?pEUZ|5)NN$BzUTXAIV)DpyJI6Eh zA`B%ruk&Pz=9m*f1{;A6xtwq#3cGr2+L_2041$$v?=xs?HC9DX z8?KS^{}h5jSF1zGKcYF%LNT~IEb;&7Lt6g(XKv%7Jtg=4n_O9u;6!ACvOZNLQz4%h;nH`q8n8}#tNbA)>E2y>!DYBY7WH8T!e$M^S}nqL=u@5>Rh|Kzr+gZ8 YU-GF#+pI;q`5$}+wFtK;YXffo0*OJ \ No newline at end of file diff --git a/codes/Demo/target/maven-archiver/pom.properties b/codes/Demo/target/maven-archiver/pom.properties new file mode 100644 index 0000000..67ada22 --- /dev/null +++ b/codes/Demo/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=Demo +groupId=org.cubegpt +version=1.0-SNAPSHOT diff --git a/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..93c8498 --- /dev/null +++ b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +org\cubegpt\_54672e99\Main.class diff --git a/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..07108c4 --- /dev/null +++ b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +D:\zhousl\BukkitGPT\BukkitGPT-v3\codes\Demo\src\main\java\org\cubegpt\54672e99\Main.java diff --git a/codes/ExamplePlugin4/target/classes/org/cubegpt/188eba63/Main.class b/codes/ExamplePlugin4/target/classes/org/cubegpt/188eba63/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6e07f61c996f22c13f89a409c8e9287aea691939 GIT binary patch literal 841 zcmah{ZHv=D5T32IX=AkB`C8AHz57%_8bp!96G5aRN0h@m3x1MKGNfyh-LTmd{R{pf zK|#O!qr}-<&O>bRLuPlfGtWHp%>4ZI^*aDOgxel;7>u;Z!laHdD{XjxcNb&v=t1~O zNaaD7!M1yj>%~Iau*~aBs_=tYig2IILF0SSYf;)TT%xjJBrA&w4TIhjsib|%;LP~$ zj6wIgPSJyN42BI-E>spyjnSqL=NWu{s|;2;Ut-D=U6e8xR%*pdqvITl$J`$r&5@^= zdw3c)b>nHckKWYE$^vJyl2rAXBAFVoiRqnx zk($JpLZvwxV(TC3+9dcwx~2ziVJ1!?*an(3eP?OO-04A|?4VgW=L7iPz<;+He1Qu; z$m_rc*d`$oj)F^YnLN^d4Z_tG2*FB(>oB4^H`+Q|be{0((EXUtDzuH2Xg4XR H1Gjzymg~z= literal 0 HcmV?d00001 diff --git a/codes/ExamplePlugin4/target/classes/org/cubegpt/_188eba63/Main.class b/codes/ExamplePlugin4/target/classes/org/cubegpt/_188eba63/Main.class deleted file mode 100644 index d5d5c9206bfdb74e76a8c484e50d7ea511eba517..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1157 zcmaJ>(M}Ul5IxgUmbMF&A_!Qmh)OBQiYV69kSJmdDTavQ)!f3(a%H(ow%aCrmM?03 z@B{oP5Mhf%_!AGl7tdv>Nm=fdl{ zN;{uLPdIyQ4x%$*^rg}&+$LmeD@O&4A#b5zqX?TYm8gFm!4UGU3=d_{lL29-w$e(Z z#NlQU6PUD6vN45n8su+bi9uol`$7xXU@fJw26R(NjC=z#7G`bS#2lfT=shf-FcC;s zbwU~J_M{Fwghnk%SemHQG8tM1&E%^TUehSEfLj(SHg4k%VL8z{M!E3Br3{>d$nE(` zM=fK$;vk`t{zh)D!plKPa}0M0xl`$Rei8SuWZ}Mz2Y5)BOEyc^5Q-hCPxfV}!y=k_ zw4(WXLc7jk7%1&Bbqh7Zg26cMwxxR!I-fQg4cQi3o6f#a+CrT$pX`y6g)p+?pD_Al zOKJJOd)}78N742;Qf~Rj!aEXyGUq{XBs^8DbR|-Ac*iDT%-6d*MzMW;tr}r%$cToE z%iqR|Me-9;H}QWX;pX!nx-8?lJW?IS#9wLchayzIX5Q80Er@ZVNxl>M#N$gsC>;9T z;8?y@MuNOiaNVemMJ)6BF%#a!EPGx-wyS({*c1C){Tt{DKV-1R*1QJtc*NF@6R^(7 z;OECz#oG}WQ2Gw5k8wi1-p6zn*EnYDfpJXo;$35vuCO-ngfk40H|$NWz4{gN` knSXG~y!+D;&TO1Jz%d**`6oko#t4S{7JI^Twiz`301@FLr~m)} diff --git a/core.py b/core.py index e5308e6..597709e 100644 --- a/core.py +++ b/core.py @@ -23,6 +23,10 @@ def initialize(): locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') logger(f"Launch. Software version {config.VERSION_NUMBER}, platform {sys.platform}") + if "gpt-3.5" in config.GENERATION_MODEL and config.BYPASS_NO_GPT35_FOR_GENERATION_LIMIT is False: + print("gpt-3.5 writes bugs *all the time* and is not recommended for code generation. Switching to gpt-4.") + config.edit_config("GENERATION_MODEL", config.GENERATION_MODEL.replace("gpt-3.5", "gpt-4")) + def askgpt(system_prompt: str, user_prompt: str, model_name: str, disable_json_mode: bool = False, image_url: str = None): """ Interacts with ChatGPT using the specified prompts. diff --git a/ui.py b/ui.py index aa4597c..75970ad 100644 --- a/ui.py +++ b/ui.py @@ -9,7 +9,9 @@ from log_writer import logger import config import core +import build +#---------- Functions ----------# def open_config(args: dict): """ Opens the config file. @@ -94,22 +96,134 @@ def raise_error(args: dict): """ raise Exception("This is a test error.") -root = CreateQGUI(title="CubeAgents", - tab_names=["Generate", "Settings", "DevTools"] +#---------- Generate Function ----------# +def generate(args: dict): + """ + Generates the plugin. + + Args: + args (dict): A dictionary containing the arguments. + + Returns: + bool: Always True. + """ + global error_msg, pkg_id_path + + # Get user inputs + name = args["PluginName"].get() + description = args["PluginDescription"].get() + + artifact_name = name.replace(" ", "") + package_id = f"org.cubegpt.{uuid.uuid4().hex[:8]}" + + pkg_id_path = "" + for id in package_id.split("."): + pkg_id_path += id + "/" + + logger(f"user_input -> name: {name}") + logger(f"user_input -> description: {description}") + logger(f"random_generate -> package_id: {package_id}") + logger(f"str_path -> pkg_id_path: {pkg_id_path}") + + print("Generating plugin...") + + codes = core.askgpt(config.SYS_GEN.replace("%ARTIFACT_NAME%", artifact_name).replace("%PKG_ID_LST%", pkg_id_path), config.USR_GEN.replace("%DESCRIPTION", description), config.GENERATION_MODEL) + logger(f"codes: {codes}") + + core.response_to_action(codes) + + print("Code generated. Building now...") + + result = build.build_plugin(artifact_name) + if "BUILD SUCCESS" in result: + print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'") + elif "Compilation failure": + error_msg = result + print("Build failed. To pass the error to ChatGPT && let it fix, jump to the Fixing page and click the Fix button.") + else: + print("Unknown error. Please check the logs && send the log to @BaimoQilin on discord.") + + + return True + +def fix(args: dict): + """ + Fixes the error. + + Args: + args (dict): A dictionary containing the arguments. + + Returns: + bool: Always True. + """ + artifact_name = args["PluginName"].get() + + print("Passing the error to ChatGPT...") + + files = [f"codes/{artifact_name}/src/main/java/{pkg_id_path}Main.java", + f"codes/{artifact_name}/src/main/resources/plugin.yml", + f"codes/{artifact_name}/src/main/resources/config.yml", + f"codes/{artifact_name}/pom.xml"] + + ids = ["main_java", + "plugin_yml", + "config_yml", + "pom_xml"] + + main_java = None + plugin_yml = None + config_yml = None + pom_xml = None + + for file in files: + with open(file, "r") as f: + code = f.read() + id = ids[files.index(file)] + globals()[id] = code + + print("Generating...") + codes = core.askgpt(config.SYS_FIX.replace("%ARTIFACT_NAME%", str(artifact_name)), config.USR_FIX.replace("%MAIN_JAVA%", str(main_java)).replace("%PLUGIN_YML%", str(plugin_yml)).replace("%CONFIG_YML%", str(config_yml)).replace("%POM_XML%", str(pom_xml)).replave("%PKG_ID_LST%", pkg_id_path).replace("%P_ERROR_MSG%", str(error_msg)), config.FIXING_MODEL) + + shutil.rmtree(f"codes/{artifact_name}") + core.response_to_action(codes) + + print("Code generated. Building now...") + + result = build.build_plugin(artifact_name) + + if "BUILD SUCCESS" in result: + print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'") + else: + print("Build failed again. Please check the logs && send the log to @BaimoQilin on discord.") + + return True + +#---------- Main Program ----------# + +root = CreateQGUI(title="BukkitGPT-v3", + tab_names=["Generate", "Fixing", "Settings", "DevTools"] ) +error_msg = None logger("Starting program.") # Initialize Core core.initialize() +print("BukkitGPT v3 beta console running") + # Banner -root.add_banner_tool(GitHub("https://github.com/CubeGPT/CubeAgents")) +root.add_banner_tool(GitHub("https://github.com/CubeGPT/BukkitGPT-v3")) # Generate Page -# Codes here. +root.add_notebook_tool(InputBox(name="PluginName", default="ExamplePlugin", label_info="Plugin Name")) +root.add_notebook_tool(InputBox(name="PluginDescription", default="Send msg 'hello' to every joined player.", label_info="Plugin Description")) + +root.add_notebook_tool(RunButton(bind_func=generate, name="Generate", text="Generate Plugin", checked_text="Generating...", tab_index=0)) -# More pages here. +# Fixing Page # +root.add_notebook_tool(Label(name="Fixing_DESCRIPTION", text="This is a fixing page. If the build fails, click the Fix button to fix the error in the LATEST build.", tab_index=1)) +root.add_notebook_tool(RunButton(bind_func=fix, name="Fix", text="Fix", checked_text="Fixing...", tab_index=1)) # Settings Page root.add_notebook_tool(InputBox(name="API_KEY", default=config.API_KEY, label_info="API Key", tab_index=2)) @@ -132,7 +246,7 @@ def raise_error(args: dict): # Sidebar root.set_navigation_about(author="CubeGPT Team", version=config.VERSION_NUMBER, - github_url="https://github.com/CubeGPT/CubeAgents") + github_url="https://github.com/CubeGPT/BukkitGPT-v3")