Skip to content

Commit

Permalink
Merge pull request #10 from DynxstyGIT/dev
Browse files Browse the repository at this point in the history
Add support for Context Commands
  • Loading branch information
jasonlessenich authored Feb 20, 2022
2 parents 7d57e8f + 351984d commit f766df9
Show file tree
Hide file tree
Showing 22 changed files with 565 additions and 301 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ An very easy-to-use Interaction Handler for JDA!
## Maven
```xml
<dependency>
<groupId>com.dynxsty</groupId>
<artifactId>dih4jda</artifactId>
<groupId>com.github.DynxstyGIT</groupId>
<artifactId>DIH4JDA</artifactId>
<version>${DIH4JDA_VERSION}</version>
</dependency>
```
Expand All @@ -18,14 +18,12 @@ An very easy-to-use Interaction Handler for JDA!
```gradle
plugins {
id 'java'
id 'jitpack'
maven { url 'https://jitpack.io' }
}
dependencies {
[...]
implementation 'com.dynxsty:dih4jda:${DIH4JDA_VERSION}'
implementation 'org.reflections:reflections:0.10.2'
implementation 'net.dv8tion:JDA:5.0.0-alpha.5'
implementation 'com.github.DynxstyGIT:DIH4JDA:${DIH4JDA_VERSION}'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

group 'com.dynxsty'
archivesBaseName = 'dih4jda'
version '1.0_002'
version '1.1'

publishing {
publications {
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/com/dynxsty/dih4jda/DIH4JDA.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.dynxsty.dih4jda;

import com.dynxsty.dih4jda.commands.SlashCommandHandler;
import com.dynxsty.dih4jda.commands.InteractionHandler;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.utils.JDALogger;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;

public class DIH4JDA extends ListenerAdapter {

public JDA jda;
public String commandsPackage;
public long ownerId;
private final JDA jda;
private final String commandsPackage;
private final long ownerId;

public static final org.slf4j.Logger log = JDALogger.getLog(DIH4JDA.class);

/**
* Constructs a new DIH4JDA instance
Expand All @@ -28,24 +31,33 @@ protected DIH4JDA(JDA jda, String commandsPackage, long ownerId) {
}

/**
* Ran once the {@link JDA} instance fires the {@link ReadyEvent}. Mainly does the following two things;
* <ol>
* <li>Creates a new {@link SlashCommandHandler} instance</li>
* <li>Register the Slash commands, depending on the {@link SlashCommandType}, either by looping through all guilds or by registering global slash commands with the JDA instance.</li>
* </ol>
* Ran once the {@link JDA} instance fires the {@link ReadyEvent}.
*
* @param event The {@link ReadyEvent} that was fired.
*/
@Override
public void onReady(@NotNull ReadyEvent event) {
if (commandsPackage == null) return;
SlashCommandHandler handler = new SlashCommandHandler(commandsPackage);
this.jda.addEventListener(handler);
if (getCommandsPackage() == null) return;
InteractionHandler handler = new InteractionHandler(getCommandsPackage());
this.getJDA().addEventListener(handler);
CompletableFuture.runAsync(() -> {
try {
handler.registerSlashCommands(this.jda);
handler.register(this.jda);
} catch (Exception e) {
e.printStackTrace();
}
});
}

public JDA getJDA() {
return this.jda;
}

public String getCommandsPackage() {
return this.commandsPackage;
}

public long getOwnerId() {
return this.ownerId;
}
}
Loading

0 comments on commit f766df9

Please sign in to comment.