use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class CurrencyCmds method rep.
@Command
public static void rep(CommandRegistry cr) {
cr.register("rep", new SimpleCommand(Category.CURRENCY) {
RateLimiter rateLimiter = new RateLimiter(TimeUnit.HOURS, 12);
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (event.getMessage().getMentionedUsers().isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention at least one user.").queue();
return;
}
if (event.getMessage().getMentionedUsers().get(0).isBot()) {
event.getChannel().sendMessage(EmoteReference.THINKING + "You cannot rep a bot.").queue();
return;
}
if (event.getMessage().getMentionedUsers().get(0).equals(event.getAuthor())) {
event.getChannel().sendMessage(EmoteReference.THINKING + "You cannot rep yourself.").queue();
return;
}
if (event.getMessage().getMentionedUsers().isEmpty()) {
event.getChannel().sendMessage(EmoteReference.THINKING + "You need to mention one user.").queue();
return;
}
if (!rateLimiter.process(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You can only rep once every 12 hours.\n**You'll be able to use this command again in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(event.getMember())) + ".**").queue();
return;
}
User mentioned = event.getMessage().getMentionedUsers().get(0);
Player player = MantaroData.db().getPlayer(event.getGuild().getMember(mentioned));
player.addReputation(1L);
player.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Added reputation to **" + mentioned.getName() + "**").queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Reputation command").setDescription("**Reps an user**").addField("Usage", "`~>rep <@user>` - **Gives reputation to x user**", false).addField("Parameters", "`@user` - user to mention", false).addField("Important", "Only usable every 24 hours.", false).build();
}
});
cr.registerAlias("rep", "reputation");
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class PlayerCmds method profile.
@Subscribe
public void profile(CommandRegistry cr) {
ITreeCommand profileCommand = (TreeCommand) cr.register("profile", new TreeCommand(Category.CURRENCY) {
@Override
public Command defaultTrigger(GuildMessageReceivedEvent event, String mainCommand, String commandName) {
return new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
User userLooked = event.getAuthor();
Player player = MantaroData.db().getPlayer(userLooked);
UserData user = MantaroData.db().getUser(event.getMember()).getData();
Member memberLooked = event.getMember();
List<Member> found = FinderUtil.findMembers(content, event.getGuild());
if (found.isEmpty() && !content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Didn't find any member with your search criteria :(").queue();
return;
}
if (found.size() > 1 && !content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.THINKING + "Too many members found, maybe refine your search? (ex. use name#discriminator)\n" + "**Members found:** " + found.stream().map(m -> m.getUser().getName() + "#" + m.getUser().getDiscriminator()).collect(Collectors.joining(", "))).queue();
return;
}
if (found.size() == 1 && !content.isEmpty()) {
userLooked = found.get(0).getUser();
memberLooked = found.get(0);
if (userLooked.isBot()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Bots don't have profiles.").queue();
return;
}
user = MantaroData.db().getUser(userLooked).getData();
player = MantaroData.db().getPlayer(memberLooked);
}
User marriedTo = (player.getData().getMarriedWith() == null || player.getData().getMarriedWith().isEmpty()) ? null : MantaroBot.getInstance().getUserById(player.getData().getMarriedWith());
PlayerData playerData = player.getData();
Inventory inv = player.getInventory();
// start of badge assigning
Guild mh = MantaroBot.getInstance().getGuildById("213468583252983809");
Member mhMember = mh == null ? null : mh.getMemberById(memberLooked.getUser().getId());
boolean saveAfter = false;
if (player.getMoney() > 7526527671L && playerData.addBadgeIfAbsent(Badge.ALTERNATIVE_WORLD))
saveAfter = true;
if (MantaroData.config().get().isOwner(userLooked) && playerData.addBadgeIfAbsent(Badge.DEVELOPER))
saveAfter = true;
if (inv.asList().stream().anyMatch(stack -> stack.getAmount() == 5000) && playerData.addBadgeIfAbsent(Badge.SHOPPER))
saveAfter = true;
if (inv.asList().stream().anyMatch(stack -> stack.getItem().equals(Items.CHRISTMAS_TREE_SPECIAL) || stack.getItem().equals(Items.BELL_SPECIAL)) && playerData.addBadgeIfAbsent(Badge.CHRISTMAS))
saveAfter = true;
if (MantaroBot.getInstance().getShardedMantaro().getDiscordBotsUpvoters().contains(userLooked.getIdLong()) && playerData.addBadgeIfAbsent(Badge.UPVOTER))
saveAfter = true;
if (player.getLevel() >= 10 && playerData.addBadgeIfAbsent(Badge.WALKER))
saveAfter = true;
if (player.getLevel() >= 50 && playerData.addBadgeIfAbsent(Badge.RUNNER))
saveAfter = true;
if (player.getLevel() >= 100 && playerData.addBadgeIfAbsent(Badge.FAST_RUNNER))
saveAfter = true;
if (player.getLevel() >= 150 && playerData.addBadgeIfAbsent(Badge.MARATHON_RUNNER))
saveAfter = true;
if (player.getLevel() >= 200 && playerData.addBadgeIfAbsent(Badge.MARATHON_WINNER))
saveAfter = true;
if (playerData.getMarketUsed() > 1000 && playerData.addBadgeIfAbsent(Badge.COMPULSIVE_BUYER))
saveAfter = true;
if (mhMember != null && mhMember.getRoles().stream().anyMatch(r -> r.getIdLong() == 406920476259123201L) && playerData.addBadgeIfAbsent(Badge.HELPER_2))
saveAfter = true;
if (mhMember != null && mhMember.getRoles().stream().anyMatch(r -> r.getIdLong() == 290257037072531466L || r.getIdLong() == 290902183300431872L) && playerData.addBadgeIfAbsent(Badge.DONATOR_2))
saveAfter = true;
if (saveAfter)
player.saveAsync();
// end of badge assigning
List<Badge> badges = playerData.getBadges();
Collections.sort(badges);
String displayBadges = badges.stream().map(Badge::getUnicode).limit(5).collect(Collectors.joining(" "));
applyBadge(event.getChannel(), badges.isEmpty() ? null : (playerData.getMainBadge() == null ? badges.get(0) : playerData.getMainBadge()), userLooked, baseEmbed(event, (marriedTo == null || !player.getInventory().containsItem(Items.RING) ? "" : EmoteReference.RING) + memberLooked.getEffectiveName() + "'s Profile", userLooked.getEffectiveAvatarUrl()).setThumbnail(userLooked.getEffectiveAvatarUrl()).setDescription((player.getData().isShowBadge() ? (badges.isEmpty() ? "" : String.format("**%s**\n", (playerData.getMainBadge() == null ? badges.get(0) : playerData.getMainBadge()))) : "") + (player.getData().getDescription() == null ? "No description set" : player.getData().getDescription())).addField(EmoteReference.DOLLAR + "Credits", "$ " + player.getMoney(), true).addField(EmoteReference.ZAP + "Level", player.getLevel() + " (Experience: " + player.getData().getExperience() + ")", true).addField(EmoteReference.REP + "Reputation", String.valueOf(player.getReputation()), true).addField(EmoteReference.POPPER + "Birthday", user.getBirthday() != null ? user.getBirthday().substring(0, 5) : "Not specified.", true).addField(EmoteReference.HEART + "Married with", marriedTo == null ? "Nobody." : marriedTo.getName() + "#" + marriedTo.getDiscriminator(), false).addField(EmoteReference.POUCH + "Inventory", ItemStack.toString(inv.asList()), false).addField(EmoteReference.HEART + "Top 5 Badges", displayBadges.isEmpty() ? "No badges (yet!)" : displayBadges, false).setFooter("User's timezone: " + (user.getTimezone() == null ? "No timezone set." : user.getTimezone()) + " | " + "Requested by " + event.getAuthor().getName(), null));
}
};
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Profile command.").setDescription("**Retrieves your current user profile.**").addField("Usage", "- To retrieve your profile, `~>profile`\n" + "- To change your description do `~>profile description set <description>`\n" + " -- To clear it, just do `~>profile description clear`\n" + "- To set your timezone do `~>profile timezone <timezone>`\n" + "- To set your display badge use `~>profile displaybadge` and `~>profile displaybadge reset` to reset it.\n" + " -- You can also use `~>profile displaybadge none` to display no badge on your profile.\n" + "**The profile only shows the 5 most important badges!.** Use `~>badges` to get a complete list.", false).build();
}
});
profileCommand.addSubCommand("timezone", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
DBUser dbUser = MantaroData.db().getUser(event.getAuthor());
String[] args = content.split(" ");
if (args.length < 1) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify the timezone.").queue();
return;
}
String timezone = args[0];
if (timezone.equalsIgnoreCase("reset")) {
dbUser.getData().setTimezone(null);
dbUser.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Reset timezone.").queue();
return;
}
if (!Utils.isValidTimeZone(timezone)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid timezone.").queue();
return;
}
try {
UtilsCmds.dateGMT(event.getGuild(), timezone);
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid timezone.").queue();
return;
}
dbUser.getData().setTimezone(timezone);
dbUser.saveAsync();
event.getChannel().sendMessage(String.format("%sSaved timezone, your profile timezone is now: **%s**", EmoteReference.CORRECT, timezone)).queue();
}
});
profileCommand.addSubCommand("description", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] args = content.split(" ");
User author = event.getAuthor();
Player player = MantaroData.db().getPlayer(author);
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to provide an argument! (set or remove)\n" + "for example, ~>profile description set Hi there!").queue();
return;
}
if (args[0].equals("set")) {
int MAX_LENGTH = 300;
if (MantaroData.db().getUser(author).isPremium())
MAX_LENGTH = 500;
String content1 = SPLIT_PATTERN.split(content, 2)[1];
if (content1.length() > MAX_LENGTH) {
event.getChannel().sendMessage(EmoteReference.ERROR + "The description is too long! `(Limit of 300 characters for everyone and 500 for premium users)`").queue();
return;
}
player.getData().setDescription(content1);
event.getChannel().sendMessage(EmoteReference.POPPER + "Set description to: **" + content1 + "**\n" + "Check your shiny new profile with `~>profile`").queue();
player.save();
return;
}
if (args[1].equals("clear")) {
player.getData().setDescription(null);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully cleared description.").queue();
player.save();
}
}
});
profileCommand.addSubCommand("displaybadge", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] args = content.split(" ");
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify your main badge!").queue();
return;
}
Player player = MantaroData.db().getPlayer(event.getAuthor());
PlayerData data = player.getData();
if (args[0].equalsIgnoreCase("none")) {
data.setShowBadge(false);
event.getChannel().sendMessage(EmoteReference.CORRECT + "No badge will show on the top of your profile now!").queue();
player.saveAsync();
return;
}
if (args[0].equalsIgnoreCase("reset")) {
data.setMainBadge(null);
data.setShowBadge(true);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Your display badge is now the most important one.").queue();
player.saveAsync();
return;
}
Badge badge = Badge.lookupFromString(content);
if (badge == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There's no such badge...\n" + "Your available badges: " + player.getData().getBadges().stream().map(Badge::getDisplay).collect(Collectors.joining(", "))).queue();
return;
}
if (!data.getBadges().contains(badge)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You don't have that badge.\n" + "Your available badges: " + player.getData().getBadges().stream().map(Badge::getDisplay).collect(Collectors.joining(", "))).queue();
return;
}
data.setShowBadge(true);
data.setMainBadge(badge);
player.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Your display badge is now: **" + badge.display + "**").queue();
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class UtilsCmds method weather.
@Subscribe
public void weather(CommandRegistry registry) {
registry.register("weather", new SimpleCommand(Category.UTILS) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (content.isEmpty()) {
onError(event);
return;
}
EmbedBuilder embed = new EmbedBuilder();
try {
long start = System.currentTimeMillis();
WeatherData data = GsonDataManager.GSON_PRETTY.fromJson(Utils.wgetResty(String.format("http://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s", URLEncoder.encode(content, "UTF-8"), MantaroData.config().get().weatherAppId), event), WeatherData.class);
String countryCode = data.getSys().country;
String status = data.getWeather().get(0).main;
Double temp = data.getMain().getTemp();
double pressure = data.getMain().getPressure();
int humidity = data.getMain().getHumidity();
Double ws = data.getWind().speed;
int cloudiness = data.getClouds().all;
Double finalTemperatureCelsius = temp - 273.15;
Double finalTemperatureFahrenheit = temp * 9 / 5 - 459.67;
Double finalWindSpeedMetric = ws * 3.6;
Double finalWindSpeedImperial = ws / 0.447046;
long end = System.currentTimeMillis() - start;
embed.setColor(Color.CYAN).setTitle(":flag_" + countryCode.toLowerCase() + ":" + " Forecast information for " + content, null).setDescription(status + " (" + cloudiness + "% clouds)").addField(":thermometer: Temperature", String.format("%d°C | %d°F", finalTemperatureCelsius.intValue(), finalTemperatureFahrenheit.intValue()), true).addField(":droplet: Humidity", humidity + "%", true).addBlankField(true).addField(":wind_blowing_face: Wind Speed", String.format("%dkm/h | %dmph", finalWindSpeedMetric.intValue(), finalWindSpeedImperial.intValue()), true).addField("Pressure", pressure + "hPA", true).addBlankField(true).setFooter("Information provided by OpenWeatherMap (Process time: " + end + "ms)", null);
event.getChannel().sendMessage(embed.build()).queue();
} catch (NullPointerException npe) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Error while fetching results. (Not found?)").queue();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Error while fetching results. (Not found?)").queue();
log.warn("Exception caught while trying to fetch weather data, maybe the API changed something?", e);
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Weather command").setDescription("This command retrieves information from OpenWeatherMap. Used to check **forecast information.**").addField("Usage", "`~>weather <city>,<countrycode>` - **Retrieves the forecast information for the given location.**", false).addField("Parameters", "`city` - **Your city name, e.g. New York, **\n" + "`countrycode` - **(OPTIONAL) The abbreviation for your country, for example US (USA) or MX (Mexico).**", false).addField("Example", "`~>weather New York, US`", false).build();
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class GuessTheNumber method call.
@Override
public void call(GameLobby lobby, List<String> players) {
// This class is not using Game<T>#callDefault due to it being custom/way too different from the default ones (aka give hints/etc)
InteractiveOperations.createOverriding(lobby.getChannel(), 30, new InteractiveOperation() {
@Override
public int run(GuildMessageReceivedEvent e) {
if (!e.getChannel().getId().equals(lobby.getChannel().getId())) {
return Operation.IGNORED;
}
for (String s : MantaroData.config().get().getPrefix()) {
if (e.getMessage().getContentRaw().startsWith(s)) {
return Operation.IGNORED;
}
}
if (MantaroData.db().getGuild(lobby.getChannel().getGuild()).getData().getGuildCustomPrefix() != null && e.getMessage().getContentRaw().startsWith(MantaroData.db().getGuild(lobby.getChannel().getGuild()).getData().getGuildCustomPrefix())) {
return Operation.IGNORED;
}
if (players.contains(e.getAuthor().getId())) {
if (e.getMessage().getContentRaw().equalsIgnoreCase("end")) {
lobby.getChannel().sendMessage(EmoteReference.CORRECT + "Ended game. The number was: " + number).queue();
lobby.startNextGame();
GameLobby.LOBBYS.remove(lobby.getChannel());
return Operation.COMPLETED;
}
if (e.getMessage().getContentRaw().equalsIgnoreCase("endlobby")) {
lobby.getChannel().sendMessage(EmoteReference.CORRECT + "Ended lobby correctly! Thanks for playing!").queue();
lobby.getGamesToPlay().clear();
lobby.startNextGame();
return Operation.COMPLETED;
}
int parsedAnswer;
try {
parsedAnswer = Integer.parseInt(e.getMessage().getContentRaw());
} catch (NumberFormatException ex) {
lobby.getChannel().sendMessage(EmoteReference.ERROR + "That's not even a number...").queue();
attempts = attempts + 1;
return Operation.IGNORED;
}
if (e.getMessage().getContentRaw().equals(String.valueOf(number))) {
Player player = MantaroData.db().getPlayer(e.getMember());
int gains = 95;
player.addMoney(gains);
player.getData().setGamesWon(player.getData().getGamesWon() + 1);
if (player.getData().getGamesWon() == 100)
player.getData().addBadgeIfAbsent(Badge.GAMER);
player.save();
TextChannelGround.of(e).dropItemWithChance(Items.FLOPPY_DISK, 3);
lobby.getChannel().sendMessage(EmoteReference.MEGA + "**" + e.getMember().getEffectiveName() + "**" + " Just won $" + gains + " credits by answering correctly!").queue();
lobby.startNextGame();
return Operation.COMPLETED;
}
if (attempts >= maxAttempts) {
lobby.getChannel().sendMessage(EmoteReference.ERROR + "Already used all attempts, ending game. The number was: " + number).queue();
// This should take care of removing the lobby, actually.
lobby.startNextGame();
return Operation.COMPLETED;
}
lobby.getChannel().sendMessage(EmoteReference.ERROR + "That's not it, you have " + (maxAttempts - attempts) + " attempts remaning.\n" + "Hint: The number is " + (parsedAnswer < number ? "higher" : "lower") + " than your input number.").queue();
attempts = attempts + 1;
return Operation.IGNORED;
}
return Operation.IGNORED;
}
@Override
public void onExpire() {
if (lobby.getChannel() == null)
return;
lobby.getChannel().sendMessage(EmoteReference.ERROR + "The time ran out! The number was: " + number).queue();
GameLobby.LOBBYS.remove(lobby.getChannel());
}
@Override
public void onCancel() {
GameLobby.LOBBYS.remove(lobby.getChannel());
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class ImageboardUtils method getImage.
public static void getImage(ImageBoard<?> api, ImageRequestType type, boolean nsfwOnly, String imageboard, String[] args, String content, GuildMessageReceivedEvent event) {
Rating rating = Rating.SAFE;
boolean needRating = args.length >= 3;
final TextChannel channel = event.getChannel();
final Player player = MantaroData.db().getPlayer(event.getAuthor());
final PlayerData playerData = player.getData();
if (needRating && !nsfwOnly)
rating = Rating.lookupFromString(args[2]);
if (nsfwOnly)
rating = Rating.EXPLICIT;
if (rating == null) {
channel.sendMessage(EmoteReference.ERROR + "You provided an invalid rating (Available types: questionable, explicit, safe)!").queue();
return;
}
final Rating finalRating = rating;
if (!nsfwCheck(event, nsfwOnly, false, finalRating)) {
channel.sendMessage(EmoteReference.ERROR + "Cannot send a NSFW image in a non-nsfw channel :(").queue();
return;
}
int page = Math.max(1, r.nextInt(25));
String queryRating = nsfwOnly ? null : rating.getLongName();
switch(type) {
case GET:
try {
String arguments = content.replace("get ", "");
String[] argumentsSplit = arguments.split(" ");
api.get(page, queryRating).async(requestedImages -> {
if (isListNull(requestedImages, event))
return;
try {
int number;
List<BoardImage> images = (List<BoardImage>) requestedImages;
if (!nsfwOnly)
images = requestedImages.stream().filter(data -> data.getRating().equals(finalRating)).collect(Collectors.toList());
if (images.isEmpty()) {
channel.sendMessage(EmoteReference.SAD + "There are no images matching your search criteria...").queue();
return;
}
try {
number = Integer.parseInt(argumentsSplit[0]);
} catch (Exception e) {
number = r.nextInt(images.size());
}
BoardImage image = images.get(number);
String tags = image.getTags().stream().collect(Collectors.joining(", "));
if (foundMinorTags(event, tags, image.getRating())) {
return;
}
imageEmbed(image.getURL(), String.valueOf(image.getWidth()), String.valueOf(image.getHeight()), tags, image.getRating(), imageboard, channel);
if (image.getRating().equals(Rating.EXPLICIT)) {
if (playerData.addBadgeIfAbsent(Badge.LEWDIE)) {
player.saveAsync();
}
TextChannelGround.of(event).dropItemWithChance(13, 3);
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't any more images or no results found**! Please try with a lower " + "number or another search.").queue();
}
}, failure -> event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for an image...").queue());
} catch (NumberFormatException ne) {
channel.sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help " + imageboard).queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking an image...").queue();
}
break;
case TAGS:
try {
String sNoArgs = content.replace("tags ", "");
String[] arguments = sNoArgs.split(" ");
String tags = arguments[0];
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
if (dbGuild.getData().getBlackListedImageTags().contains(tags.toLowerCase())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "This image tag has been blacklisted here by an administrator.").queue();
return;
}
api.search(tags, queryRating).async(requestedImages -> {
// account for this
if (isListNull(requestedImages, event))
return;
try {
List<BoardImage> filter = (List<BoardImage>) requestedImages;
if (!nsfwOnly)
filter = requestedImages.stream().filter(data -> data.getRating().equals(finalRating)).collect(Collectors.toList());
if (filter.isEmpty()) {
channel.sendMessage(EmoteReference.SAD + "There are no images matching your search criteria...").queue();
return;
}
int number;
try {
number = Integer.parseInt(arguments[1]);
} catch (Exception e) {
number = r.nextInt(filter.size() > 0 ? filter.size() - 1 : filter.size());
}
BoardImage image = filter.get(number);
String imageTags = image.getTags().stream().collect(Collectors.joining(", "));
if (foundMinorTags(event, imageTags, image.getRating())) {
return;
}
imageEmbed(image.getURL(), String.valueOf(image.getWidth()), String.valueOf(image.getHeight()), imageTags, image.getRating(), imageboard, channel);
if (image.getRating().equals(Rating.EXPLICIT)) {
if (playerData.addBadgeIfAbsent(Badge.LEWDIE)) {
player.saveAsync();
}
TextChannelGround.of(event).dropItemWithChance(13, 3);
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't any more images or no results found**! Please try with a lower " + "number or another search.").queue();
}
}, failure -> event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for this tag...").queue());
} catch (NumberFormatException numberEx) {
channel.sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help " + imageboard).queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
} catch (Exception exception) {
event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for this tag...").queue();
}
break;
case RANDOM:
api.get(page, queryRating).async(requestedImages -> {
try {
if (isListNull(requestedImages, event))
return;
List<BoardImage> filter = (List<BoardImage>) requestedImages;
if (!nsfwOnly)
filter = requestedImages.stream().filter(data -> data.getRating().equals(finalRating)).collect(Collectors.toList());
if (filter.isEmpty()) {
channel.sendMessage(EmoteReference.SAD + "There are no images matching your search criteria...").queue();
return;
}
int number = r.nextInt(filter.size());
BoardImage image = filter.get(number);
String tags = image.getTags().stream().collect(Collectors.joining(", "));
imageEmbed(image.getURL(), String.valueOf(image.getWidth()), String.valueOf(image.getHeight()), tags, image.getRating(), imageboard, channel);
if (image.getRating().equals(Rating.EXPLICIT)) {
if (playerData.addBadgeIfAbsent(Badge.LEWDIE)) {
player.saveAsync();
}
TextChannelGround.of(event).dropItemWithChance(13, 3);
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.SAD + "There was an unknown error while looking for a random image...").queue();
}
}, failure -> event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for a random image...").queue());
break;
}
}
Aggregations