Skip to content

Commit

Permalink
Merge pull request #9 from Azzerial/development
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
azzerial authored Sep 16, 2021
2 parents 7b9c0f4 + 04a05e5 commit 4be0648
Show file tree
Hide file tree
Showing 28 changed files with 799 additions and 186 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@

## Features

A few of the things you can do with Slash Commands:
A few things you can do with the library:

* Create and manage Slash Commands
* Assign callbacks to Slash Commands events (supports per [command path](https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/interactions/commands/CommandInteraction.html#getCommandPath()) callbacks)
* Assign callbacks to buttons
* Session system for interactions (with session store)
* Assign callbacks to Slash Commands (supports per [command path](https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/interactions/commands/CommandInteraction.html#getCommandPath()) and wildcard callbacks)
* Assign callbacks to message components:
* Buttons
* Selection Menus
* Bind data to a message component:
* Raw data buffer
* Session storage

## How to Use

Expand All @@ -48,7 +52,7 @@ public class PingCommand {
public static void main(String[] args) throws LoginException, InterruptedException {
final JDA jda = JDABuilder.createDefault(...)
.build()
.awaitReady();
.awaitReady(); // wait for JDA to be connected (mandatory)
final SlashClient slash = SlashClientBuilder.create(jda)
.addCommand(new PingCommand()) // register the ping command
.build();
Expand Down Expand Up @@ -82,7 +86,7 @@ repositories {
}
dependencies {
implementation 'com.github.azzerial.slash-commands:api:1.0'
implementation 'com.github.azzerial.slash-commands:api:1.1'
}
```

Expand All @@ -99,16 +103,17 @@ dependencies {
<dependency>
<groupId>com.github.azzerial.slash-commands</groupId>
<artifactId>api</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>
```

## License

This project is licensed under the [Apache License 2.0](LICENSE) © 2021 [Robin Mercier](https://github.com/azzerial/).
This project is licensed under the [Apache License 2.0](LICENSE) © 2021 [Robin Mercier](https://github.com/Azzerial).

---

<p align="center">
Slash Commands by <a href="https://github.com/azzerial">@Azzerial</a>
Slash Commands by <a href="https://github.com/Azzerial">Robin Mercier</a> •
<a href="https://www.azzerial.net">azzerial.net</a>
</p>
2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ ext.moduleName = 'api'
archivesBaseName = moduleName

dependencies {
implementation ('net.dv8tion:JDA:4.3.0_277')
implementation jda()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
* limitations under the License.
*/

package com.github.azzerial.slash;
package net.azzerial.slash;

import com.github.azzerial.slash.internal.CommandRegistry;
import com.github.azzerial.slash.internal.InteractionListener;
import net.azzerial.slash.internal.CommandRegistry;
import net.azzerial.slash.internal.InteractionListener;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.hooks.EventListener;

import java.util.EnumSet;

public final class SlashClient {

private final JDA jda;
Expand All @@ -42,4 +44,35 @@ public final class SlashClient {
public SlashCommand getCommand(String tag) {
return registry.getCommand(tag);
}

/* Nested Classes */

public enum Flag {
DELETE_UNREGISTERED_COMMANDS;

private final boolean isDefault;

/* Constructors */

Flag() {
this(false);
}

Flag(boolean isDefault) {
this.isDefault = isDefault;
}

/* Methods */

public static EnumSet<Flag> getDefault() {
final EnumSet<Flag> set = EnumSet.noneOf(Flag.class);

for (Flag flag : values()) {
if (flag.isDefault) {
set.add(flag);
}
}
return set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,30 @@
* limitations under the License.
*/

package com.github.azzerial.slash;
package net.azzerial.slash;

import com.github.azzerial.slash.internal.CommandRegistry;
import net.azzerial.slash.SlashClient.Flag;
import net.azzerial.slash.internal.CommandRegistry;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.internal.utils.Checks;

import java.util.Collection;
import java.util.EnumSet;
import java.util.List;

public final class SlashClientBuilder {

private final JDA jda;
private final CommandRegistry registry;

private boolean deleteUnregisteredCommands = false;
private final EnumSet<Flag> flags;

/* Constructors */

private SlashClientBuilder(JDA jda) {
this.jda = jda;
this.registry = new CommandRegistry(jda);
this.flags = Flag.getDefault();
}

/* Methods */
Expand All @@ -59,12 +61,18 @@ public SlashClientBuilder addCommands(Object... commands) {
return this;
}

public SlashClientBuilder deleteUnregisteredCommands(boolean enabled) {
this.deleteUnregisteredCommands = enabled;
public SlashClientBuilder setFlag(Flag flag, boolean enabled) {
Checks.notNull(flag, "Flag");
if (enabled) {
flags.add(flag);
} else {
flags.remove(flag);
}
return this;
}

public SlashClient build() {
Checks.check(jda.getStatus() == JDA.Status.CONNECTED, "JDA is not JDA.Status.CONNECTED! Maybe you forgot to call JDA#awaitReady()?");
final Collection<SlashCommand> commands = registry.getCommands();

loadGlobalCommands(commands);
Expand All @@ -81,7 +89,7 @@ private void loadGlobalCommands(Collection<SlashCommand> commands) {
for (Command cmd : cmds) {
if (cmd.getName().equals(command.getData().getName())) {
command.putCommand(SlashCommand.GLOBAL, cmd);
} else if (deleteUnregisteredCommands) {
} else if (flags.contains(Flag.DELETE_UNREGISTERED_COMMANDS)) {
cmd.delete().queue();
}
}
Expand All @@ -97,7 +105,7 @@ private void loadGuildCommands(Collection<SlashCommand> commands) {
for (Command cmd : cmds) {
if (cmd.getName().equals(command.getData().getName())) {
command.putCommand(guild.getIdLong(), cmd);
} else if (deleteUnregisteredCommands) {
} else if (flags.contains(Flag.DELETE_UNREGISTERED_COMMANDS)) {
cmd.delete().queue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.github.azzerial.slash;
package net.azzerial.slash;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.github.azzerial.slash.annotations;
package net.azzerial.slash.annotations;

import java.lang.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.github.azzerial.slash.annotations;
package net.azzerial.slash.annotations;

import java.lang.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,36 @@
* limitations under the License.
*/

package com.github.azzerial.slash.annotations;
package net.azzerial.slash.annotations;

/**
* This enum represents the type of a Slash Command option.
*/
public enum OptionType {
STRING,
INTEGER,
STRING(true),
INTEGER(true),
BOOLEAN,
USER,
CHANNEL,
ROLE,
MENTIONABLE
MENTIONABLE,
NUMBER(true);

private final boolean supportsChoices;

/* Constructors */

OptionType() {
this(false);
}

OptionType(boolean supportsChoices) {
this.supportsChoices = supportsChoices;
}

/* Getters & Setters */

public boolean canSupportsChoices() {
return supportsChoices;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.github.azzerial.slash.annotations;
package net.azzerial.slash.annotations;

import java.lang.annotation.*;

Expand Down Expand Up @@ -74,6 +74,18 @@
String value() default "";
}

/**
* This annotation labels a method as a Slash Command selection menu handler.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface SelectionMenu {

/** The tag of the selection menu. */
String value();
}

/**
* This annotations assigns an identification tag to a Slash Command for registration purposes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.github.azzerial.slash.annotations;
package net.azzerial.slash.annotations;

import java.lang.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.github.azzerial.slash.annotations;
package net.azzerial.slash.annotations;

import java.lang.annotation.*;

Expand Down
Loading

0 comments on commit 4be0648

Please sign in to comment.