Skip to content

Commit

Permalink
smarter emoji handling (DiscordButtonTag and SelectionTag)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 9, 2021
1 parent 2c69ebe commit 8c0246e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
<bukkit.version>1.17.1-R0.1-SNAPSHOT</bukkit.version>
<denizen.version>1.2.2-SNAPSHOT</denizen.version>
<denizen.version>1.2.3-SNAPSHOT</denizen.version>
</properties>

<!-- Repositories -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public DiscordCommandCommand() {
//
// Slash commands and replies to interactions, have limitations. See <@link url https://gist.github.com/MinnDevelopment/b883b078fdb69d0e568249cc8bf37fe9>.
//
// See also Discord's internal API documentation for commands: <@link url https://discord.com/developers/docs/interactions/application-commands>
//
// Generally used alongside <@link command discordinteraction>
//
// The command should usually be ~waited for. See <@link language ~waitable>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public DiscordInteractionCommand() {
//
// The "ephemeral" argument can be used to have the reply message be visible to that one user.
//
// You should almost always defer an interaction before replying. A defer will override a reply in terms of being ephemeral.
// You should usually defer an interaction before replying.
// If you defer, the 'ephemeral' option can only be set by the defer - you cannot change it with the later reply.
// Replying to an interaction uses similar logic to normal messaging. See <@link command discordmessage>.
// If you deferred without using 'ephemeral', the 'delete' option will delete the "Thinking..." message.
//
// Slash commands and replies to interactions, have limitations. See <@link url https://gist.github.com/MinnDevelopment/b883b078fdb69d0e568249cc8bf37fe9>.
//
Expand All @@ -61,6 +63,10 @@ public DiscordInteractionCommand() {
// <entry[saveName].command> returns the DiscordCommandTag of a slash command upon creation, when the command is ~waited for.
//
// @Usage
// Use to quickly reply to a slash command interaction.
// - ~discordinteraction reply interaction:<context.interaction> "hello!"
//
// @Usage
// Use to defer and reply to a slash command interaction.
// - ~discordinteraction defer interaction:<context.interaction>
// - ~discordinteraction reply interaction:<context.interaction> <context.options.get[hello].if_null[world]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,18 @@ public DiscordButtonTag(Button button) {
}

public Button build() {
ObjectTag style = buttonData.getObject("style");
ObjectTag id = buttonData.getObject("id");
ObjectTag label = buttonData.getObject("label");
ObjectTag emoji = buttonData.getObject("emoji");
ButtonStyle styleData;
Button button = null;
boolean isValidType = false;
for (ButtonStyle val : ButtonStyle.values()) {
if (val.name().toUpperCase().equals(
style.toString().toUpperCase()
)) {
isValidType = true;
break;
}
}
if (!isValidType) {
if (id == null) {
return null;
}
styleData = ButtonStyle.valueOf(style.toString().toUpperCase());
ObjectTag label = buttonData.getObject("label");
ObjectTag emoji = buttonData.getObject("emoji");
ObjectTag style = buttonData.getObject("style");
ButtonStyle styleData = ButtonStyle.PRIMARY;
if (style != null) {
styleData = ButtonStyle.valueOf(style.toString().toUpperCase());
}
if (id != null) {
if (emoji != null) {
Emoji emojiData = Emoji.fromUnicode(emoji.toString());
if (emojiData != null) {
button = Button.of(styleData, id.toString(), emojiData);
}
} else {
if (label != null) {
button = Button.of(styleData, id.toString(), label.toString());
}
}
}
return button;
return Button.of(styleData, id.toString(), label == null ? null : label.toString(), emoji == null ? null : Emoji.fromMarkdown(emoji.toString()));
}

public MapTag buttonData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public SelectionMenu.Builder build(TagContext context) {
ElementTag emoji = (ElementTag) option.getObject("emoji");
Emoji emojiData = null;
if (emoji != null) {
emojiData = Emoji.fromUnicode(emoji.toString());
emojiData = Emoji.fromMarkdown(emoji.toString());
}
if (label == null || value == null) {
return null;
Expand Down

0 comments on commit 8c0246e

Please sign in to comment.