Search in sources :

Example 6 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class OsuStatsCmd method osustats.

@Command
public static void osustats(CommandRegistry cr) {
    cr.register("osustats", new SimpleCommand(Category.GAMES) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            String noArgs = content.split(" ")[0];
            TextChannelGround.of(event).dropItemWithChance(4, 5);
            switch(noArgs) {
                case "best":
                    event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Retrieving information from osu! server...").queue(sentMessage -> {
                        Future<String> task = threadpool.submit(() -> best(content));
                        try {
                            sentMessage.editMessage(task.get(16, TimeUnit.SECONDS)).queue();
                        } catch (Exception e) {
                            if (e instanceof TimeoutException) {
                                task.cancel(true);
                                sentMessage.editMessage(EmoteReference.ERROR + "Request timeout. Maybe osu! API is slow?").queue();
                            } else
                                log.warn("Exception thrown while fetching data", e);
                        }
                    });
                    break;
                case "recent":
                    event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Retrieving information from server...").queue(sentMessage -> {
                        Future<String> task = threadpool.submit(() -> recent(content));
                        try {
                            sentMessage.editMessage(task.get(16, TimeUnit.SECONDS)).queue();
                        } catch (Exception e) {
                            if (e instanceof TimeoutException) {
                                task.cancel(true);
                                sentMessage.editMessage(EmoteReference.ERROR + "Request timeout. Maybe osu! API is slow?").queue();
                            } else
                                log.warn("Exception thrown while fetching data", e);
                        }
                    });
                    break;
                case "user":
                    event.getChannel().sendMessage(user(content)).queue();
                    break;
                default:
                    onError(event);
                    break;
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "osu! command").setDescription("**Retrieves information from the osu!API**.").addField("Usage", "`~>osustats best <player>` - **Retrieves best scores of the user specified in the specified gamemode**.\n" + "`~>osustats recent <player>` - **Retrieves recent scores of the user specified in the specified gamemode.**\n" + "`~>osustats user <player>` - **Retrieves information about a osu! player**.\n", false).addField("Parameters", "`player` - **The osu! player to look info for.**", false).build();
        }
    });
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) UserScore(com.osu.api.ciyfhx.UserScore) Mod(com.osu.api.ciyfhx.Mod) java.util.concurrent(java.util.concurrent) DecimalFormat(java.text.DecimalFormat) Module(net.kodehawa.mantarobot.modules.Module) HashMap(java.util.HashMap) Category(net.kodehawa.mantarobot.modules.commands.base.Category) User(com.osu.api.ciyfhx.User) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) JSONException(org.json.JSONException) List(java.util.List) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) Map(java.util.Map) MantaroData(net.kodehawa.mantarobot.data.MantaroData) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) OsuClient(com.osu.api.ciyfhx.OsuClient) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) OsuMod(net.kodehawa.mantarobot.commands.osu.OsuMod) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) JSONException(org.json.JSONException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 7 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class QuoteCmd method quote.

@Command
public static void quote(CommandRegistry cr) {
    cr.register("quote", new SimpleCommand(Category.MISC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (content.isEmpty()) {
                onHelp(event);
                return;
            }
            String action = args[0];
            String phrase = content.replace(action + " ", "");
            Guild guild = event.getGuild();
            ManagedDatabase db = MantaroData.db();
            EmbedBuilder builder = new EmbedBuilder();
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            List<Message> messageHistory;
            try {
                messageHistory = event.getChannel().getHistory().retrievePast(100).complete();
            } catch (Exception e) {
                if (e instanceof PermissionException) {
                    event.getChannel().sendMessage(EmoteReference.CRYING + "I don't have permission to do this :<").queue();
                    return;
                }
                event.getChannel().sendMessage(EmoteReference.ERROR + "It seems like discord is on fire, as my" + " " + "request to retrieve message history was denied" + "with the error `" + e.getClass().getSimpleName() + "`").queue();
                log.warn("Shit exploded on Discord's backend. <@155867458203287552>", e);
                return;
            }
            if (action.equals("addfrom")) {
                Message message = messageHistory.stream().filter(msg -> msg.getContent().toLowerCase().contains(phrase.toLowerCase()) && !msg.getContent().startsWith(db.getGuild(guild).getData().getGuildCustomPrefix() == null ? MantaroData.config().get().getPrefix() : db.getGuild(guild).getData().getGuildCustomPrefix()) && !msg.getContent().startsWith(MantaroData.config().get().getPrefix())).findFirst().orElse(null);
                if (message == null) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "I couldn't find a message matching the specified search" + " criteria. Please try again with a more specific query.").queue();
                    return;
                }
                TextChannel channel = guild.getTextChannelById(message.getChannel().getId());
                Quote quote = Quote.of(guild.getMember(message.getAuthor()), channel, message);
                db.getQuotes(guild).add(quote);
                event.getChannel().sendMessage(buildQuoteEmbed(dateFormat, builder, quote)).queue();
                quote.saveAsync();
                return;
            }
            if (action.equals("random")) {
                try {
                    Quote quote = CollectionUtils.random(db.getQuotes(event.getGuild()));
                    event.getChannel().sendMessage(buildQuoteEmbed(dateFormat, builder, quote)).queue();
                } catch (Exception e) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "This server has no set quotes!").queue();
                }
                return;
            }
            if (action.equals("readfrom")) {
                try {
                    List<Quote> quotes = db.getQuotes(guild);
                    for (int i2 = 0; i2 < quotes.size(); i2++) {
                        if (quotes.get(i2).getContent().contains(phrase)) {
                            Quote quote = quotes.get(i2);
                            event.getChannel().sendMessage(buildQuoteEmbed(dateFormat, builder, quote)).queue();
                            break;
                        }
                    }
                } catch (Exception e) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find any quotes! (no quotes match the criteria).").queue();
                }
                return;
            }
            if (action.equals("removefrom")) {
                try {
                    List<Quote> quotes = db.getQuotes(guild);
                    for (int i2 = 0; i2 < quotes.size(); i2++) {
                        if (quotes.get(i2).getContent().contains(phrase)) {
                            Quote quote = quotes.get(i2);
                            db.getQuotes(guild).remove(i2);
                            quote.saveAsync();
                            event.getChannel().sendMessage(EmoteReference.CORRECT + "Removed quote with content: " + quote.getContent()).queue();
                            break;
                        }
                    }
                } catch (Exception e) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "No quotes match the criteria.").queue();
                }
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Quote command").setDescription("**Quotes a message by search term.**").addField("Usage", "`~>quote addfrom <phrase>`- **Add a quote with the content defined by the specified number. For example, providing 1 will quote " + "the last message.**\n" + "`~>quote removefrom <phrase>` - **Remove a quote based on your text query.**\n" + "`~>quote readfrom <phrase>` - **Search for the first quote which matches your search criteria and prints " + "it.**\n" + "`~>quote random` - **Get a random quote.** \n", false).addField("Parameters", "`phrase` - A part of the quote phrase.", false).setColor(Color.DARK_GRAY).build();
        }
    });
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Date(java.util.Date) Module(net.kodehawa.mantarobot.modules.Module) SimpleDateFormat(java.text.SimpleDateFormat) Category(net.kodehawa.mantarobot.modules.commands.base.Category) Quote(net.kodehawa.mantarobot.data.entities.Quote) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Guild(net.dv8tion.jda.core.entities.Guild) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) List(java.util.List) CollectionUtils(br.com.brjdevs.java.utils.collections.CollectionUtils) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) ManagedDatabase(net.kodehawa.mantarobot.data.db.ManagedDatabase) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Message(net.dv8tion.jda.core.entities.Message) Guild(net.dv8tion.jda.core.entities.Guild) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) Quote(net.kodehawa.mantarobot.data.entities.Quote) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TextChannel(net.dv8tion.jda.core.entities.TextChannel) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) List(java.util.List) ManagedDatabase(net.kodehawa.mantarobot.data.db.ManagedDatabase) SimpleDateFormat(java.text.SimpleDateFormat) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 8 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class UtilsCmds method dictionary.

