-
-
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.
- Loading branch information
1 parent
1695cf9
commit 2b3f5e6
Showing
8 changed files
with
345 additions
and
4 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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/beanbeanjuice/cafebot/commands/settings/update/UpdateCommand.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.update; | ||
|
||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.commands.settings.update.channel.UpdateChannelRemoveSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.settings.update.channel.UpdateChannelSetSubCommand; | ||
import com.beanbeanjuice.cafebot.utility.commands.*; | ||
import net.dv8tion.jda.api.Permission; | ||
|
||
public class UpdateCommand extends Command implements ICommand { | ||
|
||
public UpdateCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "update"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Edit the bot update 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 ISubCommand[] getSubCommands() { | ||
return new ISubCommand[] { | ||
new UpdateStatusSubCommand(cafeBot) | ||
}; | ||
} | ||
|
||
@Override | ||
public SubCommandGroup[] getSubCommandGroups() { | ||
SubCommandGroup channelGroup = new SubCommandGroup("channel", "Edit the update channel."); | ||
channelGroup.addSubCommands(new ISubCommand[]{ | ||
new UpdateChannelSetSubCommand(cafeBot), | ||
new UpdateChannelRemoveSubCommand(cafeBot) | ||
} | ||
); | ||
|
||
return new SubCommandGroup[]{ channelGroup }; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/beanbeanjuice/cafebot/commands/settings/update/UpdateStatusSubCommand.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,55 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.update; | ||
|
||
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; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
|
||
public class UpdateStatusSubCommand extends Command implements ISubCommand { | ||
|
||
public UpdateStatusSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
boolean status = event.getOption("enabled").getAsBoolean(); | ||
|
||
cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.NOTIFY_ON_UPDATE, status) | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Bot Update Notification Status Changed", | ||
"The bot update notification status has been successfully changed." | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Changing Bot Notification Status", | ||
String.format("There was an error changing the bot notification status: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "status"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Enable or disable bot update notifications."; | ||
} | ||
|
||
@Override | ||
public OptionData[] getOptions() { | ||
return new OptionData[] { | ||
new OptionData(OptionType.BOOLEAN, "enabled", "Enable or disable bot update notifications.", true) | ||
}; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...beanbeanjuice/cafebot/commands/settings/update/channel/UpdateChannelRemoveSubCommand.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.update.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 UpdateChannelRemoveSubCommand extends Command implements ISubCommand { | ||
|
||
public UpdateChannelRemoveSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.UPDATE_CHANNEL_ID, "0") | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Update Channel Removed", | ||
"The update channel has been successfully removed. Don't forget to disable update notifications too!" | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Removing Update Channel", | ||
String.format("There was an error removing the update channel: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "remove"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove the update channel."; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...om/beanbeanjuice/cafebot/commands/settings/update/channel/UpdateChannelSetSubCommand.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,61 @@ | ||
package com.beanbeanjuice.cafebot.commands.settings.update.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 UpdateChannelSetSubCommand extends Command implements ISubCommand { | ||
|
||
public UpdateChannelSetSubCommand(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.UPDATE_CHANNEL_ID, channel.getId()) | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Update Channel Set", | ||
String.format("The update channel has been successfully set to %s. Don't forget to enable bot updates!", channel.getAsMention()) | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Setting Update Channel", | ||
String.format("There was an error setting the update channel: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Set the bot update channel!"; | ||
} | ||
|
||
@Override | ||
public OptionData[] getOptions() { | ||
return new OptionData[] { | ||
new OptionData(OptionType.CHANNEL, "channel", "The channel you want to set the update channel to.", false) | ||
}; | ||
} | ||
|
||
} |
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.