Skip to content

Commit 31a92e7

Browse files
committed
more updates
1 parent d956a27 commit 31a92e7

18 files changed

+775
-172
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
id 'signing'
99
}
1010

11-
def baseVersion = "4.0.1"
11+
def baseVersion = "4.0.2"
1212
def isSnapshot = false
1313

1414
version = (isSnapshot) ? baseVersion + '-SNAPSHOT' : baseVersion

dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repositories {
33
}
44

55
ext {
6-
jdaVersion = '5.0.0-beta.2'
6+
jdaVersion = '5.0.0-beta.3'
77
jsonVersion = '20220320'
88
lang3Version = '3.12.0'
99
fasterXmlVersion = '2.14.1'

src/main/java/com/readonlydev/api/ClientInterface.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import com.readonlydev.command.Command;
3434
import com.readonlydev.command.Command.Category;
3535
import com.readonlydev.command.CommandListener;
36-
import com.readonlydev.command.client.ServerCommands;
36+
import com.readonlydev.command.ServerCommands;
37+
import com.readonlydev.command.SlashCommand;
3738
import com.readonlydev.command.ctx.ContextMenu;
38-
import com.readonlydev.command.slash.SlashCommand;
3939
import com.readonlydev.settings.GuildSettingsManager;
4040

4141
import net.dv8tion.jda.api.JDA;
@@ -45,7 +45,7 @@
4545
/**
4646
* A Bot Client interface implemented on objects used to hold bot data.
4747
* <p>
48-
* This is implemented in {@link com.readonlydev.command.client.Client ClientImpl} alongside implementation of
48+
* This is implemented in {@link com.readonlydev.command.Client ClientImpl} alongside implementation of
4949
* {@link net.dv8tion.jda.api.hooks.EventListener EventListener} to create a compounded "Client Listener" which catches
5050
* specific kinds of events thrown by JDA and processes them automatically to handle and execute
5151
* {@link com.readonlydev.command.Command Command}s.
@@ -75,13 +75,13 @@
7575
* ID, that'll just flat out throw an {@link java.lang.IllegalArgumentException IllegalArgumentException}).
7676
* <p>
7777
* <b>4)</b> Do not provide strings when using
78-
* {@link com.readonlydev.command.client.ClientBuilder#setEmojis(String, String, String)
78+
* {@link com.readonlydev.command.ClientBuilder#setEmojis(String, String, String)
7979
* ClientBuilder#setEmojis(String, String, String)} that are not unicode emojis or that do not match the
8080
* custom emote format specified in {@link net.dv8tion.jda.api.entities.emoji.Emoji#getFormatted()
8181
* Emote#getAsMention()} (IE: {@code <:EmoteName:EmoteID>}).
8282
* <p>
8383
* <b>5)</b> Avoid using
84-
* {@link com.readonlydev.command.client.Client#linkIds(long, net.dv8tion.jda.api.entities.Message)}. This
84+
* {@link com.readonlydev.command.Client#linkIds(long, net.dv8tion.jda.api.entities.Message)}. This
8585
* will create errors and has no real purpose outside of it's current usage.
8686
*/
8787
public interface ClientInterface
@@ -183,7 +183,7 @@ default void addCommands(Command... commands)
183183
}
184184

