Skip to content

Commit

Permalink
Cleanup that PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 16, 2021
1 parent 34cd4ac commit 2161ddb
Show file tree
Hide file tree
Showing 9 changed files with 505 additions and 490 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.denizenscript.ddiscordbot;

import com.denizenscript.ddiscordbot.commands.DiscordCommand;
import com.denizenscript.ddiscordbot.commands.DiscordConnectCommand;
import com.denizenscript.ddiscordbot.commands.DiscordInteractionCommand;
import com.denizenscript.ddiscordbot.commands.DiscordMessageCommand;
import com.denizenscript.ddiscordbot.commands.DiscordReactCommand;
import com.denizenscript.ddiscordbot.commands.*;
import com.denizenscript.ddiscordbot.events.*;
import com.denizenscript.ddiscordbot.objects.*;
import com.denizenscript.denizencore.utilities.debugging.Debug;
Expand Down Expand Up @@ -38,6 +34,7 @@ public void onEnable() {
instance = this;
try {
DenizenCore.getCommandRegistry().registerCommand(DiscordCommand.class);
DenizenCore.getCommandRegistry().registerCommand(DiscordCommandCommand.class);
DenizenCore.getCommandRegistry().registerCommand(DiscordConnectCommand.class);
DenizenCore.getCommandRegistry().registerCommand(DiscordInteractionCommand.class);
DenizenCore.getCommandRegistry().registerCommand(DiscordMessageCommand.class);
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.Holdable;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.dv8tion.jda.api.JDA;
Expand Down Expand Up @@ -69,7 +68,7 @@ public DiscordMessageCommand() {
//
// @Usage
// Use to message an embed to a Discord channel.
// - ~discordmessage id:mybot channel:<discord[mybot].group[Denizen].channel[bot-spam]> "<discord_embed.with[title].as[hi].with[description].as[This is an embed!]>"
// - ~discordmessage id:mybot channel:<discord[mybot].group[Denizen].channel[bot-spam]> "<discord_embed[title=hi;description=this is an embed!]>"
//
// @Usage
// Use to message a Discord channel and record the ID.
Expand Down Expand Up @@ -127,7 +126,7 @@ else if (!scriptEntry.hasObject("no_mention")
}
else if (!scriptEntry.hasObject("rows")
&& arg.matchesPrefix("rows")) {
scriptEntry.addObject("rows", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(ListTag.class, scriptEntry));
scriptEntry.addObject("rows", ListTag.getListFor(arg.object, scriptEntry.getContext()).filter(ListTag.class, scriptEntry));
}
else if (!scriptEntry.hasObject("message")) {
scriptEntry.addObject("message", new ElementTag(arg.getRawValue()));
Expand All @@ -150,7 +149,7 @@ public static List<ActionRow> createRows(ScriptEntry scriptEntry, List<ListTag>
for (ListTag row : rows) {
List<Button> buttons = new ArrayList<>();
for (DiscordButtonTag button : row.filter(DiscordButtonTag.class, scriptEntry.getContext())) {
Button built = button.build(scriptEntry.getContext());
Button built = button.build();
if (built != null) {
buttons.add(built);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.denizenscript.ddiscordbot.objects.DiscordGroupTag;
import com.denizenscript.ddiscordbot.objects.DiscordInteractionTag;
import com.denizenscript.denizencore.objects.ObjectTag;

import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;

public class DiscordButtonClickedScriptEvent extends DiscordScriptEvent {
Expand Down Expand Up @@ -78,14 +77,14 @@ public ObjectTag getContext(String name) {
}
break;
case "interaction":
return new DiscordInteractionTag(botID, getEvent().getInteraction());
return DiscordInteractionTag.getOrCreate(botID, getEvent().getInteraction());
case "button":
return new DiscordButtonTag(getEvent().getButton());
}

return super.getContext(name);
}

@Override
public String getName() {
return "DiscordButtonClicked";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.utilities.text.StringHolder;

import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;

Expand Down Expand Up @@ -88,15 +87,15 @@ public ObjectTag getContext(String name) {
}
break;
case "interaction":
return new DiscordInteractionTag(botID, getEvent().getInteraction());
return DiscordInteractionTag.getOrCreate(botID, getEvent().getInteraction());
case "command":
return new DiscordCommandTag(botID, getEvent().isFromGuild() ? getEvent().getGuild().getIdLong() : 0, getEvent().getCommandIdLong());
case "options": {
Map<StringHolder, ObjectTag> options = new HashMap<>();
for (OptionMapping mapping : getEvent().getOptions()) {
ObjectTag result;
switch (mapping.getType()) {
case STRING:
case STRING:
case SUB_COMMAND:
case SUB_COMMAND_GROUP:
result = new ElementTag(mapping.getAsString()); break;
Expand All @@ -111,21 +110,21 @@ public ObjectTag getContext(String name) {
else {
result = new DiscordUserTag(botID, mapping.getAsMentionable().getIdLong());
}
break;
break;
}
case ROLE: result = new DiscordRoleTag(botID, mapping.getAsRole()); break;
case USER: result = new DiscordUserTag(botID, mapping.getAsUser()); break;
default: result = new ElementTag(botID, null);
}
options.put(new StringHolder(mapping.getName()), result);
}
return new MapTag(options);
return new MapTag(options);
}
}

return super.getContext(name);
}

@Override
public String getName() {
return "DiscordSlashCommand";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.denizenscript.ddiscordbot.objects;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;

import com.denizenscript.denizencore.objects.Fetchable;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
Expand All @@ -14,11 +10,14 @@
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.text.StringHolder;

import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.interactions.components.ButtonStyle;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;

public class DiscordButtonTag implements ObjectTag {

// <--[ObjectType]
Expand Down Expand Up @@ -68,30 +67,24 @@ public DiscordButtonTag(MapTag map) {

public DiscordButtonTag(Button button) {
buttonData = new MapTag();

if (button.getStyle() != null && button.getStyle().name() != null) {
buttonData.putObject("style", new ElementTag(button.getStyle().name()));
}
buttonData.putObject("style", new ElementTag(button.getStyle().name()));
buttonData.putObject("label", new ElementTag(button.getLabel()));
if (button.getId() != null) {
buttonData.putObject("id", new ElementTag(button.getId()));
}
if (button.getLabel() != null) {
buttonData.putObject("label", new ElementTag(button.getLabel()));
}
if (button.getEmoji() != null && button.getEmoji().getName() != null) {
if (button.getEmoji() != null) {
buttonData.putObject("emoji", new ElementTag(button.getEmoji().getName()));
}
}

public Button build(TagContext context) {
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 = null;
ButtonStyle styleData;
Button button = null;
boolean isValidType = false;

for (ButtonStyle val : ButtonStyle.values()) {
if (val.name().toUpperCase().equals(
style.toString().toUpperCase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.denizenscript.ddiscordbot.objects;

import java.util.List;

import com.denizenscript.ddiscordbot.DenizenDiscordBot;
import com.denizenscript.ddiscordbot.DiscordConnection;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
import com.denizenscript.denizencore.flags.RedirectionFlagTracker;
Expand All @@ -19,14 +16,15 @@
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.utilities.CoreUtilities;

import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.Command.Choice;
import net.dv8tion.jda.api.interactions.commands.Command.Option;

import java.util.List;

public class DiscordCommandTag implements ObjectTag, FlaggableObject {

// <--[ObjectType]
// @name DiscordCommandTag
// @prefix discordcommand
Expand Down Expand Up @@ -176,7 +174,7 @@ public void reapplyTracker(AbstractFlagTracker tracker) {
}

public static void registerTags() {

AbstractFlagTracker.registerFlagHandlers(tagProcessor);

// <--[tag]
Expand Down Expand Up @@ -217,19 +215,19 @@ public static void registerTags() {
// @returns ListTag(MapTag)
// @plugin dDiscordBot
// @description
// Returns the option MapTags of the command. This is the same value as the one provided when creating a command.
// Returns the option MapTags of the command. This is the same value as the one provided when creating a command, as documented in <@link command DiscordCommand>.
// -->
registerTag("options", (attribute, object) -> {
ListTag options = new ListTag();
for (Option option : object.getCommand().getOptions()) {
for (Command.Option option : object.getCommand().getOptions()) {
MapTag map = new MapTag();
map.putObject("type", new ElementTag(option.getType().toString().toLowerCase().replaceAll("_", "")));
map.putObject("name", new ElementTag(option.getName()));
map.putObject("description", new ElementTag(option.getDescription()));
map.putObject("required", new ElementTag(option.isRequired()));
if (option.getType() == OptionType.STRING || option.getType() == OptionType.INTEGER) {
ListTag choices = new ListTag();
for (Choice choice : option.getChoices()) {
for (Command.Choice choice : option.getChoices()) {
MapTag choiceData = new MapTag();
choiceData.putObject("name", new ElementTag(choice.getName()));
if (option.getType() == OptionType.STRING) {
Expand Down
Loading

0 comments on commit 2161ddb

Please sign in to comment.