Skip to content

Commit

Permalink
Merge pull request #500 from beanbeanjuice/integration
Browse files Browse the repository at this point in the history
v3.1.0 Integration
  • Loading branch information
beanbeanjuice committed Jul 24, 2022
2 parents 50b5d5e + 83d1156 commit da16883
Show file tree
Hide file tree
Showing 36 changed files with 1,287 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature-request.md
Expand Up @@ -19,4 +19,4 @@ Add any other context or screenshots about the feature request here.
# Checklist:

- [ ] I have checked for similar issues.
- [ ] This is a feature request, not improvement request, bug report, or security vulnerability report.
- [ ] This is a feature request, not an improvement request, bug report, or security vulnerability report.
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -21,7 +21,7 @@
<p align="center">
A cafe bot for your discord server!
<br />
<a href="https://github.com/beanbeanjuice/cafeBot"><strong>Explore the docs »</strong></a>
<a href="https://github.com/beanbeanjuice/cafeBot"><strong>Explore the Docs »</strong></a>
<br />
<br />
<a href="https://github.com/beanbeanjuice/cafeBot">View Demo</a>
Expand Down Expand Up @@ -133,8 +133,10 @@ As you can see, this was shown using the command `/help order`. It shows each pa
* `feature-request` - Request a bot feature.
* `generate-code` - Generate a random 32-digit long code!
* `help` - Shows the list of command sections and command list for those sections.
* `ping` - Show bot information!
* `info` - Show information about the bot!
* `ping` - Show technical information about the bot!
* `remove-my-data` - Request to remove your data from the bot!
* `stats` - Show statistics such as commands run, current servers, and users!
* `support` - Get support for the bot!
* `user-info` - Get user information about someone.
##### 2. **CAFE**
Expand All @@ -145,11 +147,14 @@ As you can see, this was shown using the command `/help order`. It shows each pa
* `serve` - Get beanCoins! Essentially you run this command by doing `/serve (dictionary word)`! This must be an english word. The longer the word, the more money you get. However, the more popular the word is, the less money you will get for it.
##### 3. **FUN**
* `avatar` - Get yours or someone else's avatar image!
* `banner` - Get yours or someone else's profile banner!
* `birthday` - Add, change, or remove your birthday! Even get someone else's birthday!
* `coffee-meme` - Get a coffee meme!
* `counting-statistics` - Get counting information for your server!
* `joke` - Send a joke in the current channel. (SFW)
* `meme` - Send a meme in the current channel. (SFW)
* `rate` - Rate the percentages of someone! (*somewhat* NSFW)
* `snipe` - Snipe a recently deleted message! (30 Seconds)
* `tea-meme` - Get a tea meme!
##### 4. **GAMES**
* `8-ball` - Ask a yes or no question!
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/beanbeanjuice/Bot.java
Expand Up @@ -100,6 +100,7 @@ public Bot() throws LoginException, InterruptedException {
commandHandler,
new ServerListener(), // Listening for Guild Joins/Leaves
new MessageListener(), // Listening for specific messages
new MessageDeleteListener(), // Listening for message deletions
new WelcomeListener(), // Listening for user joins for a guild.
new AIResponseListener(), // Listening for messages.
new VoiceChatRoleBindListener(), // Listening for voice joins/leaves
Expand All @@ -120,7 +121,7 @@ public Bot() throws LoginException, InterruptedException {
VoiceChatRoleBindHandler.start();

bot.getPresence().setStatus(OnlineStatus.ONLINE);
updateGuildPresence();
Helper.startBioUpdateTimer();
logger.log(Bot.class, LogLevel.OKAY, "The bot is online!");

new GitHubUpdateHelper().start(); // Notify Guilds of Update
Expand Down Expand Up @@ -171,11 +172,4 @@ public static CommandHandler getCommandHandler() {
return commandHandler;
}

/**
* Updates the presence for the {@link JDA}.
*/
public static void updateGuildPresence() {
bot.getPresence().setActivity(Activity.playing("/help | cafeBot " + BOT_VERSION + " - Currently in " + bot.getGuilds().size() + " servers!"));
}

}
Expand Up @@ -33,7 +33,7 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
@NotNull
private MessageEmbed avatarEmbed(@NotNull User user) {
return new EmbedBuilder()
.setTitle(user.getName() + "'s Avatar", user.getAvatarUrl())
.setTitle(user.getName() + "'s Avatar")
.setImage(user.getAvatarUrl() + "?size=512")
.setColor(Helper.getRandomColor())
.build();
Expand Down
126 changes: 126 additions & 0 deletions src/main/java/com/beanbeanjuice/command/fun/BannerCommand.java
@@ -0,0 +1,126 @@
package com.beanbeanjuice.command.fun;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ICommand;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
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 org.jetbrains.annotations.NotNull;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
* An {@link ICommand} used to get the banner of a {@link net.dv8tion.jda.api.entities.User User}.
*
* @author beanbeanjuice
* @since v3.1.0
*/
public class BannerCommand implements ICommand {

private final String filename = "banner_image.jpg";

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
User user = event.getUser();
if (event.getOption("user") != null)
user = event.getOption("user").getAsUser();

String username = user.getName();
String avatarURL = user.getAvatarUrl();

user.retrieveProfile().queue(
(profile) -> {
if (profile.getBannerUrl() != null) {
event.getHook().sendMessageEmbeds(bannerEmbed(username, avatarURL, profile)).queue();
} else {
File file = new File(filename);
event.getHook().sendMessageEmbeds(bannerEmbed(username, avatarURL, profile))
.addFile(file, filename).queue((message) -> {
file.delete(); // Finally delete the file once the message is sent.
});
}
},
(failure) -> {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Getting Banner",
"There was an error getting " + username + "'s banner. " +
"Please try again later."
)).queue();
});
}