185185
/**
186-
* Adds a single {@link com.readonlydev.command.slash.SlashCommand SlashCommand} to this Client's registered
186+
* Adds a single {@link com.readonlydev.command.SlashCommand SlashCommand} to this Client's registered
187187
* SlashCommand.
188188
* <p>
189189
* For Client's containing 20 commands or less, command calls by users will have the bot iterate through the entire
@@ -193,7 +193,7 @@ default void addCommands(Command... commands)
193193
* To prevent delay a Client that has more that 20 Commands registered to it will begin to use <b>indexed calls</b>.
194194
* <br>
195195
* Indexed calls use a {@link java.util.HashMap HashMap} which links their
196-
* {@link com.readonlydev.command.slash.SlashCommand#name name} to the index that which they are located at in the
196+
* {@link com.readonlydev.command.SlashCommand#name name} to the index that which they are located at in the
197197
* ArrayList they are stored.
198198
* <p>
199199
* This means that all insertion and removal of SlashCommands must reorganize the index maintained by the HashMap.
@@ -210,7 +210,7 @@ default void addCommands(Command... commands)
210210
void indexSlashCommand(SlashCommand command);
211211

212212
/**
213-
* Adds a single {@link com.readonlydev.command.slash.SlashCommand SlashCommand} to this Client's registered
213+
* Adds a single {@link com.readonlydev.command.SlashCommand SlashCommand} to this Client's registered
214214
* Commands at the specified index.
215215
* <p>
216216
* For Client's containing 20 commands or less, command calls by users will have the bot iterate through the entire
@@ -316,7 +316,7 @@ default void addCommands(Command... commands)
316316
List<ServerCommands> getServerCommands();
317317

318318
/**
319-
* Returns the list of registered {@link com.readonlydev.command.slash.SlashCommand SlashCommand}s during this
319+
* Returns the list of registered {@link com.readonlydev.command.SlashCommand SlashCommand}s during this
320320
* session.
321321
*
322322
* @return A never-null List of Slash Commands registered during this session
@@ -521,7 +521,7 @@ default void addCommands(Command... commands)
521521
*
522522
* @return {@code true} if the bot uses linked deletion, {@code false} otherwise.
523523
*
524-
* @see com.readonlydev.command.client.ClientBuilder#setLinkedCacheSize(int) ClientBuilder#setLinkedCacheSize(int)
524+
* @see com.readonlydev.command.ClientBuilder#setLinkedCacheSize(int) ClientBuilder#setLinkedCacheSize(int)
525525
*/
526526
boolean usesLinkedDeletion();
527527

