Skip to content

Commit cc2c67e

Browse files
committed
some tweaks to installations
1 parent ceb30f8 commit cc2c67e

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

command/src/main/java/com/jagrosh/jdautilities/command/ContextMenu.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import net.dv8tion.jda.api.JDA;
1919
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
2020
import net.dv8tion.jda.api.interactions.DiscordLocale;
21+
import net.dv8tion.jda.api.interactions.IntegrationType;
2122
import net.dv8tion.jda.api.interactions.InteractionContextType;
2223
import net.dv8tion.jda.api.interactions.commands.Command;
2324
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
2425
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
2526
import net.dv8tion.jda.api.interactions.commands.build.Commands;
2627

2728
import java.util.HashMap;
29+
import java.util.HashSet;
2830
import java.util.Map;
2931
import java.util.Set;
3032

@@ -154,16 +156,28 @@ public CommandData buildCommandData()
154156

155157
Set<InteractionContextType> contexts = getContexts();
156158

157-
// manually set to true
159+
// Check for guildOnly state.
158160
if (this.guildOnly == null) {
159-
// do nothing!!! nothing!!!!
161+
// don't do anything
160162
} else if (this.guildOnly) {
161-
// remove bot dm from contexts
162163
contexts.remove(InteractionContextType.BOT_DM);
163164
} else if (!this.guildOnly) {
164165
contexts.add(InteractionContextType.BOT_DM);
165166
}
166167

168+
Set<IntegrationType> types = new HashSet<>();
169+
// Mark as a user install if it's a private channel. Only users can access private channels.
170+
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
171+
types.add(IntegrationType.USER_INSTALL);
172+
}
173+
// Mark as a guild install if it's a guild or bot dm. Default behavior.
174+
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
175+
types.add(IntegrationType.GUILD_INSTALL);
176+
}
177+
178+
data.setIntegrationTypes(types);
179+
data.setContexts(contexts);
180+
167181
//Check name localizations
168182
if (!getNameLocalization().isEmpty())
169183
{

command/src/main/java/com/jagrosh/jdautilities/command/MessageContextMenu.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import net.dv8tion.jda.api.entities.GuildVoiceState;
2020
import net.dv8tion.jda.api.entities.Member;
2121
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
22+
import net.dv8tion.jda.api.interactions.IntegrationType;
2223
import net.dv8tion.jda.api.interactions.InteractionContextType;
2324
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
2425
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
2526
import net.dv8tion.jda.api.interactions.commands.build.Commands;
2627

28+
import java.util.HashSet;
2729
import java.util.Set;
2830

2931
public abstract class MessageContextMenu extends ContextMenu
@@ -179,15 +181,28 @@ public CommandData buildCommandData()
179181

180182
Set<InteractionContextType> contexts = getContexts();
181183

182-
// manually set to true
184+
// Check for guildOnly state.
183185
if (this.guildOnly == null) {
184-
// do nothing!!! nothing!!!!
186+
// don't do anything
185187
} else if (this.guildOnly) {
186-
// remove bot dm from contexts
187188
contexts.remove(InteractionContextType.BOT_DM);
188189
} else if (!this.guildOnly) {
189190
contexts.add(InteractionContextType.BOT_DM);
190191
}
192+
193+
Set<IntegrationType> types = new HashSet<>();
194+
// Mark as a user install if it's a private channel. Only users can access private channels.
195+
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
196+
types.add(IntegrationType.USER_INSTALL);
197+
}
198+
// Mark as a guild install if it's a guild or bot dm. Default behavior.
199+
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
200+
types.add(IntegrationType.GUILD_INSTALL);
201+
}
202+
203+
data.setIntegrationTypes(types);
204+
data.setContexts(contexts);
205+
191206
data.setNSFW(this.nsfwOnly);
192207

193208
return data;

command/src/main/java/com/jagrosh/jdautilities/command/SlashCommand.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,22 @@ public CommandData buildCommandData()
478478

479479
Set<InteractionContextType> contexts = getContexts();
480480

481-
// manually set to true
481+
// Check for guildOnly state.
482482
if (this.guildOnly == null) {
483-
// do nothing!!! nothing!!!!
483+
// don't do anything
484484
} else if (this.guildOnly) {
485-
// remove bot dm from contexts
486485
contexts.remove(InteractionContextType.BOT_DM);
487486
} else if (!this.guildOnly) {
488487
contexts.add(InteractionContextType.BOT_DM);
489488
}
490489

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

command/src/main/java/com/jagrosh/jdautilities/command/UserContextMenu.java

+24
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import net.dv8tion.jda.api.entities.GuildVoiceState;
2020
import net.dv8tion.jda.api.entities.Member;
2121
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
22+
import net.dv8tion.jda.api.interactions.IntegrationType;
2223
import net.dv8tion.jda.api.interactions.InteractionContextType;
2324
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
2425
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
2526
import net.dv8tion.jda.api.interactions.commands.build.Commands;
2627

28+
import java.util.HashSet;
2729
import java.util.Set;
2830

2931
/**
@@ -228,6 +230,28 @@ public CommandData buildCommandData()
228230
}
229231
data.setNSFW(this.nsfwOnly);
230232

233+
// Check for guildOnly state.
234+
if (this.guildOnly == null) {
235+
// don't do anything
236+
} else if (this.guildOnly) {
237+
contexts.remove(InteractionContextType.BOT_DM);
238+
} else if (!this.guildOnly) {
239+
contexts.add(InteractionContextType.BOT_DM);
240+
}
241+
242+
Set<IntegrationType> types = new HashSet<>();
243+
// Mark as a user install if it's a private channel. Only users can access private channels.
244+
if (contexts.contains(InteractionContextType.PRIVATE_CHANNEL)) {
245+
types.add(IntegrationType.USER_INSTALL);
246+
}
247+
// Mark as a guild install if it's a guild or bot dm. Default behavior.
248+
if (contexts.contains(InteractionContextType.BOT_DM) || contexts.contains(InteractionContextType.GUILD)) {
249+
types.add(IntegrationType.GUILD_INSTALL);
250+
}
251+
252+
data.setIntegrationTypes(types);
253+
data.setContexts(contexts);
254+
231255
return data;
232256
}
233257
}

0 commit comments

Comments
 (0)