-
-
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.
Merge pull request #586 from beanbeanjuice/544-goodbye-channel
Created the Goodbye Channel
- Loading branch information
Showing
15 changed files
with
490 additions
and
13 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
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
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
107 changes: 107 additions & 0 deletions
107
src/main/java/com/beanbeanjuice/command/settings/goodbye/EditGoodbyeMessageSubCommand.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,107 @@ | ||
package com.beanbeanjuice.command.settings.goodbye; | ||
|
||
import com.beanbeanjuice.Bot; | ||
import com.beanbeanjuice.cafeapi.cafebot.goodbyes.GuildGoodbye; | ||
import com.beanbeanjuice.cafeapi.exception.api.CafeException; | ||
import com.beanbeanjuice.cafeapi.exception.api.ConflictException; | ||
import com.beanbeanjuice.utility.command.CommandCategory; | ||
import com.beanbeanjuice.utility.command.ISubCommand; | ||
import com.beanbeanjuice.utility.helper.Helper; | ||
import com.beanbeanjuice.utility.listener.GoodbyeListener; | ||
import com.beanbeanjuice.utility.logging.LogLevel; | ||
import net.dv8tion.jda.api.entities.User; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class EditGoodbyeMessageSubCommand implements ISubCommand { | ||
|
||
@Override | ||
public void handle(@NotNull SlashCommandInteractionEvent event) { | ||
User user = event.getUser(); | ||
String description = event.getOption("inner_message").getAsString(); | ||
String message = null; | ||
String imageURL = null; | ||
String thumbnailURL = null; | ||
|
||
if (event.getOption("outer_message") != null) | ||
message = event.getOption("outer_message").getAsString(); | ||
|
||
if (event.getOption("image") != null) | ||
imageURL = event.getOption("image").getAsAttachment().getUrl(); | ||
|
||
if (event.getOption("thumbnail") != null) | ||
thumbnailURL = event.getOption("thumbnail").getAsAttachment().getUrl(); | ||
|
||
GuildGoodbye guildGoodbye = new GuildGoodbye(event.getGuild().getId(), description, thumbnailURL, imageURL, message); | ||
|
||
// Sets it in the API | ||
if (setGuildGoodbye(guildGoodbye)) { | ||
if (guildGoodbye.getMessage() != null) | ||
event.getHook().sendMessage(guildGoodbye.getMessage()).addEmbeds(GoodbyeListener.getGoodbyeEmbed(guildGoodbye, user)).queue(); | ||
else | ||
event.getHook().sendMessageEmbeds(GoodbyeListener.getGoodbyeEmbed(guildGoodbye, user)).queue(); | ||
return; | ||
} | ||
|
||
event.getHook().sendMessageEmbeds(Helper.sqlServerError()).queue(); | ||
} | ||
|
||
/** | ||
* Sets the {@link GuildGoodbye} in the {@link com.beanbeanjuice.cafeapi.CafeAPI CafeAPI}. | ||
* @param guildGoodbye The {@link GuildGoodbye} to set. | ||
* @return True, if the {@link GuildGoodbye} was set successfully. | ||
*/ | ||
@NotNull | ||
public Boolean setGuildGoodbye(@NotNull GuildGoodbye guildGoodbye) { | ||
try { | ||
return Bot.getCafeAPI().GOODBYE.createGuildGoodbye(guildGoodbye); | ||
} catch (ConflictException e) { | ||
return Bot.getCafeAPI().GOODBYE.updateGuildGoodbye(guildGoodbye); | ||
} catch (CafeException e) { | ||
Bot.getLogger().log(this.getClass(), LogLevel.ERROR, "Error Setting Guild Goodbye: " + e.getMessage(), e); | ||
return false; | ||
} | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Edit the goodbye channel message!"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String exampleUsage() { | ||
return "`/goodbye-channel edit-message message:@awesomerole, someone left the server... description:Sadly, {user} left the server` or `/goodbye-channel edit-message description:Goodbye!!`"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ArrayList<OptionData> getOptions() { | ||
ArrayList<OptionData> options = new ArrayList<>(); | ||
options.add(new OptionData(OptionType.STRING, "inner_message", "The inner message to send when someone joins. " + | ||
"You can use `\\n` and use {user}.", true)); | ||
options.add(new OptionData(OptionType.STRING, "outer_message", "The outer message to send when someone joins. " + | ||
"You can use `\\n` and use {user}.", false)); | ||
options.add(new OptionData(OptionType.ATTACHMENT, "image", "The image to show when someone joins.", false)); | ||
options.add(new OptionData(OptionType.ATTACHMENT, "thumbnail", "The thumbnail image to show when someone joins.", false)); | ||
return options; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CommandCategory getCategoryType() { | ||
return CommandCategory.SETTINGS; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return "edit-message"; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/beanbeanjuice/command/settings/goodbye/GoodbyeChannelCommand.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.command.settings.goodbye; | ||
|
||
import com.beanbeanjuice.utility.command.CommandCategory; | ||
import com.beanbeanjuice.utility.command.ICommand; | ||
import com.beanbeanjuice.utility.command.ISubCommand; | ||
import net.dv8tion.jda.api.Permission; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class GoodbyeChannelCommand implements ICommand { | ||
|
||
@Override | ||
public void handle(@NotNull SlashCommandInteractionEvent event) { } | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Set/Remove the goodbye channel or edit the goodbye message!"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String exampleUsage() { | ||
return "`/goodbye-channel set` or `/goodbye-channel remove` or `/goodbye-channel edit-message`"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CommandCategory getCategoryType() { | ||
return CommandCategory.SETTINGS; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ArrayList<ISubCommand> getSubCommands() { | ||
ArrayList<ISubCommand> subCommands = new ArrayList<>(); | ||
subCommands.add(new SetGoodbyeChannelSubCommand()); | ||
subCommands.add(new RemoveGoodbyeChannelSubCommand()); | ||
subCommands.add(new EditGoodbyeMessageSubCommand()); | ||
return subCommands; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Boolean isHidden() { | ||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ArrayList<Permission> getPermissions() { | ||
ArrayList<Permission> permissions = new ArrayList<>(); | ||
permissions.add(Permission.MANAGE_SERVER); | ||
return permissions; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/beanbeanjuice/command/settings/goodbye/RemoveGoodbyeChannelSubCommand.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,48 @@ | ||
package com.beanbeanjuice.command.settings.goodbye; | ||
|
||
import com.beanbeanjuice.utility.command.CommandCategory; | ||
import com.beanbeanjuice.utility.command.ISubCommand; | ||
import com.beanbeanjuice.utility.handler.guild.GuildHandler; | ||
import com.beanbeanjuice.utility.helper.Helper; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class RemoveGoodbyeChannelSubCommand implements ISubCommand { | ||
|
||
@Override | ||
public void handle(@NotNull SlashCommandInteractionEvent event) { | ||
if (GuildHandler.getCustomGuild(event.getGuild()).setGoodbyeChannelID("0")) { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Removed Goodbye Channel", | ||
"The goodbye channel has been successfully removed!" | ||
)).queue(); | ||
return; | ||
} | ||
event.getHook().sendMessageEmbeds(Helper.sqlServerError()).queue(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Remove the current goodbye channel!"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String exampleUsage() { | ||
return "`/goodbye-channel remove`"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CommandCategory getCategoryType() { | ||
return CommandCategory.SETTINGS; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return "remove"; | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/com/beanbeanjuice/command/settings/goodbye/SetGoodbyeChannelSubCommand.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,81 @@ | ||
package com.beanbeanjuice.command.settings.goodbye; | ||
|
||
import com.beanbeanjuice.utility.command.CommandCategory; | ||
import com.beanbeanjuice.utility.command.ISubCommand; | ||
import com.beanbeanjuice.utility.handler.guild.GuildHandler; | ||
import com.beanbeanjuice.utility.helper.Helper; | ||
import net.dv8tion.jda.api.entities.channel.ChannelType; | ||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class SetGoodbyeChannelSubCommand implements ISubCommand { | ||
|
||
@Override | ||
public void handle(@NotNull SlashCommandInteractionEvent event) { | ||
|
||
// Checking if a text channel. | ||
if (!Helper.isTextChannel(event.getChannel())) { | ||
event.getHook().sendMessageEmbeds(Helper.notATextChannelEmbed(event.getChannelType())).queue(); | ||
return; | ||
} | ||
|
||
TextChannel channel = event.getChannel().asTextChannel(); | ||
if (event.getOption("goodbye_channel") != null) | ||
channel = event.getOption("goodbye_channel").getAsChannel().asTextChannel(); | ||
|
||
// If the channel is already set, notify them that this cannot be done. | ||
if (GuildHandler.getCustomGuild(event.getGuild()).isDailyChannel(channel.getId())) { | ||
event.getHook().sendMessageEmbeds(Helper.alreadyDailyChannel()).queue(); | ||
return; | ||
} | ||
|
||
if (GuildHandler.getCustomGuild(event.getGuild()).setGoodbyeChannelID(channel.getId())) { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Set Goodbye Channel", | ||
"This channel has been set to the goodbye channel! Make sure to " + | ||
"edit the goodbye message with the `/goodbye-channel edit-message` command!" | ||
)).queue(); | ||
return; | ||
} | ||
event.getHook().sendMessageEmbeds(Helper.sqlServerError()).queue(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ArrayList<OptionData> getOptions() { | ||
ArrayList<OptionData> options = new ArrayList<>(); | ||
options.add(new OptionData(OptionType.CHANNEL, "goodbye_channel", "The text channel to send goodbye information to.", false) | ||
.setChannelTypes(ChannelType.TEXT)); | ||
return options; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Set a channel to goodbye channel!"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String exampleUsage() { | ||
return "`/goodbye-channel set`"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CommandCategory getCategoryType() { | ||
return CommandCategory.SETTINGS; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
} |
Oops, something went wrong.