-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7447c35
commit 74582c9
Showing
11 changed files
with
251 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,83 @@ | ||
package tech.xigam.cch.command; | ||
|
||
import net.dv8tion.jda.api.entities.Emoji; | ||
import net.dv8tion.jda.api.entities.Member; | ||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.entities.TextChannel; | ||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.components.buttons.Button; | ||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; | ||
import tech.xigam.cch.ComplexCommandHandler; | ||
import tech.xigam.cch.utils.Interaction; | ||
|
||
import java.util.List; | ||
|
||
import static tech.xigam.cch.utils.Validation.isUrl; | ||
|
||
/** | ||
* An interface used by {@link Command}, {@link SubCommand}, and {@link Alias} | ||
*/ | ||
public interface BaseCommand { | ||
/* | ||
* General command information. | ||
*/ | ||
|
||
String getLabel(); | ||
|
||
String getDescription(); | ||
|
||
/* | ||
* Back-end code. | ||
*/ | ||
|
||
void execute(Interaction interaction); | ||
|
||
void prepareForExecution(List<String> arguments, Message message, Member sender, TextChannel channel, boolean skipArguments, ComplexCommandHandler handler); | ||
|
||
void prepareForExecution(SlashCommandInteractionEvent event, ComplexCommandHandler handler); | ||
|
||
void prepareForCompletion(CommandAutoCompleteInteractionEvent event, ComplexCommandHandler handler); | ||
|
||
// void prepareForCallback(MessageReactionAddEvent event, ComplexCommandHandler handler); | ||
|
||
void prepareForCallback(String cmdLabel, ButtonInteractionEvent event, ComplexCommandHandler handler); | ||
|
||
/** | ||
* Creates a button with proper handling for this command. | ||
* | ||
* @param style The button style. | ||
* @param reference The reference to the button (or a URL). | ||
* @param text The text to display on the button. | ||
* @return The button. | ||
*/ | ||
default Button createButton(ButtonStyle style, String reference, String text) { | ||
return Button.of(style, isUrl(reference) ? reference : "<" + this.getLabel().toLowerCase() + ">" + reference, text); | ||
} | ||
|
||
/** | ||
* Creates a button with proper handling for this command. | ||
* | ||
* @param style The button style. | ||
* @param reference The reference to the button (or a URL). | ||
* @param emoji The emoji to show on the button. | ||
* @return The button. | ||
*/ | ||
default Button createButton(ButtonStyle style, String reference, Emoji emoji) { | ||
return Button.of(style, isUrl(reference) ? reference : "<" + this.getLabel().toLowerCase() + ">" + reference, emoji); | ||
} | ||
|
||
/** | ||
* Creates a button with proper handling for this command. | ||
* | ||
* @param style The button style. | ||
* @param reference The reference to the button (or a URL). | ||
* @param text The text to show to the right of the emoji. | ||
* @param emoji The emoji to show on the button. | ||
* @return The button. | ||
*/ | ||
default Button createButton(ButtonStyle style, String reference, String text, Emoji emoji) { | ||
return Button.of(style, isUrl(reference) ? reference : "<" + this.getLabel().toLowerCase() + ">" + reference, text, emoji); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tech.xigam.cch.command; | ||
|
||
import tech.xigam.cch.utils.Callback; | ||
|
||
/** | ||
* Declares a class as callable, allowing: | ||
* - buttons to work | ||
* - forms to work | ||
*/ | ||
public interface Callable { | ||
void callback(Callback callback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tech.xigam.cch.utils; | ||
|
||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; | ||
|
||
/** | ||
* A callback for buttons and forms. | ||
*/ | ||
public final class Callback { | ||
private final boolean isSlash, inGuild; | ||
private final String reference; | ||
|
||
private GenericComponentInteractionCreateEvent interactionExecutor = null; | ||
|
||
private boolean deferred = false; | ||
|
||
public Callback(ButtonInteractionEvent event) { | ||
this.isSlash = true; | ||
this.inGuild = event.isFromGuild(); | ||
this.interactionExecutor = event; | ||
|
||
var rawReference = event.getComponentId(); | ||
this.reference = rawReference.split(">")[1]; | ||
} | ||
|
||
public String getReference() { | ||
return this.reference; | ||
} | ||
|
||
// ---------- UTILITY METHODS ---------- \\ | ||
|
||
public Callback deferEdit() { | ||
if (this.isSlash) | ||
this.interactionExecutor.deferEdit().queue(); | ||
this.deferred = true; | ||
return this; | ||
} | ||
|
||
// ---------- REPLY METHODS ---------- \\ | ||
|
||
public void reply(String message) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.