-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additionally, there is now a goodbye listener.
- Loading branch information
1 parent
100d912
commit 1695cf9
Showing
11 changed files
with
427 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/com/beanbeanjuice/cafebot/commands/settings/goodbye/GoodbyeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.goodbye; | ||
|
||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.commands.settings.goodbye.channel.GoodbyeChannelRemoveSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.settings.goodbye.channel.GoodbyeChannelSetSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.settings.goodbye.message.GoodbyeMessageRemoveSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.settings.goodbye.message.GoodbyeMessageSetSubCommand; | ||
import com.beanbeanjuice.cafebot.utility.commands.*; | ||
import net.dv8tion.jda.api.Permission; | ||
|
||
public class GoodbyeCommand extends Command implements ICommand { | ||
|
||
public GoodbyeCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "goodbye"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Edit the goodbye settings!"; | ||
} | ||
|
||
@Override | ||
public CommandCategory getCategory() { | ||
return CommandCategory.SETTINGS; | ||
} | ||
|
||
@Override | ||
public Permission[] getPermissions() { | ||
return new Permission[] { | ||
Permission.MANAGE_SERVER | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isEphemeral() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isNSFW() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean allowDM() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public SubCommandGroup[] getSubCommandGroups() { | ||
SubCommandGroup channelGroup = new SubCommandGroup("channel", "Edit the goodbye channel."); | ||
channelGroup.addSubCommands(new ISubCommand[] { | ||
new GoodbyeChannelSetSubCommand(cafeBot), | ||
new GoodbyeChannelRemoveSubCommand(cafeBot) | ||
}); | ||
|
||
SubCommandGroup messageGroup = new SubCommandGroup("message", "Edit the goodbye message."); | ||
messageGroup.addSubCommands(new ISubCommand[] { | ||
new GoodbyeMessageSetSubCommand(cafeBot), | ||
new GoodbyeMessageRemoveSubCommand(cafeBot) | ||
}); | ||
|
||
return new SubCommandGroup[] { channelGroup, messageGroup }; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...anbeanjuice/cafebot/commands/settings/goodbye/channel/GoodbyeChannelRemoveSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.goodbye.channel; | ||
|
||
import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GuildInformationType; | ||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.utility.commands.Command; | ||
import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; | ||
import com.beanbeanjuice.cafebot.utility.helper.Helper; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
public class GoodbyeChannelRemoveSubCommand extends Command implements ISubCommand { | ||
|
||
public GoodbyeChannelRemoveSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.GOODBYE_CHANNEL_ID, "0") | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Goodbye Channel Removed", | ||
"The goodbye channel has been removed!" | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Removing Goodbye Channel", | ||
String.format("There was an error removing the goodbye channel: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "remove"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove the goodbye channel!"; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
.../beanbeanjuice/cafebot/commands/settings/goodbye/channel/GoodbyeChannelSetSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.goodbye.channel; | ||
|
||
import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GuildInformationType; | ||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.utility.commands.Command; | ||
import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; | ||
import com.beanbeanjuice.cafebot.utility.helper.Helper; | ||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.OptionMapping; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
|
||
import java.util.Optional; | ||
|
||
public class GoodbyeChannelSetSubCommand extends Command implements ISubCommand { | ||
|
||
public GoodbyeChannelSetSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
Optional<OptionMapping> channelMapping = Optional.ofNullable(event.getOption("channel")); | ||
GuildChannelUnion channel = channelMapping.map(OptionMapping::getAsChannel).orElse((GuildChannelUnion) event.getChannel()); | ||
|
||
cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.GOODBYE_CHANNEL_ID, channel.getId()) | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Goodbye Channel Set", | ||
String.format("The goodbye channel has been set to %s. Make sure you set the goodbye message!", channel.getAsMention()) | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Setting Goodbye Channel", | ||
String.format("There was an error setting the goodbye channel: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Set the goodbye channel!"; | ||
} | ||
|
||
@Override | ||
public OptionData[] getOptions() { | ||
return new OptionData[] { | ||
new OptionData(OptionType.CHANNEL, "channel", "The channel to set the goodbye channel to.", false) | ||
}; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
.../beanbeanjuice/cafebot/commands/settings/goodbye/message/GoodbyeMessageModalListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.goodbye.message; | ||
|
||
import com.beanbeanjuice.cafeapi.wrapper.endpoints.goodbyes.GoodbyesEndpoint; | ||
import com.beanbeanjuice.cafeapi.wrapper.endpoints.goodbyes.GuildGoodbye; | ||
import com.beanbeanjuice.cafebot.utility.helper.Helper; | ||
import com.beanbeanjuice.cafebot.utility.listeners.GoodbyeListener; | ||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
|
||
import java.util.Map; | ||
|
||
public class GoodbyeMessageModalListener extends ListenerAdapter { | ||
|
||
private final GoodbyesEndpoint goodbyesEndpoint; | ||
|
||
public GoodbyeMessageModalListener(final GoodbyesEndpoint goodbyesEndpoint) { | ||
this.goodbyesEndpoint = goodbyesEndpoint; | ||
} | ||
|
||
@Override | ||
public void onModalInteraction(ModalInteractionEvent event) { | ||
if (!event.getModalId().startsWith("cafeBot:modal:goodbye:message:")) return; | ||
|
||
Map<String, String> values = Helper.modalValuesToMap(event.getValues()); | ||
|
||
GuildGoodbye guildGoodbye = new GuildGoodbye( | ||
event.getGuild().getId(), | ||
values.get("description"), | ||
values.get("thumbnail-url"), | ||
values.get("image-url"), | ||
values.get("message") | ||
); | ||
|
||
goodbyesEndpoint.updateGuildGoodbye(guildGoodbye) | ||
.exceptionallyComposeAsync((e) -> goodbyesEndpoint.createGuildGoodbye(guildGoodbye)) | ||
.thenAcceptAsync((ignored) -> { | ||
guildGoodbye.getMessage().ifPresentOrElse( | ||
(message) -> event.reply(message.replace("{user}", event.getUser().getAsMention())).addEmbeds(GoodbyeListener.getGoodbyeEmbed(guildGoodbye, event.getUser())).setEphemeral(true).queue(), | ||
() -> event.replyEmbeds(GoodbyeListener.getGoodbyeEmbed(guildGoodbye, event.getUser())).setEphemeral(true).queue() | ||
); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.replyEmbeds(Helper.errorEmbed( | ||
"Error Setting Goodbye Message", | ||
String.format("There was an error setting the goodbye message: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
|
||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...anbeanjuice/cafebot/commands/settings/goodbye/message/GoodbyeMessageRemoveSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.goodbye.message; | ||
|
||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.utility.commands.Command; | ||
import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; | ||
import com.beanbeanjuice.cafebot.utility.helper.Helper; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
public class GoodbyeMessageRemoveSubCommand extends Command implements ISubCommand { | ||
|
||
public GoodbyeMessageRemoveSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
cafeBot.getCafeAPI().getGoodbyesEndpoint().deleteGuildGoodbye(event.getGuild().getId()) | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Goodbye Message Removed", | ||
"The goodbye message has been successfully removed." | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Removing Goodbye Message", | ||
String.format("There was an error removing the goodbye message: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "remove"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove the goodbye message!"; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
.../beanbeanjuice/cafebot/commands/settings/goodbye/message/GoodbyeMessageSetSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.goodbye.message; | ||
|
||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.utility.commands.Command; | ||
import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.components.ActionRow; | ||
import net.dv8tion.jda.api.interactions.components.text.TextInput; | ||
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; | ||
import net.dv8tion.jda.api.interactions.modals.Modal; | ||
|
||
public class GoodbyeMessageSetSubCommand extends Command implements ISubCommand { | ||
|
||
public GoodbyeMessageSetSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
|
||
cafeBot.addEventListener(new GoodbyeMessageModalListener(cafeBot.getCafeAPI().getGoodbyesEndpoint())); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
TextInput title = TextInput.create("title", "Title", TextInputStyle.SHORT) | ||
.setPlaceholder("Goodbye... {user}!") | ||
.setRequired(false) | ||
.build(); | ||
|
||
TextInput description = TextInput.create("description", "Description", TextInputStyle.PARAGRAPH) | ||
.setPlaceholder("{user} left... sad...") | ||
.setRequired(false) | ||
.build(); | ||
|
||
TextInput message = TextInput.create("message", "Message", TextInputStyle.PARAGRAPH) | ||
.setPlaceholder("@SomeRole, {user} just left...") | ||
.setRequired(false) | ||
.build(); | ||
|
||
TextInput largeImage = TextInput.create("image-url", "Large Image", TextInputStyle.SHORT) | ||
.setPlaceholder("https://some.image.url") | ||
.setRequired(false) | ||
.build(); | ||
|
||
TextInput smallImage = TextInput.create("thumbnail-url", "Small Image", TextInputStyle.SHORT) | ||
.setPlaceholder("https://some.image.url") | ||
.setRequired(false) | ||
.build(); | ||
|
||
Modal modal = Modal.create("cafeBot:modal:goodbye:message:" + this.getName(), "Edit Goodbye Message Content") | ||
.addComponents( | ||
ActionRow.of(title), | ||
ActionRow.of(description), | ||
ActionRow.of(message), | ||
ActionRow.of(largeImage), | ||
ActionRow.of(smallImage) | ||
) | ||
.build(); | ||
|
||
event.replyModal(modal).queue(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Set the goodbye message!"; | ||
} | ||
|
||
@Override | ||
public boolean isModal() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.