diff --git a/build.gradle.kts b/build.gradle.kts index 1e247d42..cc637ab1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { diff --git a/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java b/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java index 66c52fac..92ef3cff 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java +++ b/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java @@ -19,6 +19,7 @@ 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; @@ -26,12 +27,12 @@ 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; @@ -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) ); diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCommand.java new file mode 100644 index 00000000..aebba0cc --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCommand.java @@ -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(); + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCreateModalListener.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCreateModalListener.java new file mode 100644 index 00000000..43f979fd --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCreateModalListener.java @@ -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; + + + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCreateSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCreateSubCommand.java new file mode 100644 index 00000000..c3902862 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/PollCreateSubCommand.java @@ -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; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/channel/PollChannelRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/channel/PollChannelRemoveSubCommand.java new file mode 100644 index 00000000..d284d603 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/channel/PollChannelRemoveSubCommand.java @@ -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."; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/channel/PollChannelSetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/channel/PollChannelSetSubCommand.java new file mode 100644 index 00000000..d98942b1 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/polls/channel/PollChannelSetSubCommand.java @@ -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 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) + }; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/RaffleCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/RaffleCommand.java new file mode 100644 index 00000000..1ae6eb9a --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/RaffleCommand.java @@ -0,0 +1,4 @@ +package com.beanbeanjuice.cafebot.commands.moderation.raffles; + +public class RaffleCommand { +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/RaffleCreateSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/RaffleCreateSubCommand.java new file mode 100644 index 00000000..3ae0922f --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/RaffleCreateSubCommand.java @@ -0,0 +1,4 @@ +package com.beanbeanjuice.cafebot.commands.moderation.raffles; + +public class RaffleCreateSubCommand { +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/channel/RaffleChannelRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/channel/RaffleChannelRemoveSubCommand.java new file mode 100644 index 00000000..b17b97a3 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/channel/RaffleChannelRemoveSubCommand.java @@ -0,0 +1,4 @@ +package com.beanbeanjuice.cafebot.commands.moderation.raffles.channel; + +public class RaffleChannelRemoveSubCommand { +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/channel/RaffleChannelSetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/channel/RaffleChannelSetSubCommand.java new file mode 100644 index 00000000..517129e2 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/raffles/channel/RaffleChannelSetSubCommand.java @@ -0,0 +1,4 @@ +package com.beanbeanjuice.cafebot.commands.moderation.raffles.channel; + +public class RaffleChannelSetSubCommand { +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/CustomChannelsCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/CustomChannelsCommand.java new file mode 100644 index 00000000..779e0d0f --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/CustomChannelsCommand.java @@ -0,0 +1,80 @@ +package com.beanbeanjuice.cafebot.commands.settings; + +import com.beanbeanjuice.cafebot.CafeBot; +import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.ICommand; +import com.beanbeanjuice.cafebot.utility.helper.Helper; +import com.beanbeanjuice.cafebot.utility.sections.settings.CustomChannels; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; + +import java.util.Arrays; +import java.util.stream.Collectors; + +public class CustomChannelsCommand extends Command implements ICommand { + + public CustomChannelsCommand(final CafeBot cafeBot) { + super(cafeBot); + } + + @Override + public void handle(SlashCommandInteractionEvent event) { + Guild guild = event.getGuild(); + + this.cafeBot.getCafeAPI().getGuildsEndpoint().getGuildInformation(guild.getId()) + .thenAcceptAsync((guildInformation) -> { + String channels = Arrays.stream(CustomChannels.values()).map((type) -> { + String channelID = guildInformation.getSetting(type.getType()); + TextChannel channel = guild.getTextChannelById(channelID); + + String channelMention = (channel == null) ? "*Unset*" : channel.getAsMention(); + + return String.format("**%s** - %s", type.name(), channelMention); + }).collect(Collectors.joining("\n")); + + event.getHook().sendMessageEmbeds(Helper.successEmbed( + "Custom Channels", + channels + )).queue(); + }); + } + + @Override + public String getName() { + return "customchannels"; + } + + @Override + public String getDescription() { + return "List all of the custom channels on this server!"; + } + + @Override + public CommandCategory getCategory() { + return CommandCategory.SETTINGS; + } + + @Override + public Permission[] getPermissions() { + return new Permission[0]; + } + + @Override + public boolean isEphemeral() { + return true; + } + + @Override + public boolean isNSFW() { + return false; + } + + @Override + public boolean allowDM() { + return false; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/AIResponseListener.java b/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/ai/AIResponseListener.java similarity index 98% rename from src/main/java/com/beanbeanjuice/cafebot/utility/listeners/AIResponseListener.java rename to src/main/java/com/beanbeanjuice/cafebot/utility/listeners/ai/AIResponseListener.java index 7b8884e8..df495c48 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/AIResponseListener.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/ai/AIResponseListener.java @@ -1,4 +1,4 @@ -package com.beanbeanjuice.cafebot.utility.listeners; +package com.beanbeanjuice.cafebot.utility.listeners.ai; import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GuildInformationType; import com.beanbeanjuice.cafebot.CafeBot; @@ -22,7 +22,6 @@ public class AIResponseListener extends ListenerAdapter { public AIResponseListener(final CafeBot cafeBot) { this.cafeBot = cafeBot; this.messageMap = new HashMap<>(); - refreshMaps(); } @@ -77,5 +76,4 @@ private String parseMessage(final String message, final User user) { return message.replace("{user}", user.getAsMention()); } - } diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/settings/CustomChannels.java b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/settings/CustomChannels.java new file mode 100644 index 00000000..13a4519e --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/settings/CustomChannels.java @@ -0,0 +1,23 @@ +package com.beanbeanjuice.cafebot.utility.sections.settings; + +import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GuildInformationType; +import lombok.Getter; + +public enum CustomChannels { + + WELCOME (GuildInformationType.WELCOME_CHANNEL_ID), + GOODBYE (GuildInformationType.GOODBYE_CHANNEL_ID), + VENTING (GuildInformationType.VENTING_CHANNEL_ID), + COUNTING (GuildInformationType.COUNTING_CHANNEL_ID), + DAILY (GuildInformationType.DAILY_CHANNEL_ID), + UPDATE (GuildInformationType.UPDATE_CHANNEL_ID), + TWITCH (GuildInformationType.TWITCH_CHANNEL_ID), + BIRTHDAY (GuildInformationType.BIRTHDAY_CHANNEL_ID); + + @Getter private final GuildInformationType type; + + CustomChannels(GuildInformationType type) { + this.type = type; + } + +}