Skip to content

Commit

Permalink
feat: Basic UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-Shilin committed Jun 14, 2024
1 parent 95c192f commit 8155501
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 6 deletions.
54 changes: 54 additions & 0 deletions codes/Demo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.cubegpt</groupId>
<artifactId>Demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.cubegpt._54672e99.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
30 changes: 30 additions & 0 deletions codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
1 change: 1 addition & 0 deletions codes/Demo/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
greeting-message: 'hello'
10 changes: 10 additions & 0 deletions codes/Demo/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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: /<command>
Binary file added codes/Demo/target/Demo-1.0-SNAPSHOT.jar
Binary file not shown.
1 change: 1 addition & 0 deletions codes/Demo/target/classes/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
greeting-message: 'hello'
Binary file not shown.
10 changes: 10 additions & 0 deletions codes/Demo/target/classes/plugin.yml
Original file line number Diff line number Diff line change
@@ -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: /<command>
3 changes: 3 additions & 0 deletions codes/Demo/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=Demo
groupId=org.cubegpt
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org\cubegpt\_54672e99\Main.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D:\zhousl\BukkitGPT\BukkitGPT-v3\codes\Demo\src\main\java\org\cubegpt\54672e99\Main.java
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
126 changes: 120 additions & 6 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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")



Expand Down

0 comments on commit 8155501

Please sign in to comment.