Search in sources :

Example 11 with MessageEmbed

use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.

the class ImageCmds method rule34.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!nsfwCheck(event, true, true))
                return;
            String noArgs = content.split(" ")[0];
            TextChannelGround.of(event).dropItemWithChance(13, 3);
            switch(noArgs) {
                case "get":
                    try {
                        String whole1 = content.replace("get ", "");
                        String[] wholeBeheaded = whole1.split(" ");
                        Rule34.get(60, image -> {
                            try {
                                int number;
                                try {
                                    number = Integer.parseInt(wholeBeheaded[0]);
                                } catch (Exception e) {
                                    number = r.nextInt(image.size());
                                }
                                String TAGS = image.get(number).getTags().replace(" ", " ,");
                                EmbedBuilder builder = new EmbedBuilder();
                                builder.setAuthor("Found image", null, "http:" + image.get(number - 1).getFile_url()).setImage("http:" + image.get(number - 1).getFile_url()).addField("Width", String.valueOf(image.get(number - 1).getWidth()), true).addField("Height", String.valueOf(image.get(number - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
                                event.getChannel().sendMessage(builder.build()).queue();
                            } catch (ArrayIndexOutOfBoundsException e) {
                                event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
                            }
                        });
                    } catch (Exception exception) {
                        if (exception instanceof NumberFormatException)
                            event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
                    }
                    break;
                case "tags":
                    try {
                        try {
                            boolean isOldFormat = args[1].matches("^[0-9]*$");
                            if (isOldFormat) {
                                event.getChannel().sendMessage(EmoteReference.WARNING + "Now you don't need to specify the page number. Please use ~>rule34 tags <tag>").queue();
                                return;
                            }
                            String sNoArgs = content.replace("tags ", "");
                            String[] expectedNumber = sNoArgs.split(" ");
                            String tags = expectedNumber[0];
                            Rule34.onSearch(60, tags, images -> {
                                try {
                                    try {
                                        number1 = Integer.parseInt(expectedNumber[2]);
                                    } catch (Exception e) {
                                        number1 = r.nextInt(images.size() > 0 ? images.size() - 1 : images.size());
                                    }
                                    String TAGS = images.get(number).getTags() == null ? tags : images.get(number).getTags().replace(" ", " ,");
                                    EmbedBuilder builder = new EmbedBuilder();
                                    builder.setAuthor("Found image", null, "http:" + images.get(number1 - 1).getFile_url()).setImage("http:" + images.get(number1 - 1).getFile_url()).addField("Width", String.valueOf(images.get(number1 - 1).getWidth()), true).addField("Height", String.valueOf(images.get(number1 - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
                                    event.getChannel().sendMessage(builder.build()).queue();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
                                }
                            });
                        } catch (Exception exception) {
                            if (exception instanceof NumberFormatException)
                                event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
                        }
                    } catch (NullPointerException e) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Rule34 decided to not fetch the image. Well, you can try with another number or tag.").queue();
                    }
                    break;
                default:
                    onHelp(event);
                    break;
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "rule34.xxx commmand").setColor(Color.PINK).setDescription("**Retrieves images from the rule34 (hentai) image board.**").addField("Usage", "`~>rule34 get <imagenumber>` - **Gets an image based in parameters.**\n" + "`~>rule34 tags <tag> <imagenumber>` - **Gets an image based in the specified tag and parameters.**\n", false).addField("Parameters", "`page` - **Can be any value from 1 to the rule34 maximum page. Probably around 4000.**\n" + "`imagenumber` - **(OPTIONAL) Any number from 1 to the maximum possible images to get, specified by the first instance of the command.**\n" + "`tag` - **Any valid image tag. For example animal_ears or original.**", false).build();
        }
    });
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) Arrays(java.util.Arrays) YandereImageData(net.kodehawa.mantarobot.commands.image.YandereImageData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Utils(net.kodehawa.mantarobot.utils.Utils) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) Module(net.kodehawa.mantarobot.modules.Module) Wallpaper(net.kodehawa.lib.imageboards.konachan.main.entities.Wallpaper) Random(java.util.Random) ArrayList(java.util.ArrayList) Unirest(com.mashape.unirest.http.Unirest) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) OptsCmd.registerOption(net.kodehawa.mantarobot.commands.OptsCmd.registerOption) URLCache(net.kodehawa.mantarobot.utils.cache.URLCache) JSONObject(org.json.JSONObject) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) BidiMap(org.apache.commons.collections4.BidiMap) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) DualHashBidiMap(org.apache.commons.collections4.bidimap.DualHashBidiMap) Category(net.kodehawa.mantarobot.modules.commands.base.Category) GsonDataManager(net.kodehawa.mantarobot.utils.data.GsonDataManager) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) URLEncoder(java.net.URLEncoder) List(java.util.List) CollectionUtils(br.com.brjdevs.java.utils.collections.CollectionUtils) Rule34(net.kodehawa.lib.imageboards.rule34.Rule34) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) net.kodehawa.lib.imageboards.e621.e621(net.kodehawa.lib.imageboards.e621.e621) Konachan(net.kodehawa.lib.imageboards.konachan.Konachan) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 12 with MessageEmbed

use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.

the class AssistedCommand method onHelp.

default default void onHelp(GuildMessageReceivedEvent event) {
    MessageEmbed helpEmbed = help(event);
    if (helpEmbed == null) {
        event.getChannel().sendMessage(EmoteReference.ERROR + "There's no extended help set for this command.").queue(message -> message.delete().queueAfter(20, TimeUnit.SECONDS));
        return;
    }
    event.getChannel().sendMessage(help(event)).queue();
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed)

