Skip to content

Commit

Permalink
Remove legacy color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
RappyTV committed Aug 18, 2023
1 parent f6b750b commit 3a92233
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ labyMod {
author = "RappyTV"
description = "Communicate with ChatGPT right in your Chat. Powered by OpenAI."
minecraftVersion = "*"
version = System.getenv().getOrDefault("VERSION", "1.1.0")
version = System.getenv().getOrDefault("VERSION", "1.1.1")
}

minecraft {
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/com/rappytv/labygpt/GPTAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import com.rappytv.labygpt.commands.GPTCommand;
import com.rappytv.labygpt.config.GPTAddonConfig;
import net.labymod.api.addon.LabyAddon;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.models.addon.annotation.AddonMain;
import java.util.ArrayList;

@AddonMain
public class GPTAddon extends LabyAddon<GPTAddonConfig> {

public static final String prefix = "§8[§9LabyGPT§8] §7";
public static final Component prefix = Component.text("[", NamedTextColor.DARK_GRAY)
.append(Component.text("LabyGPT", NamedTextColor.BLUE))
.append(Component.text("] ", NamedTextColor.DARK_GRAY));
public static final ArrayList<GPTMessage> queryHistory = new ArrayList<>();

@Override
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/com/rappytv/labygpt/commands/GPTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.rappytv.labygpt.commands.subcommands.GPTClearSubCommand;
import com.rappytv.labygpt.commands.subcommands.GPTHistorySubCommand;
import net.labymod.api.client.chat.command.Command;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.util.I18n;
import java.util.Objects;

Expand All @@ -23,11 +25,11 @@ public GPTCommand(GPTAddon addon) {
@Override
public boolean execute(String prefix, String[] arguments) {
if(addon.configuration().openAI().bearer().isEmpty()) {
displayMessage(GPTAddon.prefix + "§c" + I18n.translate("labygpt.messages.noKey"));
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.translatable("labygpt.messages.noKey", NamedTextColor.RED)));
return true;
}
if(arguments.length < 1) {
displayMessage(GPTAddon.prefix + "§c" + I18n.translate("labygpt.messages.noQuery"));
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.translatable("labygpt.messages.noQuery", NamedTextColor.RED)));
return true;
}

Expand All @@ -43,11 +45,11 @@ public boolean execute(String prefix, String[] arguments) {

if(!request.isSuccessful() || request.getOutput() == null) {
GPTAddon.queryHistory.remove(GPTAddon.queryHistory.size() - 1);
displayMessage(GPTAddon.prefix + "§c" + Objects.requireNonNullElseGet(request.getError(), () -> I18n.translate("labygpt.messages.requestError")));
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.text(Objects.requireNonNullElseGet(request.getError(), () -> I18n.translate("labygpt.messages.requestError")), NamedTextColor.RED)));
return true;
}

displayMessage(GPTAddon.prefix + "§f" + request.getOutput());
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.text(request.getOutput(), NamedTextColor.WHITE)));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.rappytv.labygpt.GPTAddon;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.util.I18n;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;

public class GPTClearSubCommand extends SubCommand {

Expand All @@ -13,11 +14,11 @@ public GPTClearSubCommand() {
@Override
public boolean execute(String prefix, String[] arguments) {
if(GPTAddon.queryHistory.isEmpty()) {
displayMessage(GPTAddon.prefix + "§c" + I18n.translate("labygpt.messages.alreadyEmptyHistory"));
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.translatable("labygpt.messages.alreadyEmptyHistory", NamedTextColor.RED)));
return true;
}
GPTAddon.queryHistory.clear();
displayMessage(GPTAddon.prefix + "§a" + I18n.translate("labygpt.messages.historyCleared"));
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.translatable("labygpt.messages.historyCleared", NamedTextColor.GREEN)));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.rappytv.labygpt.api.GPTMessage;
import com.rappytv.labygpt.api.GPTRole;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.util.I18n;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;

public class GPTHistorySubCommand extends SubCommand {

Expand All @@ -15,20 +16,24 @@ public GPTHistorySubCommand() {
@Override
public boolean execute(String prefix, String[] arguments) {
if(GPTAddon.queryHistory.size() < 2) {
displayMessage(GPTAddon.prefix + "§c" + I18n.translate("labygpt.messages.emptyHistory"));
displayMessage(Component.empty().append(GPTAddon.prefix).append(Component.translatable("labygpt.messages.emptyHistory", NamedTextColor.RED)));
return true;
}

StringBuilder builder = new StringBuilder();
Component component = Component.empty();
for(int i = 0; i < GPTAddon.queryHistory.size(); i++) {
GPTMessage message = GPTAddon.queryHistory.get(i);
String name = message.name.isEmpty() ? labyAPI.getName() : message.name;
if(message.role != GPTRole.System)
builder.append("§8[§9").append(name).append("§8] §f").append(message.content.replace("\n\n", "")).append("\n");
component
.append(Component.text(i == 0 ? "" : "\n"))
.append(Component.text("[", NamedTextColor.DARK_GRAY))
.append(Component.text(name))
.append(Component.text("] ", NamedTextColor.DARK_GRAY))
.append(Component.text(message.content.replace("\n\n", ""), NamedTextColor.WHITE));
}
String history = builder.toString();

displayMessage(history.substring(0, history.length() - 1));
displayMessage(component);
return true;
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Communicate with ChatGPT right in your Chat.<br>Powered by [OpenAI](https://open
### Installation
1. Press `Win` + `R`
2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod-neo/addons` and press enter (This path may change when lm4 gets released)
3. It should open your Labymod addon directory; Paste the [LabyGPT.jar](https://github.com/RappyLabyAddons/LabyGPT/releases/download/v1.1.0/LabyGPT.jar) in there.
3. It should open your Labymod addon directory; Paste the [LabyGPT.jar](https://github.com/RappyLabyAddons/LabyGPT/releases/download/v1.1.1/LabyGPT.jar) in there.
4. Launch your Labymod client.

If you have any problems with the addon/have update ideas, feel free to
Expand Down

0 comments on commit 3a92233

Please sign in to comment.