Skip to content

Commit

Permalink
Added the Welcome Command
Browse files Browse the repository at this point in the history
Additionally, the user join listener has been added. The welcome and
it's listener are now fully functional.
  • Loading branch information
beanbeanjuice committed Jul 15, 2024
1 parent e5e4502 commit 100d912
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 136 deletions.
22 changes: 15 additions & 7 deletions src/main/java/com/beanbeanjuice/cafebot/CafeBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import com.beanbeanjuice.cafebot.commands.generic.*;
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.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.commands.CommandHandler;
import com.beanbeanjuice.cafebot.utility.helper.Helper;
import com.beanbeanjuice.cafebot.utility.listeners.AIResponseListener;
import com.beanbeanjuice.cafebot.utility.listeners.BotAddListener;
import com.beanbeanjuice.cafebot.utility.listeners.BotRemoveListener;
import com.beanbeanjuice.cafebot.utility.listeners.CountingListener;
import com.beanbeanjuice.cafebot.utility.listeners.*;
import com.beanbeanjuice.cafebot.utility.logging.LogLevel;
import com.beanbeanjuice.cafebot.utility.logging.LogManager;
import com.beanbeanjuice.cafeapi.wrapper.CafeAPI;
Expand All @@ -45,6 +44,7 @@
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.restaction.CacheRestAction;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -186,7 +186,6 @@ private void setupCommands() {

// Fun
new AvatarCommand(this),
new AICommand(this),
new BannerCommand(this),
new BirthdayCommand(this),
new MemeCommand(this),
Expand Down Expand Up @@ -249,7 +248,11 @@ private void setupCommands() {
new TwitchCommand(this),

// Moderation
new ClearChatCommand(this)
new ClearChatCommand(this),

// Settings
new AICommand(this),
new WelcomeCommand(this)

// new EmbedCommand(this)
);
Expand All @@ -259,6 +262,10 @@ private void setupCommands() {
this.twitchHandler = new TwitchHandler(System.getenv("CAFEBOT_TWITCH_ACCESS_TOKEN"), this);
}

public void addEventListener(final ListenerAdapter listener) {
this.JDA.addEventListener(listener);
}

private void setupListeners() {
this.aiResponseListener = new AIResponseListener(this);
this.JDA.addEventListener(
Expand All @@ -267,7 +274,8 @@ private void setupListeners() {
new CountingListener(this),
new HelpListener(commandHandler, helpHandler),
new TicTacToeListener(cafeAPI.getWinStreaksEndpoint()),
aiResponseListener
aiResponseListener,
new WelcomeListener(this)
);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.beanbeanjuice.cafebot.commands.fun;
package com.beanbeanjuice.cafebot.commands.settings;

import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GuildInformationType;
import com.beanbeanjuice.cafebot.CafeBot;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.beanbeanjuice.cafebot.commands.settings.welcome;

import com.beanbeanjuice.cafebot.CafeBot;
import com.beanbeanjuice.cafebot.commands.settings.welcome.channel.WelcomeChannelRemoveSubCommand;
import com.beanbeanjuice.cafebot.commands.settings.welcome.channel.WelcomeChannelSetSubCommand;
import com.beanbeanjuice.cafebot.commands.settings.welcome.message.WelcomeMessageRemoveSubCommand;
import com.beanbeanjuice.cafebot.commands.settings.welcome.message.WelcomeMessageSetSubCommand;
import com.beanbeanjuice.cafebot.utility.commands.*;
import net.dv8tion.jda.api.Permission;

public class WelcomeCommand extends Command implements ICommand {

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

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

@Override
public String getDescription() {
return "Edit the welcome 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 ICommand.super.getSubCommands();
}

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

SubCommandGroup messageGroup = new SubCommandGroup("message", "Edit the welcome message.");
messageGroup.addSubCommands(new ISubCommand[] {
new WelcomeMessageSetSubCommand(cafeBot),
new WelcomeMessageRemoveSubCommand(cafeBot)
});

return new SubCommandGroup[] { channelGroup, messageGroup };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.beanbeanjuice.cafebot.commands.settings.welcome.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 WelcomeChannelRemoveSubCommand extends Command implements ISubCommand {

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

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

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

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

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

public WelcomeChannelSetSubCommand(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.WELCOME_CHANNEL_ID, channel.getId())
.thenAcceptAsync((ignored) -> {
event.getHook().sendMessageEmbeds(Helper.successEmbed(
"Welcome Channel Set",
String.format("The welcome channel has been set to %s.", channel.getAsMention())
)).queue();
})
.exceptionallyAsync((e) -> {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Setting Welcome Channel",
String.format("There was an error setting the welcome channel: %s", e.getMessage())
)).queue();
return null;
});
}

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

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

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

}
Loading

0 comments on commit 100d912

Please sign in to comment.