Skip to content

Commit

Permalink
Added the Custom Channel List Command
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Jul 16, 2024
1 parent cca3f70 commit 681cb19
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 5 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ dependencies {

testImplementation("junit", "junit", "4.13.2")
testImplementation("org.junit.jupiter", "junit-jupiter", "5.8.1")

implementation("com.github.plexpt", "chatgpt", "4.4.0")
}

tasks.withType<ShadowJar> {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/beanbeanjuice/cafebot/CafeBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
import com.beanbeanjuice.cafebot.commands.interaction.*;
import com.beanbeanjuice.cafebot.commands.moderation.ClearChatCommand;
import com.beanbeanjuice.cafebot.commands.settings.AICommand;
import com.beanbeanjuice.cafebot.commands.settings.CustomChannelsCommand;
import com.beanbeanjuice.cafebot.commands.settings.daily.DailyCommand;
import com.beanbeanjuice.cafebot.commands.settings.goodbye.GoodbyeCommand;
import com.beanbeanjuice.cafebot.commands.settings.update.UpdateCommand;
import com.beanbeanjuice.cafebot.commands.settings.welcome.WelcomeCommand;
import com.beanbeanjuice.cafebot.commands.social.MemberCountCommand;
import com.beanbeanjuice.cafebot.commands.social.vent.VentCommand;
import com.beanbeanjuice.cafebot.commands.twitch.TwitchCommand;
import com.beanbeanjuice.cafebot.utility.api.GitHubVersionEndpointWrapper;
import com.beanbeanjuice.cafebot.utility.commands.CommandHandler;
import com.beanbeanjuice.cafebot.utility.helper.DailyChannelHelper;
import com.beanbeanjuice.cafebot.utility.helper.Helper;
import com.beanbeanjuice.cafebot.utility.helper.UpdateCheckHelper;
import com.beanbeanjuice.cafebot.utility.listeners.*;
import com.beanbeanjuice.cafebot.utility.listeners.ai.AIResponseListener;
import com.beanbeanjuice.cafebot.utility.logging.LogLevel;
import com.beanbeanjuice.cafebot.utility.logging.LogManager;
import com.beanbeanjuice.cafeapi.wrapper.CafeAPI;
Expand Down Expand Up @@ -264,7 +265,8 @@ private void setupCommands() {
new WelcomeCommand(this),
new GoodbyeCommand(this),
new UpdateCommand(this),
new DailyCommand(this)
new DailyCommand(this),
new CustomChannelsCommand(this)

// new EmbedCommand(this)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.beanbeanjuice.cafebot.commands.moderation.polls;

import com.beanbeanjuice.cafebot.CafeBot;
import com.beanbeanjuice.cafebot.commands.moderation.polls.channel.PollChannelRemoveSubCommand;
import com.beanbeanjuice.cafebot.commands.moderation.polls.channel.PollChannelSetSubCommand;
import com.beanbeanjuice.cafebot.utility.commands.*;
import net.dv8tion.jda.api.Permission;

public class PollCommand extends Command implements ICommand {

public PollCommand(final CafeBot cafeBot) {
super(cafeBot);
}

@Override
public String getName() {
return "poll";
}

@Override
public String getDescription() {
return "Edit the poll channel or create a poll!";
}

@Override
public CommandCategory getCategory() {
return CommandCategory.MODERATION;
}

@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 PollCreateSubCommand(cafeBot)
};
}

@Override
public SubCommandGroup[] getSubCommandGroups() {
SubCommandGroup channelGroup = new SubCommandGroup("channel", "Edit the poll channel.");
channelGroup.addSubCommands(new ISubCommand[] {
new PollChannelSetSubCommand(cafeBot),
new PollChannelRemoveSubCommand(cafeBot)
});

return ICommand.super.getSubCommandGroups();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.beanbeanjuice.cafebot.commands.moderation.polls;

import com.beanbeanjuice.cafeapi.wrapper.endpoints.polls.PollsEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.welcomes.GuildWelcome;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.welcomes.WelcomesEndpoint;
import com.beanbeanjuice.cafebot.utility.helper.Helper;
import com.beanbeanjuice.cafebot.utility.listeners.WelcomeListener;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import java.util.Map;

public class PollCreateModalListener extends ListenerAdapter {

private final PollsEndpoint pollsEndpoint;

public PollCreateModalListener(final PollsEndpoint pollsEndpoint) {
this.pollsEndpoint = pollsEndpoint;
}

@Override
public void onModalInteraction(ModalInteractionEvent event) {
if (!event.getModalId().startsWith("cafeBot:modal:polls:create")) return;


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.beanbeanjuice.cafebot.commands.moderation.polls;

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 PollCreateSubCommand extends Command implements ISubCommand {

public PollCreateSubCommand(CafeBot cafeBot) {
super(cafeBot);
}

@Override
public void handle(SlashCommandInteractionEvent event) {
// TODO: This might not be needed anymore.
// TextInput title = TextInput.create("title", "Title", TextInputStyle.SHORT)
// .setPlaceholder("Welcome to the server, {user}!")
// .setRequired(false)
// .build();
//
// TextInput description = TextInput.create("description", "Description", TextInputStyle.PARAGRAPH)
// .setPlaceholder("Welcome {user} to the server!\nThese are our rules...")
// .setRequired(false)
// .build();
//
// TextInput message = TextInput.create("message", "Message", TextInputStyle.PARAGRAPH)
// .setPlaceholder("@SomeRole, {user} just joined!")
// .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:welcome:message:" + this.getName(), "Edit Welcome 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 "create";
}

@Override
public String getDescription() {
return "Create a poll!";
}

@Override
public boolean isModal() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.beanbeanjuice.cafebot.commands.moderation.polls.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 PollChannelRemoveSubCommand extends Command implements ISubCommand {

public PollChannelRemoveSubCommand(final CafeBot cafeBot) {
super(cafeBot);
}

@Override
public void handle(SlashCommandInteractionEvent event) {
this.cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.POLL_CHANNEL_ID, "0")
.thenAcceptAsync((ignored) -> {
event.getHook().sendMessageEmbeds(Helper.successEmbed(
"Poll Channel Removed",
"The poll channel has been successfully removed."
)).queue();
})
.exceptionallyAsync((e) -> {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Removing Poll Channel",
String.format("There was an error removing the poll channel: %s", e.getMessage())
)).queue();
return null;
});
}

@Override
public String getName() {
return "remove";
}

@Override
public String getDescription() {
return "Remove the poll channel.";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.beanbeanjuice.cafebot.commands.moderation.polls.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 PollChannelSetSubCommand extends Command implements ISubCommand {

public PollChannelSetSubCommand(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());

this.cafeBot.getCafeAPI().getGuildsEndpoint().updateGuildInformation(event.getGuild().getId(), GuildInformationType.POLL_CHANNEL_ID, channel.getId())
.thenAcceptAsync((ignored) -> {
event.getHook().sendMessageEmbeds(Helper.successEmbed(
"Poll Channel Set",
String.format("The poll channel has been set to %s. To create a poll run **/poll create**!", channel.getAsMention())
)).queue();
})
.exceptionallyAsync((e) -> {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Setting Poll Channel",
String.format("There was an error setting the poll channel: %s", e.getMessage())
)).queue();
return null;
});
}

@Override
public String getName() {
return "set";
}

@Override
public String getDescription() {
return "Set the poll channel!";
}

@Override
public OptionData[] getOptions() {
return new OptionData[] {
new OptionData(OptionType.CHANNEL, "channel", "The channel you want to set the poll channel to.", false)
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.beanbeanjuice.cafebot.commands.moderation.raffles;

public class RaffleCommand {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.beanbeanjuice.cafebot.commands.moderation.raffles;

public class RaffleCreateSubCommand {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.beanbeanjuice.cafebot.commands.moderation.raffles.channel;

public class RaffleChannelRemoveSubCommand {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.beanbeanjuice.cafebot.commands.moderation.raffles.channel;

public class RaffleChannelSetSubCommand {
}
Loading

0 comments on commit 681cb19

Please sign in to comment.