-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for installation and interaction contexts #86
base: master
Are you sure you want to change the base?
Changes from all commits
52caca3
ceb30f8
cc2c67e
92186b4
4446edb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,15 @@ | |
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 | ||
{ | ||
/** | ||
|
@@ -174,7 +179,31 @@ public CommandData buildCommandData() | |
else | ||
data.setDefaultPermissions(DefaultMemberPermissions.enabledFor(this.userPermissions)); | ||
|
||
data.setGuildOnly(this.guildOnly); | ||
Set<InteractionContextType> contexts = getContexts(); | ||
|
||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment. |
||
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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,17 @@ | |
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; | ||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; | ||
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.DefaultMemberPermissions; | ||
import net.dv8tion.jda.api.interactions.commands.build.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* <h2><b>Slash Commands In JDA-Chewtils</b></h2> | ||
|
@@ -298,11 +302,6 @@ else if(!selfMember.hasPermission(vc, p)) | |
return; | ||
} | ||
} | ||
else if(guildOnly) | ||
{ | ||
terminate(event, client.getError()+" This command cannot be used in direct messages", client); | ||
return; | ||
} | ||
|
||
// cooldown check, ignoring owner | ||
if(cooldown>0 && !(isOwner(event, client))) | ||
|
@@ -470,7 +469,31 @@ public CommandData buildCommandData() | |
else | ||
data.setDefaultPermissions(DefaultMemberPermissions.enabledFor(this.getUserPermissions())); | ||
|
||
data.setGuildOnly(this.guildOnly); | ||
data.setNSFW(this.nsfwOnly); | ||
|
||
Set<InteractionContextType> contexts = getContexts(); | ||
|
||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See first comment. |
||
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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,15 @@ | |
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; | ||
|
||
/** | ||
* <h2><b>User Context Menus In JDA-Chewtils</b></h2> | ||
* | ||
|
@@ -212,7 +217,40 @@ public CommandData buildCommandData() | |
else | ||
data.setDefaultPermissions(DefaultMemberPermissions.enabledFor(this.userPermissions)); | ||
|
||
data.setGuildOnly(this.guildOnly); | ||
Set<InteractionContextType> contexts = getContexts(); | ||
|
||
// manually set to true | ||
if (this.guildOnly == null) { | ||
// do nothing!!! nothing!!!! | ||
} else if (this.guildOnly) { | ||
// remove bot dm from contexts | ||
contexts.remove(InteractionContextType.BOT_DM); | ||
} else if (!this.guildOnly) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blablabla first comment. |
||
contexts.add(InteractionContextType.BOT_DM); | ||
} | ||
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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure a simple
} else {
should work here given you already check for null and if it is true. And since it's a boolean can there only be false be left by the logic.