@@ -531,7 +531,7 @@ default void addCommands(Command... commands)
531531
* <p>
532532
* The returning object for this is specified via provision of a
533533
* {@link com.readonlydev.settings.GuildSettingsManager GuildSettingsManager} to
534-
* {@link com.readonlydev.command.client.ClientBuilder#setGuildSettingsManager(com.readonlydev.settings.GuildSettingsManager)
534+
* {@link com.readonlydev.command.ClientBuilder#setGuildSettingsManager(com.readonlydev.settings.GuildSettingsManager)
535535
* ClientBuilder#setGuildSettingsManager(GuildSettingsManager)}, more specifically
536536
* {@link GuildSettingsManager#getSettings(net.dv8tion.jda.api.entities.Guild)
537537
* GuildSettingsManager#getSettings(Guild)}.

src/main/java/com/readonlydev/command/client/Client.java renamed to src/main/java/com/readonlydev/command/Client.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
package com.readonlydev.command.client;
25+
package com.readonlydev.command;
2626

2727
import java.time.OffsetDateTime;
2828
import java.time.temporal.ChronoUnit;
@@ -51,18 +51,15 @@
5151
import org.slf4j.LoggerFactory;
5252

5353
import com.readonlydev.api.ClientInterface;
54-
import com.readonlydev.command.Command;
5554
import com.readonlydev.command.Command.Category;
56-
import com.readonlydev.command.CommandListener;
5755
import com.readonlydev.command.arg.parse.ArgumentIndex;
5856
import com.readonlydev.command.ctx.ContextMenu;
5957
import com.readonlydev.command.ctx.MessageContextMenu;
6058
import com.readonlydev.command.ctx.UserContextMenu;
6159
import com.readonlydev.command.event.CommandEvent;
6260
import com.readonlydev.command.event.MessageContextMenuEvent;
61+
import com.readonlydev.command.event.SlashCommandEvent;
6362
import com.readonlydev.command.event.UserContextMenuEvent;
64-
import com.readonlydev.command.slash.SlashCommand;
65-
import com.readonlydev.command.slash.SlashCommandEvent;
6663
import com.readonlydev.common.utils.FixedSizeCache;
6764
import com.readonlydev.common.utils.SafeIdUtil;
6865
import com.readonlydev.settings.GuildSettingsManager;
@@ -131,6 +128,8 @@ public class Client implements ClientInterface, EventListener
131128
private final ScheduledExecutorService executor;
132129
private final GuildSettingsManager<?> manager;
133130

131+
private final LinkedList<SlashCommand> globalCommands;
132+
134133
private final LinkedList<SlashCommand> totalSlashCommands;
135134
private final HashMap<String, Integer> slashCommandIndex;
136135

@@ -208,6 +207,7 @@ public Client(
208207
this.slashCommandIndex = new HashMap<>();
209208
this.totalContextMenus = new LinkedList<>();
210209
this.contextMenuIndex = new HashMap<>();
210+
this.globalCommands = new LinkedList<>();
211211
this.commands = new ArrayList<>();
212212
this.categoryToCommandListMap = new HashMap<>();
213213
this.categoryToCommandListMap.put(new Category("Uncategorized"), new ArrayList<>());
@@ -267,6 +267,7 @@ public Client(
267267
for (SlashCommand command : globalSlashCommands)
268268
{
269269
indexSlashCommand(command);
270+
globalCommands.add(command);
270271
}
271272

272273
// Load context menus
@@ -277,6 +278,8 @@ public Client(
277278

278279
for (ServerCommands serverCmds : serverCommands)
279280
{
281+
this.serverCommands.add(serverCmds);
282+
280283
for (SlashCommand serverSlashCmd : serverCmds.getSlashCommands())
281284
{
282285
indexSlashCommand(serverSlashCmd);
@@ -316,7 +319,7 @@ public List<ServerCommands> getServerCommands()
316319
@Override
317320
public List<SlashCommand> getGlobalSlashCommands()
318321
{
319-
return totalSlashCommands.stream().filter(SlashCommand::isGlobalCommand).toList();
322+
return globalCommands;
320323
}
321324

322325
@Override
@@ -718,10 +721,7 @@ private void onReady(ReadyEvent event)
718721
manager.init(event.getJDA());
719722
}
720723

721-
if (!serverCommands.isEmpty())
722-
{
723-
upsertServerCommands(event.getJDA());
724-
}
724+
upsertServerCommands(event.getJDA());
725725

726726
upsertGlobalSlashCommands(event.getJDA());
727727
}
@@ -730,24 +730,34 @@ public void upsertServerCommands(JDA jda)
730730
{
731731
if (serverCommands.isEmpty())
732732
{
733+
LOG.info("ServerCommands is empty. Skipping guildCommandUpsert");
733734
return;
734735
}
735736

736737
for (ServerCommands server : serverCommands)
737738
{
738739
List<CommandData> data = new ArrayList<>();
739740

740-
data.addAll(server.getSlashCommands().stream().map(SlashCommand::getCommandData).toList());
741-
data.addAll(server.getContextMenus().stream().map(ContextMenu::getCommandData).toList());
741+
for(SlashCommand cmd : server.getSlashCommands())
742+
{
743+
data.add(cmd.build());
744+
}
745+
746+
for(ContextMenu ctx : server.getContextMenus())
747+
{
748+
data.add(ctx.build());
749+
}
742750

743751
// Attempt to retrieve the provided guild
744-
Guild guild = jda.getGuildById(server.getServerId());
752+
Guild guild = jda.getGuildById(server.getGuildIdLong());
745753
if (guild == null)
746754
{
747-
LOG.error("Specified guild '{}' is null! Slash Commands will NOT be added!", server.getServerId());
755+
LOG.error("Specified guild '{}' is null! Slash Commands will NOT be added!", server.getGuildIdLong());
748756
return;
749757
} else
750758
{
759+
guild.updateCommands().queue();
760+
751761
//@noformat
752762
guild.updateCommands().addCommands(data).queue(
753763
priv -> LOG.info("Successfully added " + server.getSlashCommands().size() + " slash commands and " + server.getContextMenus().size() + " menus to server " + guild.getName()),
@@ -760,9 +770,11 @@ public void upsertServerCommands(JDA jda)
760770
public void upsertGlobalSlashCommands(JDA jda)
761771
{
762772
// Get all commands
763-
List<SlashCommand> globalCommands = totalSlashCommands.stream().filter(SlashCommand::isGlobalCommand).toList();
764773
List<CommandData> data = new ArrayList<>();
765-
data.addAll(globalCommands.stream().map(SlashCommand::getCommandData).toList());
774+
for(SlashCommand cmd : globalCommands)
775+
{
776+
data.add(cmd.build());
777+
}
766778

767779
jda.updateCommands().addCommands(data).queue(commands -> LOG.info("Successfully added " + globalCommands.size() + " global slash commands!"));
768780
}
@@ -988,6 +1000,7 @@ private void onSlashCommand(SlashCommandInteractionEvent event)
9881000
listener.onSlashCommand(commandEvent, command);
9891001
}
9901002
uses.put(command.getName(), uses.getOrDefault(command.getName(), 0) + 1);
1003+
9911004
command.run(commandEvent);
9921005
// Command is done
9931006
}

0 commit comments

Comments
 (0)