Example 13 with MessageEmbed

use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.

the class DiscordUtils method list.

public static Future<Void> list(GuildMessageReceivedEvent event, int timeoutSeconds, boolean canEveryoneUse, IntIntObjectFunction<EmbedBuilder> supplier, String... parts) {
    if (parts.length == 0)
        return null;
    List<MessageEmbed> embeds = new ArrayList<>();
    StringBuilder sb = new StringBuilder();
    int total;
    {
        int t = 0;
        int c = 0;
        for (String s : parts) {
            if (s.length() + c + 1 > MessageEmbed.TEXT_MAX_LENGTH) {
                t++;
                c = 0;
            }
            c += s.length() + 1;
        }
        if (c > 0)
            t++;
        total = t;
    }
    for (String s : parts) {
        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) {
            EmbedBuilder eb = supplier.apply(embeds.size() + 1, total);
            eb.setDescription(sb.toString());
            embeds.add(eb.build());
            sb = new StringBuilder();
        }
        sb.append(s).append('\n');
    }
    if (sb.length() > 0) {
        EmbedBuilder eb = supplier.apply(embeds.size() + 1, total);
        eb.setDescription(sb.toString());
        embeds.add(eb.build());
    }
    AtomicInteger index = new AtomicInteger();
    Message m = event.getChannel().sendMessage(embeds.get(0)).complete();
    return ReactionOperations.create(m, timeoutSeconds, (e) -> {
        if (!canEveryoneUse && e.getUser().getIdLong() != event.getAuthor().getIdLong())
            return false;
        switch(e.getReactionEmote().getName()) {
            case //left arrow
            "⬅":
                if (index.get() == 0)
                    break;
                m.editMessage(embeds.get(index.decrementAndGet())).queue();
                break;
            case //right arrow
            "➡":
                if (index.get() + 1 >= embeds.size())
                    break;
                m.editMessage(embeds.get(index.incrementAndGet())).queue();
                break;
        }
        if (event.getGuild().getSelfMember().hasPermission(e.getTextChannel(), Permission.MESSAGE_MANAGE)) {
            e.getReaction().removeReaction(e.getUser()).queue();
        }
        return false;
    }, "⬅", "➡");
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Message(net.dv8tion.jda.core.entities.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList)

Example 14 with MessageEmbed

use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.

the class MiscCmds method randomFact.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            event.getChannel().sendMessage(EmoteReference.TALKING + facts.get().get(new Random().nextInt(facts.get().size() - 1))).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Random Fact").setDescription("**Sends a random fact.**").build();
        }
    });
    cr.registerAlias("randomfact", "rf");
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 15 with MessageEmbed

use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.

the class OwnerCmd method blacklist.

@Command
public static void blacklist(CommandRegistry cr) {
    cr.register("blacklist", new SimpleCommand(Category.OWNER, CommandPermission.OWNER) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            MantaroObj obj = MantaroData.db().getMantaroData();
            if (args[0].equals("guild")) {
                if (args[1].equals("add")) {
                    if (MantaroBot.getInstance().getGuildById(args[2]) == null)
                        return;
                    obj.getBlackListedGuilds().add(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Blacklisted Guild: " + event.getJDA().getGuildById(args[2])).queue();
                    obj.save();
                } else if (args[1].equals("remove")) {
                    if (!obj.getBlackListedGuilds().contains(args[2]))
                        return;
                    obj.getBlackListedGuilds().remove(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Unblacklisted Guild: " + args[2]).queue();
                    obj.save();
                }
                return;
            }
            if (args[0].equals("user")) {
                if (args[1].equals("add")) {
                    if (MantaroBot.getInstance().getUserById(args[2]) == null)
                        return;
                    obj.getBlackListedUsers().add(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Blacklisted User: " + event.getJDA().getUserById(args[2])).queue();
                    obj.save();
                } else if (args[1].equals("remove")) {
                    if (!obj.getBlackListedUsers().contains(args[2]))
                        return;
                    obj.getBlackListedUsers().remove(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Unblacklisted User: " + event.getJDA().getUserById(args[2])).queue();
                    obj.save();
                }
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Blacklist command").setDescription("**Blacklists a user (user argument) or a guild (guild argument) by id.**").setFooter("Examples", "~>blacklist user add/remove 293884638101897216\n" + "~>blacklist guild add/remove 305408763915927552").build();
        }
    });
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) MantaroObj(net.kodehawa.mantarobot.data.entities.MantaroObj) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Aggregations

MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)26 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)22 Command (net.kodehawa.mantarobot.modules.Command)22 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)22 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)12 MantaroData (net.kodehawa.mantarobot.data.MantaroData)8 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)8 Module (net.kodehawa.mantarobot.modules.Module)8 Category (net.kodehawa.mantarobot.modules.commands.base.Category)8 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)8 Player (net.kodehawa.mantarobot.data.entities.Player)7 Color (java.awt.Color)6 TimeUnit (java.util.concurrent.TimeUnit)5 Slf4j (lombok.extern.slf4j.Slf4j)5 Utils (net.kodehawa.mantarobot.utils.Utils)5 Collectors (java.util.stream.Collectors)4 User (net.dv8tion.jda.core.entities.User)4 RateLimiter (net.kodehawa.mantarobot.commands.currency.RateLimiter)4 TextChannelGround (net.kodehawa.mantarobot.commands.currency.TextChannelGround)4 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)4