@Command
public static void dictionary(CommandRegistry registry) {
    registry.register("dictionary", new SimpleCommand(Category.UTILS) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (args.length == 0) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify a word.").queue();
                return;
            }
            String word = content;
            JSONObject main;
            String definition, part_of_speech, headword, example;
            try {
                main = Unirest.get("http://api.pearson.com/v2/dictionaries/laes/entries?headword=" + word).asJson().getBody().getObject();
                JSONArray results = main.getJSONArray("results");
                JSONObject result = results.getJSONObject(0);
                JSONArray senses = result.getJSONArray("senses");
                headword = result.getString("headword");
                if (result.has("part_of_speech"))
                    part_of_speech = result.getString("part_of_speech");
                else
                    part_of_speech = "Not found.";
                if (senses.getJSONObject(0).get("definition") instanceof JSONArray)
                    definition = senses.getJSONObject(0).getJSONArray("definition").getString(0);
                else
                    definition = senses.getJSONObject(0).getString("definition");
                try {
                    if (senses.getJSONObject(0).getJSONArray("translations").getJSONObject(0).get("example") instanceof JSONArray) {
                        example = senses.getJSONObject(0).getJSONArray("translations").getJSONObject(0).getJSONArray("example").getJSONObject(0).getString("text");
                    } else {
                        example = senses.getJSONObject(0).getJSONArray("translations").getJSONObject(0).getJSONObject("example").getString("text");
                    }
                } catch (Exception e) {
                    example = "Not found";
                }
            } catch (Exception e) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "No results.").queue();
                return;
            }
            EmbedBuilder eb = new EmbedBuilder();
            eb.setAuthor("Definition for " + word, null, event.getAuthor().getAvatarUrl()).setThumbnail("https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Wikt_dynamic_dictionary_logo.svg/1000px-Wikt_dynamic_dictionary_logo.svg.png").addField("Definition", "**" + definition + "**", false).addField("Example", "**" + example + "**", false).setDescription(String.format("**Part of speech:** `%s`\n" + "**Headword:** `%s`\n", part_of_speech, headword));
            event.getChannel().sendMessage(eb.build()).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Dictionary command").setDescription("**Looks up a word in the dictionary.**").addField("Usage", "`~>dictionary <word>` - Searches a word in the dictionary.", false).addField("Parameters", "`word` - The word to look for", false).build();
        }
    });
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 9 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class AudioCmdUtils method embedForQueue.

