diff --git a/pom.xml b/pom.xml
index 78f66d8d..1446dcf8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,12 @@
JDA
4.4.0_350
+
+
+ joda-time
+ joda-time
+ 2.12.4
+
diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java
new file mode 100644
index 00000000..e8b2fa04
--- /dev/null
+++ b/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java
@@ -0,0 +1,66 @@
+package me.chayapak1.chomens_bot.commands;
+
+import me.chayapak1.chomens_bot.command.Command;
+import me.chayapak1.chomens_bot.command.CommandContext;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TimeCommand implements Command {
+ public String name() { return "time"; }
+
+ public String description() {
+ return "Shows the date and time for the specified timezone";
+ }
+
+ public List usage() {
+ final List usages = new ArrayList<>();
+ usages.add("");
+
+ return usages;
+ }
+
+ public List alias() {
+ final List aliases = new ArrayList<>();
+ aliases.add("dateandtime");
+ aliases.add("date");
+
+ return aliases;
+ }
+
+ public int trustLevel() {
+ return 0;
+ }
+
+ public Component execute(CommandContext context, String[] args, String[] fullArgs) {
+ final String timezone = args[0];
+
+ DateTimeZone zone;
+ try {
+ zone = DateTimeZone.forID(timezone);
+ } catch (IllegalArgumentException ignored) {
+ return Component.text("Invalid timezone (case-sensitive)").color(NamedTextColor.RED);
+ }
+
+ final DateTime dateTime = new DateTime(zone);
+
+ final DateTimeFormatter formatter = DateTimeFormat.forPattern("EEEE, MMMM d, YYYY, hh:mm:ss a");
+ final String formattedTime = formatter.print(dateTime);
+
+ context.sendOutput(
+ Component.translatable(
+ "The current date and time for the timezone %s is: %s",
+ Component.text(timezone).color(NamedTextColor.AQUA),
+ Component.text(formattedTime).color(NamedTextColor.GREEN)
+ )
+ );
+
+ return Component.text("success");
+ }
+}
diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java
new file mode 100644
index 00000000..71197dae
--- /dev/null
+++ b/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java
@@ -0,0 +1,93 @@
+package me.chayapak1.chomens_bot.commands;
+
+import me.chayapak1.chomens_bot.Bot;
+import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry;
+import me.chayapak1.chomens_bot.command.Command;
+import me.chayapak1.chomens_bot.command.CommandContext;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.ClickEvent;
+import net.kyori.adventure.text.event.HoverEvent;
+import net.kyori.adventure.text.format.NamedTextColor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UUIDCommand implements Command {
+ public String name() { return "uuid"; }
+
+ public String description() {
+ return "Shows your UUID or other player's UUID";
+ }
+
+ public List usage() {
+ final List usages = new ArrayList<>();
+ usages.add("[{username}]");
+
+ return usages;
+ }
+
+ public List alias() {
+ final List aliases = new ArrayList<>();
+ aliases.add("");
+
+ return aliases;
+ }
+
+ public int trustLevel() {
+ return 0;
+ }
+
+ public Component execute(CommandContext context, String[] args, String[] fullArgs) {
+ final Bot bot = context.bot();
+
+ if (args.length > 0) {
+ final MutablePlayerListEntry entry = bot.players().getEntry(String.join(" ", args));
+
+ if (entry == null) return Component.text("Invalid player name").color(NamedTextColor.RED);
+
+ final String name = entry.profile().getName();
+ final String uuid = entry.profile().getIdAsString();
+
+ context.sendOutput(
+ Component.translatable(
+ "%s's UUID: %s",
+ Component.text(name),
+ Component
+ .text(uuid)
+ .hoverEvent(
+ HoverEvent.showText(
+ Component.text("Click here to copy the UUID to your clipboard").color(NamedTextColor.GREEN)
+ )
+ )
+ .clickEvent(
+ ClickEvent.copyToClipboard(uuid)
+ )
+ .color(NamedTextColor.AQUA)
+ ).color(NamedTextColor.GREEN)
+ );
+ } else {
+ final MutablePlayerListEntry entry = context.sender();
+
+ final String uuid = entry.profile().getIdAsString();
+
+ context.sendOutput(
+ Component.translatable(
+ "Your UUID: %s",
+ Component
+ .text(uuid)
+ .hoverEvent(
+ HoverEvent.showText(
+ Component.text("Click here to copy the UUID to your clipboard").color(NamedTextColor.GREEN)
+ )
+ )
+ .clickEvent(
+ ClickEvent.copyToClipboard(uuid)
+ )
+ .color(NamedTextColor.AQUA)
+ ).color(NamedTextColor.GREEN)
+ );
+ }
+
+ return Component.text("success");
+ }
+}
diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java
index 7340fa86..416af28e 100644
--- a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java
+++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java
@@ -40,6 +40,8 @@ public class CommandHandlerPlugin {
registerCommand(new ClearChatCommand());
registerCommand(new ListCommand());
registerCommand(new ServerEvalCommand());
+ registerCommand(new UUIDCommand());
+ registerCommand(new TimeCommand());
}
public void registerCommand (Command command) {
diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java
index 9f5d90cb..338e41e5 100644
--- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java
+++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java
@@ -70,16 +70,17 @@ public class DiscordPlugin {
for (Bot bot : Main.allBots) {
String channelId = servers.get(bot.host() + ":" + bot.port());
- boolean channelAlreadyAddedListeners = alreadyAddedListeners.getOrDefault(channelId, false);
-
bot.addListener(new SessionAdapter() {
@Override
public void connected(ConnectedEvent event) {
boolean channelAlreadyAddedListeners = alreadyAddedListeners.getOrDefault(channelId, false);
- if (channelAlreadyAddedListeners) return;
sendMessageInstantly("Successfully connected to: " + "`" + bot.host() + ":" + bot.port() + "`", channelId);
+ if (channelAlreadyAddedListeners) return;
+
+ alreadyAddedListeners.put(channelId, true);
+
jda.addEventListener(new ListenerAdapter() {
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
@@ -162,8 +163,6 @@ public class DiscordPlugin {
}
});
- alreadyAddedListeners.put(channelId, true);
-
bot.chat().addListener(new ChatPlugin.ChatListener() {
@Override
public void systemMessageReceived (String ignoredMessage, Component component) {