Skip to content

Commit

Permalink
Merge pull request #532 from beanbeanjuice/integration
Browse files Browse the repository at this point in the history
v3.1.3 | Ready for Integration
  • Loading branch information
beanbeanjuice authored Oct 22, 2022
2 parents 59c5cf5 + d6a6fb1 commit f487e5f
Show file tree
Hide file tree
Showing 41 changed files with 291 additions and 175 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-alpha.13</version>
<version>5.0.0-alpha.21</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/beanbeanjuice/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class Bot {
public static int commandsRun = 0;
public static final String DISCORD_AVATAR_URL = "https://cdn.beanbeanjuice.com/images/cafeBot/cafeBot.gif";

public Bot() throws LoginException {
public Bot() throws LoginException, InterruptedException {
logger = new LogManager("cafeBot Logging System", HOME_GUILD_ID, HOME_GUILD_LOG_CHANNEL_ID, "logs/");
Helper.startCafeAPIRefreshTimer(location);

Expand All @@ -75,15 +75,16 @@ public Bot() throws LoginException {
.enableIntents(
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.DIRECT_MESSAGES
GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.MESSAGE_CONTENT
)
.enableCache(
CacheFlag.EMOJI
)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.setChunkingFilter(ChunkingFilter.ALL)
.build();
// .awaitReady(); // TODO: Remove if working.
.build()
.awaitReady();

logger.enableDiscordLogging();

Expand Down Expand Up @@ -123,7 +124,7 @@ public Bot() throws LoginException {
Helper.startUpdateTimer();
}

public static void main(String[] args) throws LoginException {
public static void main(String[] args) throws LoginException, InterruptedException {
new Bot();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
import net.dv8tion.jda.api.utils.FileUpload;
import org.jetbrains.annotations.NotNull;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -43,8 +44,9 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
event.getHook().sendMessageEmbeds(bannerEmbed(username, avatarURL, profile)).queue();
} else {
File file = new File(filename);
FileUpload fileUpload = FileUpload.fromData(file, filename);
event.getHook().sendMessageEmbeds(bannerEmbed(username, avatarURL, profile))
.addFile(file, filename).queue((message) -> {
.addFiles(fileUpload).queue((message) -> {
file.delete(); // Finally delete the file once the message is sent.
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SnipeCommand implements ICommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
MessageEmbed embed = SnipeHandler.getLatestSnipe(event.getTextChannel().getId());
MessageEmbed embed = SnipeHandler.getLatestSnipe(event.getChannel().getId());

if (embed == null) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
}

if (player2.isBot()) {
event.getChannel().sendMessageEmbeds(Helper.errorEmbed(
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Cannot Play Against Bot",
"You cannot play this game against a bot!"
)).queue();
return;
}

ConnectFourGame game = new ConnectFourGame(player1, player2, event.getTextChannel());
ConnectFourGame game = new ConnectFourGame(player1, player2, event.getChannel().asGuildMessageChannel());
if (!ConnectFourHandler.createGame(event.getGuild().getId(), game)) {
event.getChannel().sendMessageEmbeds(Helper.errorEmbed(
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Creating Connect Four Game",
"There is already an active connect four game on this server. Please wait for it to end."
)).queue();
Expand All @@ -67,6 +67,12 @@ public String exampleUsage() {
return "`/connect-4 @beanbeanjuice`";
}

@NotNull
@Override
public Boolean isHidden() {
return true;
}

@NotNull
@Override
public ArrayList<OptionData> getOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
return;
}

TicTacToeGame game = new TicTacToeGame(player1, player2, event.getTextChannel());
TicTacToeGame game = new TicTacToeGame(player1, player2, event.getChannel().asGuildMessageChannel());
if (!TicTacToeHandler.createGame(event.getGuild().getId(), game)) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Creating Tic-Tac-Toe Game",
Expand All @@ -67,6 +67,12 @@ public String exampleUsage() {
return "`/tic-tac-toe @beanbeanjuice`";
}

@NotNull
@Override
public Boolean isHidden() {
return true;
}

@NotNull
@Override
public ArrayList<OptionData> getOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
Expand Down Expand Up @@ -126,7 +126,7 @@ private void editMessage(Message message, SlashCommandInteractionEvent event, Ti

event.getHook().editOriginalEmbeds(Helper.successEmbed(
"Poll Created",
"A poll has been successfully created! Check the " + message.getTextChannel().getAsMention() + " channel."
"A poll has been successfully created! Check the " + message.getChannel().asTextChannel().getAsMention() + " channel."
)).queue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
Expand Down Expand Up @@ -107,7 +107,7 @@ private void editMessage(Message message, SlashCommandInteractionEvent event,
message.addReaction(Emoji.fromUnicode("U+2705")).queue();
event.getHook().editOriginalEmbeds(Helper.successEmbed(
"Raffle Created",
"A raffle has been successfully created! Check the " + message.getTextChannel().getAsMention() + " channel."
"A raffle has been successfully created! Check the " + message.getChannel().asTextChannel().getAsMention() + " channel."
)).queue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
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;
Expand All @@ -25,18 +25,8 @@ public class CreateEmbedCommand implements ICommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {

// Checking if the provided channel is a text channel.
TextChannel textChannel;
try {
textChannel = event.getOption("channel").getAsTextChannel();
} catch (NullPointerException e) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Not A Text Channel",
"The channel you provided is not a valid text channel."
)).queue();
return;
}
GuildMessageChannel channel = event.getOption("channel").getAsChannel().asGuildMessageChannel();

// Checking if the provided attachments are images.
if ((event.getOption("thumbnail") != null && !event.getOption("thumbnail").getAsAttachment().isImage()) ||
Expand All @@ -50,14 +40,14 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {

try {
if (event.getOption("message") != null) {
textChannel.sendMessage(event.getOption("message").getAsString()).setEmbeds(createEmbed(event)).queue();
channel.sendMessage(event.getOption("message").getAsString()).setEmbeds(createEmbed(event)).queue();
} else {
textChannel.sendMessageEmbeds(createEmbed(event)).queue();
channel.sendMessageEmbeds(createEmbed(event)).queue();
}

event.getHook().sendMessageEmbeds(Helper.successEmbed(
"Created the Custom Message Embed",
"Successfully created the custom embed in " + textChannel.getAsMention() + "!"
"Successfully created the custom embed in " + channel.getAsMention() + "!"
)).queue();
} catch (IllegalStateException e) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.handler.VoiceChatRoleBindHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.exceptions.HierarchyException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
Expand All @@ -19,7 +19,7 @@

/**
* An {@link ISubCommand} used to bind a {@link net.dv8tion.jda.api.entities.Role Role} to
* a {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}.
* a {@link VoiceChannel VoiceChannel}.
*
* @author beanbeanjuice
*/
Expand All @@ -31,7 +31,7 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
String option = event.getOption("option").getAsString();
boolean set = option.equalsIgnoreCase("set");

VoiceChannel voiceChannel = event.getOption("voice_channel").getAsVoiceChannel();
VoiceChannel voiceChannel = event.getOption("voice_channel").getAsChannel().asVoiceChannel();
String voiceChannelID = voiceChannel.getId();

Role role = event.getOption("role").getAsRole();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.handler.VoiceChatRoleBindHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
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;
Expand All @@ -16,7 +16,7 @@

/**
* An {@link ISubCommand} used to list binds between {@link net.dv8tion.jda.api.entities.Role Roles}
* and {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannels}.
* and {@link VoiceChannel VoiceChannels}.
*
* @author beanbeanjuice
*/
Expand Down Expand Up @@ -79,7 +79,7 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {

// All Binds
ArrayList<Role> roles = new ArrayList<>();
VoiceChannel voiceChannel = event.getOption("voice_channel").getAsVoiceChannel();
VoiceChannel voiceChannel = event.getOption("voice_channel").getAsChannel().asVoiceChannel();

for (String roleID : new ArrayList<>(VoiceChatRoleBindHandler.getBoundRolesForChannel(event.getGuild().getId(), voiceChannel.getId()))) {
Role role = Helper.getRole(event.getGuild(), roleID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.beanbeanjuice.utility.handler.guild.GuildHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.handler.guild.GuildHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
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;
Expand All @@ -14,7 +14,7 @@
import java.util.ArrayList;

/**
* An {@link ISubCommand} used to set the birthday {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
* An {@link ISubCommand} used to set the birthday {@link TextChannel TextChannel}.
*
* @author beanbeanjuice
* @since v3.0.1
Expand All @@ -23,9 +23,16 @@ public class SetBirthdayChannelSubCommand implements ISubCommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
TextChannel channel = event.getTextChannel();

// Checking if a text channel.
if (!Helper.isTextChannel(event.getChannel())) {
event.getHook().sendMessageEmbeds(Helper.notATextChannelEmbed(event.getChannelType())).queue();
return;
}

TextChannel channel = event.getChannel().asTextChannel();
if (event.getOption("birthday_channel") != null)
channel = event.getOption("birthday_channel").getAsTextChannel();
channel = event.getOption("birthday_channel").getAsChannel().asTextChannel();

// If the channel is already set, notify them that this cannot be done.
if (GuildHandler.getCustomGuild(event.getGuild()).isDailyChannel(channel.getId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.beanbeanjuice.cafeapi.exception.api.AuthorizationException;
import com.beanbeanjuice.cafeapi.exception.api.ConflictException;
import com.beanbeanjuice.cafeapi.exception.api.ResponseException;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
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;
Expand All @@ -18,7 +18,7 @@
import java.util.ArrayList;

/**
* An {@link ISubCommand} used to set the counting {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}
* An {@link ISubCommand} used to set the counting {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannel}
* for a specified {@link net.dv8tion.jda.api.entities.Guild Guild}.
*
* @author beanbeanjuice
Expand All @@ -27,9 +27,16 @@ public class SetCountingChannelSubCommand implements ISubCommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
TextChannel channel = event.getTextChannel();

// Checking if a text channel.
if (!Helper.isTextChannel(event.getChannel())) {
event.getHook().sendMessageEmbeds(Helper.notATextChannelEmbed(event.getChannelType())).queue();
return;
}

TextChannel channel = event.getChannel().asTextChannel();
if (event.getOption("counting_channel") != null)
channel = event.getOption("counting_channel").getAsTextChannel();
channel = event.getOption("counting_channel").getAsChannel().asTextChannel();

// If the channel is already set, notify them that this cannot be done.
if (GuildHandler.getCustomGuild(event.getGuild()).isDailyChannel(channel.getId())) {
Expand Down
Loading

0 comments on commit f487e5f

Please sign in to comment.