public static void embedForQueue(int page, GuildMessageReceivedEvent event, GuildMusicManager musicManager) {
    String toSend = AudioUtils.getQueueList(musicManager.getTrackScheduler().getQueue());
    Guild guild = event.getGuild();
    if (toSend.isEmpty()) {
        event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you queue some songs?").setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
        return;
    }
    String[] lines = NEWLINE_PATTERN.split(toSend);
    if (!guild.getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION)) {
        String line = null;
        StringBuilder sb = new StringBuilder();
        int total;
        {
            int t = 0;
            int c = 0;
            for (String s : lines) {
                if (s.length() + c + 1 > MessageEmbed.TEXT_MAX_LENGTH) {
                    t++;
                    c = 0;
                }
                c += s.length() + 1;
            }
            if (c > 0)
                t++;
            total = t;
        }
        int current = 0;
        for (String s : lines) {
            int l = s.length() + 1;
            if (l > MessageEmbed.TEXT_MAX_LENGTH)
                throw new IllegalArgumentException("Length for one of the pages is greater than the maximum");
            if (sb.length() + l > MessageEmbed.TEXT_MAX_LENGTH) {
                current++;
                if (current == page) {
                    line = sb.toString();
                    break;
                }
                sb = new StringBuilder();
            }
            sb.append(s).append('\n');
        }
        if (sb.length() > 0 && current + 1 == page) {
            line = sb.toString();
        }
        if (line == null || page > total) {
            event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you go back some pages?").setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
        } else {
            long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
            EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
            String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
            VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
            builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeat() == null ? "false" : musicManager.getTrackScheduler().getRepeat()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + " -> Use ~>queue <page> to change pages. Currently in page " + page, guild.getIconUrl());
            event.getChannel().sendMessage(builder.setDescription(line).build()).queue();
        }
        return;
    }
    DiscordUtils.list(event, 30, false, (p, total) -> {
        long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
        EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
        String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
        VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
        builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeat() == null ? "false" : musicManager.getTrackScheduler().getRepeat()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + " -> React to change pages. Currently in page " + p, guild.getIconUrl());
        return builder;
    }, lines);
}
Also used : Color(java.awt.Color) Region(net.dv8tion.jda.core.Region) Arrays(java.util.Arrays) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Iterator(java.util.Iterator) NEWLINE_PATTERN(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager.NEWLINE_PATTERN) Utils(net.kodehawa.mantarobot.utils.Utils) AudioManager(net.dv8tion.jda.core.managers.AudioManager) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) List(java.util.List) Matcher(java.util.regex.Matcher) Permission(net.dv8tion.jda.core.Permission) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Pattern(java.util.regex.Pattern) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Example 10 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class MoneyCmds method loot.

