-
-
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
eb7a80f
commit ac204c8
Showing
14 changed files
with
666 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
83 changes: 83 additions & 0 deletions
83
src/main/java/com/beanbeanjuice/cafebot/commands/twitch/TwitchCommand.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,83 @@ | ||
package com.beanbeanjuice.cafebot.commands.twitch; | ||
|
||
import com.beanbeanjuice.cafebot.CafeBot; | ||
import com.beanbeanjuice.cafebot.commands.twitch.channel.TwitchChannelRemoveSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.twitch.channel.TwitchChannelSetSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.twitch.role.TwitchRoleRemoveSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.twitch.role.TwitchRoleSetSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.twitch.user.TwitchAddUserSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.twitch.user.TwitchListUsersSubCommand; | ||
import com.beanbeanjuice.cafebot.commands.twitch.user.TwitchRemoveUserSubCommand; | ||
import com.beanbeanjuice.cafebot.utility.commands.*; | ||
import net.dv8tion.jda.api.Permission; | ||
|
||
public class TwitchCommand extends Command implements ICommand { | ||
|
||
public TwitchCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "twitch"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Add or remove channels/notification channels."; | ||
} | ||
|
||
@Override | ||
public CommandCategory getCategory() { | ||
return CommandCategory.TWITCH; | ||
} | ||
|
||
@Override | ||
public Permission[] getPermissions() { | ||
return new Permission[] { | ||
Permission.MANAGE_CHANNEL, | ||
Permission.MANAGE_EVENTS, | ||
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 userSubCommandGroup = new SubCommandGroup("user", "Add, list, or remove twitch channels."); | ||
userSubCommandGroup.addSubCommands(new ISubCommand[] { | ||
new TwitchAddUserSubCommand(cafeBot), | ||
new TwitchRemoveUserSubCommand(cafeBot), | ||
new TwitchListUsersSubCommand(cafeBot) | ||
}); | ||
|
||
SubCommandGroup roleSubCommandGroup = new SubCommandGroup("role", "Add or remove the live notifications role."); | ||
roleSubCommandGroup.addSubCommands(new ISubCommand[] { | ||
new TwitchRoleSetSubCommand(cafeBot), | ||
new TwitchRoleRemoveSubCommand(cafeBot) | ||
}); | ||
|
||
SubCommandGroup channelSubCommandGroup = new SubCommandGroup("channel", "Add or remove the live notifications channel."); | ||
channelSubCommandGroup.addSubCommands(new ISubCommand[] { | ||
new TwitchChannelSetSubCommand(cafeBot), | ||
new TwitchChannelRemoveSubCommand(cafeBot) | ||
}); | ||
|
||
return new SubCommandGroup[] { userSubCommandGroup, roleSubCommandGroup, channelSubCommandGroup }; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...java/com/beanbeanjuice/cafebot/commands/twitch/channel/TwitchChannelRemoveSubCommand.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,45 @@ | ||
package com.beanbeanjuice.cafebot.commands.twitch.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 TwitchChannelRemoveSubCommand extends Command implements ISubCommand { | ||
|
||
public TwitchChannelRemoveSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
cafeBot.getCafeAPI().getGuildsEndpoint() | ||
.updateGuildInformation(event.getGuild().getId(), GuildInformationType.TWITCH_CHANNEL_ID, "0") | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Channel Removed", | ||
"The twitch notifications channel has been successfully removed." | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Removing Channel", | ||
String.format("There was an error removing the twitch notifications channel: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "remove"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove the twitch notifications channel."; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...in/java/com/beanbeanjuice/cafebot/commands/twitch/channel/TwitchChannelSetSubCommand.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,67 @@ | ||
package com.beanbeanjuice.cafebot.commands.twitch.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.concrete.TextChannel; | ||
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 TwitchChannelSetSubCommand extends Command implements ISubCommand { | ||
|
||
public TwitchChannelSetSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
Optional<OptionMapping> channelMapping = Optional.ofNullable(event.getOption("channel")); | ||
|
||
String channelID = channelMapping | ||
.map(OptionMapping::getAsChannel) | ||
.map(GuildChannelUnion::asTextChannel) | ||
.map(TextChannel::getId) | ||
.orElse(event.getChannel().getId()); | ||
|
||
cafeBot.getCafeAPI().getGuildsEndpoint() | ||
.updateGuildInformation(event.getGuild().getId(), GuildInformationType.TWITCH_CHANNEL_ID, channelID) | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Twitch Notifications Channel Set", | ||
String.format("The live notifications channel has been successfully set to %s!", event.getGuild().getChannelById(TextChannel.class, channelID).getAsMention()) | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Setting Twitch Notifications Channel", | ||
String.format("There was an error setting the twitch notifications channel: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Set the twitch notifications channel."; | ||
} | ||
|
||
@Override | ||
public OptionData[] getOptions() { | ||
return new OptionData[] { | ||
new OptionData(OptionType.CHANNEL, "channel", "The channel to set the twitch channel to.", false) | ||
}; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/beanbeanjuice/cafebot/commands/twitch/role/TwitchRoleRemoveSubCommand.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.twitch.role; | ||
|
||
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 TwitchRoleRemoveSubCommand extends Command implements ISubCommand { | ||
|
||
public TwitchRoleRemoveSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.LIVE_NOTIFICATIONS_ROLE_ID, "0") | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Successfully Removed Live Notifications Role", | ||
"The live notifications role has been successfully removed." | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Removing Live Notifications Role", | ||
String.format("There was an error removing the live notifications role: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "remove"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove the live notifications role."; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/beanbeanjuice/cafebot/commands/twitch/role/TwitchRoleSetSubCommand.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,56 @@ | ||
package com.beanbeanjuice.cafebot.commands.twitch.role; | ||
|
||
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.Role; | ||
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 TwitchRoleSetSubCommand extends Command implements ISubCommand { | ||
|
||
public TwitchRoleSetSubCommand(final CafeBot cafeBot) { | ||
super(cafeBot); | ||
} | ||
|
||
@Override | ||
public void handle(SlashCommandInteractionEvent event) { | ||
Role role = event.getOption("role").getAsRole(); // Should not be null. | ||
|
||
cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.LIVE_NOTIFICATIONS_ROLE_ID, role.getId()) | ||
.thenAcceptAsync((ignored) -> { | ||
event.getHook().sendMessageEmbeds(Helper.successEmbed( | ||
"Live Notifications Role Set", | ||
String.format("The live notifications role has been successfully set to %s.", role.getAsMention()) | ||
)).queue(); | ||
}) | ||
.exceptionallyAsync((e) -> { | ||
event.getHook().sendMessageEmbeds(Helper.errorEmbed( | ||
"Error Setting Live Notification Role", | ||
String.format("There was an error setting the live notification role: %s", e.getMessage()) | ||
)).queue(); | ||
return null; | ||
}); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Set the live notification role!"; | ||
} | ||
|
||
@Override | ||
public OptionData[] getOptions() { | ||
return new OptionData[] { | ||
new OptionData(OptionType.ROLE, "role", "The live notification role you want to set.", true) | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.