From 9a55cd11f431687b8328c0f7a421f7fd3080c63a Mon Sep 17 00:00:00 2001
From: ChomeNS <95471003+ChomeNS@users.noreply.github.com>
Date: Sun, 11 Jun 2023 20:29:35 +0700
Subject: [PATCH] add description to commands yes i need to modify brigaydier
to do this
---
pom.xml | 2 +-
.../chipmunkbot/commands/EchoCommand.java | 1 +
.../chipmunkbot/commands/HelpCommand.java | 27 ++++++++++++++-----
.../chipmunkbot/commands/InfoCommand.java | 1 +
.../chipmunkbot/commands/LogQueryCommand.java | 1 +
.../chipmunkbot/commands/MusicCommand.java | 1 +
.../chipmunkbot/commands/NetMsgCommand.java | 9 ++++---
.../commands/ReconnectCommand.java | 3 ++-
.../chipmunkbot/commands/RunCommand.java | 9 ++++---
.../chipmunkbot/commands/SayCommand.java | 3 +++
.../chipmunkbot/commands/TestCommand.java | 3 ++-
11 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/pom.xml b/pom.xml
index 0ccbf4d..02c3bff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,7 @@
com.mojang
brigadier
- 1.0.18
+ 1.1.0-SNAPSHOT
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/EchoCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/EchoCommand.java
index c3043a2..28173b6 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/EchoCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/EchoCommand.java
@@ -16,6 +16,7 @@ public class EchoCommand {
dispatcher.register(
literal("echo")
+ .describe(ComponentMessage.wrap(Component.text("Echoes a message")))
.then(
argument("text", greedyString())
.executes(instance::echo)
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/HelpCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/HelpCommand.java
index cc2f164..2d01e61 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/HelpCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/HelpCommand.java
@@ -1,5 +1,6 @@
package land.chipmunk.chipmunkbot.commands;
+import com.mojang.brigadier.Message;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.Configuration;
import land.chipmunk.chipmunkbot.command.*;
@@ -26,11 +27,12 @@ public class HelpCommand {
dispatcher.register(
literal("help")
- .executes(instance::sendCommandList)
- .then(
- argument("command", greedyString())
- .executes(instance::sendUsage)
- )
+ .describe(ComponentMessage.wrap(Component.text("Shows the help")))
+ .executes(instance::sendCommandList)
+ .then(
+ argument("command", greedyString())
+ .executes(instance::sendUsage)
+ )
);
}
@@ -87,6 +89,7 @@ public class HelpCommand {
}
public Component generateUsages (Configuration config, CommandDispatcher dispatcher, CommandNode node) {
+ final List components = new ArrayList<>();
final List usages = new ArrayList<>();
for (String usage : dispatcher.getAllUsage(node, null, true)) {
@@ -103,6 +106,18 @@ public class HelpCommand {
);
}
- return Component.join(JoinConfiguration.separator(Component.newline()), usages);
+ final Message description = node.getDescription();
+
+ components.add(
+ Component.translatable(
+ "%s - %s",
+ Component.text(node.getName()).color(TextColor.fromHexString(config.color().primary())),
+ Component.text(description == null ? "No description" : description.getString()).color(NamedTextColor.GRAY)
+ ).color(NamedTextColor.DARK_GRAY)
+ );
+
+ components.add(Component.join(JoinConfiguration.separator(Component.newline()), usages));
+
+ return Component.join(JoinConfiguration.separator(Component.newline()), components);
}
}
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/InfoCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/InfoCommand.java
index e1800be..388a290 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/InfoCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/InfoCommand.java
@@ -28,6 +28,7 @@ public class InfoCommand {
dispatcher.register(
literal("info")
+ .describe(ComponentMessage.wrap(Component.text("Shows the info about the bot")))
.executes(instance::sendBotInfo)
.then(
literal("server")
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/LogQueryCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/LogQueryCommand.java
index ecf96dd..2ac3b95 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/LogQueryCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/LogQueryCommand.java
@@ -38,6 +38,7 @@ public class LogQueryCommand {
dispatcher.register(
literal("logquery")
+ .describe(ComponentMessage.wrap(Component.text("Queries the bots log files")))
.then(
literal("abort")
.executes(instance::abortCommand)
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java
index e27eba2..a5d5be5 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java
@@ -42,6 +42,7 @@ public class MusicCommand {
dispatcher.register(
literal("music")
+ .describe(ComponentMessage.wrap(Component.text("Play musics")))
.then(
literal("play")
.then(
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java
index 3b99f6e..c7b5a9a 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java
@@ -22,10 +22,11 @@ public class NetMsgCommand {
dispatcher.register(
literal("netmsg")
- .then(
- argument("message", greedyString())
- .executes(instance::netmsg)
- )
+ .describe(ComponentMessage.wrap(Component.text("Broadcasts a message to every server")))
+ .then(
+ argument("message", greedyString())
+ .executes(instance::netmsg)
+ )
);
}
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/ReconnectCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/ReconnectCommand.java
index 68f058c..e5bf34a 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/ReconnectCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/ReconnectCommand.java
@@ -13,7 +13,8 @@ public class ReconnectCommand {
dispatcher.register(
literal("reconnect")
- .executes(instance::reconnect)
+ .describe(ComponentMessage.wrap(Component.text("Reconnects the bot")))
+ .executes(instance::reconnect)
);
}
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/RunCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/RunCommand.java
index e613582..1708737 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/RunCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/RunCommand.java
@@ -20,10 +20,11 @@ public class RunCommand {
dispatcher.register(
literal("run")
- .then(
- argument("command", greedyString())
- .executes(instance::run)
- )
+ .describe(ComponentMessage.wrap(Component.text("Runs a command in the command core and return its output")))
+ .then(
+ argument("command", greedyString())
+ .executes(instance::run)
+ )
);
}
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/SayCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/SayCommand.java
index 034e05d..c6fee57 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/SayCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/SayCommand.java
@@ -4,6 +4,8 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.command.CommandSource;
+import land.chipmunk.chipmunkbot.command.ComponentMessage;
+import net.kyori.adventure.text.Component;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
@@ -16,6 +18,7 @@ public class SayCommand {
dispatcher.register(
literal("say")
+ .describe(ComponentMessage.wrap(Component.text("Makes the bot say a message")))
.then(
argument("message", greedyString())
.executes(instance::say)
diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/TestCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/TestCommand.java
index f1619d9..6a41a2c 100644
--- a/src/main/java/land/chipmunk/chipmunkbot/commands/TestCommand.java
+++ b/src/main/java/land/chipmunk/chipmunkbot/commands/TestCommand.java
@@ -12,7 +12,8 @@ public class TestCommand {
dispatcher.register(
literal("test")
- .executes(instance::helloWorld)
+ .describe(ComponentMessage.wrap(Component.text("Tests if the bot is online/working")))
+ .executes(instance::helloWorld)
);
}