@Command
public static void loot(CommandRegistry cr) {
    RateLimiter rateLimiter = new RateLimiter(TimeUnit.MINUTES, 5);
    Random r = new Random();
    cr.register("loot", new SimpleCommand(Category.CURRENCY) {

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            String id = event.getAuthor().getId();
            Player player = MantaroData.db().getPlayer(event.getMember());
            if (!rateLimiter.process(id)) {
                event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Cooldown a lil bit, you can only do this once every 5 minutes.\n **You'll be able to use this command again " + "in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(event.getAuthor())) + ".**").queue();
                return;
            }
            TextChannelGround ground = TextChannelGround.of(event);
            if (r.nextInt(450) == 0) {
                //1 in 450 chance of it dropping a loot crate.
                ground.dropItem(Items.LOOT_CRATE);
            }
            List<ItemStack> loot = ground.collectItems();
            int moneyFound = ground.collectMoney() + Math.max(0, r.nextInt(50) - 10);
            if (MantaroData.db().getUser(event.getMember()).isPremium() && moneyFound > 0) {
                moneyFound = moneyFound + random.nextInt(moneyFound);
            }
            if (!loot.isEmpty()) {
                String s = ItemStack.toString(ItemStack.reduce(loot));
                String overflow;
                if (player.getInventory().merge(loot)) {
                    overflow = "But you already had too many items, so you decided to throw away the excess. ";
                } else {
                    overflow = "";
                }
                if (moneyFound != 0) {
                    if (player.addMoney(moneyFound)) {
                        event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found " + s + ", along " + "with $" + moneyFound + " credits!" + overflow).queue();
                    } else {
                        event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found " + s + ", along " + "with $" + moneyFound + " credits. " + overflow + "But you already had too many credits. Your bag overflowed" + ".\nCongratulations, you exploded a Java long. Here's a buggy money bag for you.").queue();
                    }
                } else {
                    event.getChannel().sendMessage(EmoteReference.MEGA + "Digging through messages, you found " + s + ". " + overflow).queue();
                }
            } else {
                if (moneyFound != 0) {
                    if (player.addMoney(moneyFound)) {
                        event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found **$" + moneyFound + " credits!**").queue();
                    } else {
                        event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found $" + moneyFound + " credits. But you already had too many credits. Your bag overflowed.\nCongratulations, you exploded " + "a Java long. Here's a buggy money bag for you.").queue();
                    }
                } else {
                    event.getChannel().sendMessage(EmoteReference.SAD + "Digging through messages, you found nothing but dust").queue();
                }
            }
            player.save();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Loot command").setDescription("**Loot the current chat for items, for usage in Mantaro's currency system.**\n" + "Currently, there are ``" + Items.ALL.length + "`` items available in chance," + "in which you have a `random chance` of getting one or more.").addField("Usage", "~>loot", false).build();
        }
    });
}
Also used : Player(net.kodehawa.mantarobot.data.entities.Player) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Aggregations

GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)36 Command (net.kodehawa.mantarobot.modules.Command)31 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)31 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)25 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)15 MantaroData (net.kodehawa.mantarobot.data.MantaroData)15 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)15 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)14 Module (net.kodehawa.mantarobot.modules.Module)14 Category (net.kodehawa.mantarobot.modules.commands.base.Category)14 TimeUnit (java.util.concurrent.TimeUnit)12 Color (java.awt.Color)11 Collectors (java.util.stream.Collectors)11 PostLoadEvent (net.kodehawa.mantarobot.modules.events.PostLoadEvent)11 Utils (net.kodehawa.mantarobot.utils.Utils)11 Slf4j (lombok.extern.slf4j.Slf4j)10 TextChannelGround (net.kodehawa.mantarobot.commands.currency.TextChannelGround)10 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)9 Player (net.kodehawa.mantarobot.data.entities.Player)9 java.util (java.util)8