Skip to content

Commit

Permalink
some tweaks to installations
Browse files Browse the repository at this point in the history
  • Loading branch information
Chew committed Jun 6, 2024
1 parent ceb30f8 commit cc2c67e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.DiscordLocale;
import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -154,16 +156,28 @@ public CommandData buildCommandData()

Set<InteractionContextType> contexts = getContexts();

// manually set to true
// Check for guildOnly state.
if (this.guildOnly == null) {
// do nothing!!! nothing!!!!
// don't do anything
} else if (this.guildOnly) {
// remove bot dm from contexts
contexts.remove(InteractionContextType.BOT_DM);
} else if (!this.guildOnly) {
contexts.add(InteractionContextType.BOT_DM);
}

Set<IntegrationType> types = new HashSet<>();
// Mark as a user install if it's a private channel. Only users can access private channels.
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
types.add(IntegrationType.USER_INSTALL);
}
// Mark as a guild install if it's a guild or bot dm. Default behavior.
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
types.add(IntegrationType.GUILD_INSTALL);
}

data.setIntegrationTypes(types);
data.setContexts(contexts);

//Check name localizations
if (!getNameLocalization().isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;

import java.util.HashSet;
import java.util.Set;

public abstract class MessageContextMenu extends ContextMenu
Expand Down Expand Up @@ -179,15 +181,28 @@ public CommandData buildCommandData()

Set<InteractionContextType> contexts = getContexts();

// manually set to true
// Check for guildOnly state.
if (this.guildOnly == null) {
// do nothing!!! nothing!!!!
// don't do anything
} else if (this.guildOnly) {
// remove bot dm from contexts
contexts.remove(InteractionContextType.BOT_DM);
} else if (!this.guildOnly) {
contexts.add(InteractionContextType.BOT_DM);
}

Set<IntegrationType> types = new HashSet<>();
// Mark as a user install if it's a private channel. Only users can access private channels.
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
types.add(IntegrationType.USER_INSTALL);
}
// Mark as a guild install if it's a guild or bot dm. Default behavior.
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
types.add(IntegrationType.GUILD_INSTALL);
}

data.setIntegrationTypes(types);
data.setContexts(contexts);

data.setNSFW(this.nsfwOnly);

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,20 +478,22 @@ public CommandData buildCommandData()

Set<InteractionContextType> contexts = getContexts();

// manually set to true
// Check for guildOnly state.
if (this.guildOnly == null) {
// do nothing!!! nothing!!!!
// don't do anything
} else if (this.guildOnly) {
// remove bot dm from contexts
contexts.remove(InteractionContextType.BOT_DM);
} else if (!this.guildOnly) {
contexts.add(InteractionContextType.BOT_DM);
}

Set<IntegrationType> types = new HashSet<>();
// Mark as a user install if it's a private channel. Only users can access private channels.
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
types.add(IntegrationType.USER_INSTALL);
} else if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
}
// Mark as a guild install if it's a guild or bot dm. Default behavior.
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
types.add(IntegrationType.GUILD_INSTALL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;

import java.util.HashSet;
import java.util.Set;

/**
Expand Down Expand Up @@ -228,6 +230,28 @@ public CommandData buildCommandData()
}
data.setNSFW(this.nsfwOnly);

// Check for guildOnly state.
if (this.guildOnly == null) {
// don't do anything
} else if (this.guildOnly) {
contexts.remove(InteractionContextType.BOT_DM);
} else if (!this.guildOnly) {
contexts.add(InteractionContextType.BOT_DM);
}

Set<IntegrationType> types = new HashSet<>();
// Mark as a user install if it's a private channel. Only users can access private channels.
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
types.add(IntegrationType.USER_INSTALL);
}
// Mark as a guild install if it's a guild or bot dm. Default behavior.
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
types.add(IntegrationType.GUILD_INSTALL);
}

data.setIntegrationTypes(types);
data.setContexts(contexts);

return data;
}
}

0 comments on commit cc2c67e

Please sign in to comment.