@NotNull
private MessageEmbed bannerEmbed(@NotNull String username, @NotNull String avatarURL, @NotNull User.Profile profile) {
EmbedBuilder embedBuilder = new EmbedBuilder()
.setColor(profile.getAccentColor())
.setAuthor(username + "'s Banner", null, avatarURL);

if (profile.getBannerUrl() != null) {
embedBuilder.setImage(profile.getBannerUrl() + "?size=600");
} else {
int width = 600, height = 240;

// Creating the image in code.
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = bufferedImage.createGraphics();

// Setting the colour and filling it.
graphics2D.setColor(profile.getAccentColor());
graphics2D.fillRect(0, 0, width, height);

// Clearing up resources.
graphics2D.dispose();

// Creating the file, and writing the file.
File file = new File(filename);
try {
ImageIO.write(bufferedImage, "jpg", file);
embedBuilder.setImage("attachment://" + filename);
} catch (IOException ignored) { }
}

return embedBuilder.build();
}

@NotNull
@Override
public String getDescription() {
return "Get your or another user's banner!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/banner` or `/banner @beanbeanjuice`";
}

@NotNull
@Override
public ArrayList<OptionData> getOptions() {
ArrayList<OptionData> options = new ArrayList<>();
options.add(new OptionData(OptionType.USER, "user", "The user you want to get the banner of.", false));
return options;
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.FUN;
}

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

}
52 changes: 52 additions & 0 deletions src/main/java/com/beanbeanjuice/command/fun/SnipeCommand.java
@@ -0,0 +1,52 @@
package com.beanbeanjuice.command.fun;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ICommand;
import com.beanbeanjuice.utility.handler.snipe.SnipeHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;

/**
* An {@link ICommand} to use with the {@link com.beanbeanjuice.utility.handler.snipe.SnipeHandler SnipeHandler}.
*
* @author beanbeanjuice
* @since v3.1.0
*/
public class SnipeCommand implements ICommand {

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

if (embed == null) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"No Snipe",
"There was nothing to snipe!"
)).queue();
return;
}

event.getHook().sendMessageEmbeds(embed).queue();
}

@NotNull
@Override
public String getDescription() {
return "Snipe a message in this channel!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/snipe`";
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.FUN;
}

}
58 changes: 58 additions & 0 deletions src/main/java/com/beanbeanjuice/command/fun/rate/RateCommand.java
@@ -0,0 +1,58 @@
package com.beanbeanjuice.command.fun.rate;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ICommand;
import com.beanbeanjuice.utility.command.ISubCommand;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
* An {@link ICommand} used to rate people.
*
* @author beanbeanjuice
* @since v3.1.0
*/
public class RateCommand implements ICommand {

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

@NotNull
@Override
public String getDescription() {
return "Rate someone!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/rate simp` or `/rate insane @beanbeanjuice`";
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.FUN;
}

@NotNull
@Override
public ArrayList<ISubCommand> getSubCommands() {
ArrayList<ISubCommand> subCommands = new ArrayList<>();
subCommands.add(new RateSimpSubCommand());
subCommands.add(new RateGaySubCommand());
subCommands.add(new RateSmartSubCommand());
subCommands.add(new RatePoorSubCommand());
subCommands.add(new RateInsaneSubCommand());
return subCommands;
}

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

}
@@ -0,0 +1,66 @@
package com.beanbeanjuice.command.fun.rate;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.entities.User;
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 org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
* An {@link ISubCommand} used to rate someone's gay percentage.
*
* @author beanbeanjuice
* @since v3.1.0
*/
public class RateGaySubCommand implements ISubCommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
User user = event.getUser();
if (event.getOption("user") != null)
user = event.getOption("user").getAsUser();

event.getHook().sendMessageEmbeds(Helper.smallAuthorEmbed(
"Gay Rating", null, user.getAvatarUrl(),
"The gay rating is `" + Helper.getRandomNumber(0, 101) + "`%! 🏳️‍🌈" // Gay Pride Flag
)).queue();
}

@NotNull
@Override
public String getDescription() {
return "Rate someone's gay percentage!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/rate gay` or `/rate gay @beanbeanjuice`";
}

@NotNull
@Override
public ArrayList<OptionData> getOptions() {
ArrayList<OptionData> options = new ArrayList<>();
options.add(new OptionData(OptionType.USER, "user", "THe person to rate!", false));
return options;
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.FUN;
}

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

}

0 comments on commit da16883

Please sign in to comment.