Search in sources :

Example 1 with RichEmbed

use of io.discloader.discloader.core.entity.message.embed.RichEmbed in project DiscLoader by R3alCl0ud.

the class CommandHelp method execute.

@Override
public void execute(MessageCreateEvent e, String[] args) {
    IMessage message = e.getMessage();
    RichEmbed embed = new RichEmbed().setFooter(String.format("type `%shelp <page>` to tab through the pages", CommandHandler.prefix), e.loader.user.getAvatar().toString()).setAuthor(e.loader.user.getUsername(), "http://discloader.io", e.loader.user.getAvatar().toString()).setColor(0x08a2ff);
    embed.setDescription("Displaying command information");
    Command command;
    embed.setThumbnail(getResourceLocation());
    if (args.length >= 1 && (command = CommandHandler.getCommand(args[0], message)) != null) {
        if (command != null) {
            File icon = DLUtil.MissingTexture;
            embed.setThumbnail(command.getResourceLocation());
            if (embed.getThumbnail() == null)
                embed.setThumbnail(icon);
            if (args.length > 1 && command instanceof CommandTree) {
                for (int i = 1; i < args.length; i++) {
                    if (((CommandTree) command).getSubCommands().get(args[i]) != null)
                        command = ((CommandTree) command).getSubCommands().get(args[i]);
                }
            }
            embed.setTitle(getCommandName(command)).setDescription(getCommandDesc(command)).addField("Usage", command.getUsage(), true);
            if (command instanceof CommandTree) {
                String commands = "";
                for (Command sub : ((CommandTree) command).getSubCommands().values()) {
                    String desc = sub.getDescription();
                    commands = String.format("%s**%s**: %s\n", commands, sub.getUnlocalizedName(), desc);
                }
                embed.addField("Sub Commands", commands, true);
            }
            e.getChannel().sendEmbed(embed);
            return;
        }
    } else if (args.length == 1 && args[0] != null && args[0].length() > 0) {
        String commands = "";
        int page = Integer.parseInt(args[0], 10);
        int size = CommandRegistry.commands.entries().size();
        List<Command> cmdList = Lists.newArrayList(CommandRegistry.commands.entries().toArray(new Command[size]));
        cmdList.sort((a, b) -> {
            if (a.getUnlocalizedName().compareToIgnoreCase(b.getUnlocalizedName()) < 0)
                return -1;
            if (a.getUnlocalizedName().compareToIgnoreCase(b.getUnlocalizedName()) > 0)
                return 1;
            return 0;
        });
        for (int i = 0 + (10 * (page - 1)); i < (10 * page) && i < size; i++) {
            String desc = this.getCommandDesc(cmdList.get(i));
            commands = String.format("%s**%s**: %s\n", commands, cmdList.get(i).getUnlocalizedName(), desc);
        }
        embed.addField("Commands", commands, true);
        embed.setTitle(String.format("Help. Page: %d/%d", page, (size / 10) + (size % 10 != 0 ? 1 : 0)));
    } else {
        String commands = "";
        int size = CommandRegistry.commands.entries().size();
        List<Command> cmdList = Lists.newArrayList(CommandRegistry.commands.entries().toArray(new Command[size]));
        cmdList.sort((a, b) -> {
            if (a.getUnlocalizedName().compareToIgnoreCase(b.getUnlocalizedName()) < 0)
                return -1;
            if (a.getUnlocalizedName().compareToIgnoreCase(b.getUnlocalizedName()) > 0)
                return 1;
            return 0;
        });
        for (int i = 0; i < 10 && i < size; i++) {
            String desc = cmdList.get(i).getDescription();
            commands = String.format("%s**%s**: %s\n", commands, cmdList.get(i).getUnlocalizedName(), desc);
        }
        embed.addField("Commands", commands, true);
        embed.setTitle(String.format("Help. Page: 1/%d", (size / 10) + (size % 10 != 0 ? 1 : 0)));
    }
    e.getChannel().sendEmbed(embed);
}
Also used : List(java.util.List) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) Resource(io.discloader.discloader.client.render.util.Resource) CommandRegistry(io.discloader.discloader.common.registry.CommandRegistry) MessageCreateEvent(io.discloader.discloader.common.event.message.MessageCreateEvent) DLUtil(io.discloader.discloader.util.DLUtil) File(java.io.File) LanguageRegistry(io.discloader.discloader.common.language.LanguageRegistry) IMessage(io.discloader.discloader.entity.message.IMessage) IMessage(io.discloader.discloader.entity.message.IMessage) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) List(java.util.List) File(java.io.File)

Example 2 with RichEmbed

use of io.discloader.discloader.core.entity.message.embed.RichEmbed in project DiscLoader by R3alCl0ud.

the class CommandMods method execute.

@Override
public void execute(MessageCreateEvent e, String[] args) {
    IMessage message = e.getMessage();
    RichEmbed embed = new RichEmbed().setColor(0x55cdF2);
    ModContainer mc;
    try {
        if (args.length == 1 && (mc = ModRegistry.mods.get(args[0])) != null) {
            if (mc != null) {
                embed.setThumbnail(DLUtil.MissingTexture);
                embed.addField("Description", mc.modInfo.desc(), true).addField("Version", mc.modInfo.version(), true).addField("Author(s)", mc.modInfo.author(), true);
            }
        } else {
            ArrayList<String> modList = new ArrayList<String>();
            if (!ModRegistry.mods.isEmpty()) {
                for (ModContainer mcs : ModRegistry.mods.values()) {
                    modList.add(String.format("%s", mcs.modInfo.name()));
                }
            } else {
                modList.add("No Mods");
            }
            embed.setThumbnail(getResourceLocation());
            String mods = Arrays.toString(modList.toArray());
            mods = mods.substring(1, mods.length() - 1);
            embed.addField("Mods", mods);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    message.getChannel().sendEmbed(embed);
}
Also used : ModContainer(io.discloader.discloader.common.discovery.ModContainer) IMessage(io.discloader.discloader.entity.message.IMessage) ArrayList(java.util.ArrayList) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed)

Example 3 with RichEmbed

use of io.discloader.discloader.core.entity.message.embed.RichEmbed in project DiscLoader by R3alCl0ud.

the class Main method runTextChannelTest.

public static void runTextChannelTest() throws Exception {
    IGuildTextChannel channel = guild.getDefaultChannel();
    IMessage msg = channel.sendMessage("content", new RichEmbed("embed").addField().setTimestamp(), new File("README.md")).get();
    AvoidRateLimits();
    msg.edit("New Content").get();
}
Also used : IMessage(io.discloader.discloader.entity.message.IMessage) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) File(java.io.File)

Example 4 with RichEmbed

use of io.discloader.discloader.core.entity.message.embed.RichEmbed in project DiscLoader by R3alCl0ud.

the class Main method testTextChannelThings.

public static CompletableFuture<Void> testTextChannelThings(IGuild guild, IChannelCategory category) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    AvoidRateLimits();
    CompletableFuture<IGuildTextChannel> f5 = category.createTextChannel("text-channel");
    f5.exceptionally(ex -> {
        logger.severe("Test Failed");
        ex.printStackTrace();
        System.exit(5);
        return null;
    });
    f5.thenAcceptAsync(textchannel -> {
        logger.config("Text Channel Created");
        AvoidRateLimits();
        CompletableFuture<IMessage> f6 = textchannel.sendMessage("content", new RichEmbed("embed").addField().setTimestamp(), new File("README.md"));
        f6.exceptionally(ex -> {
            logger.severe("Test Failed");
            ex.printStackTrace();
            System.exit(6);
            return null;
        });
        f6.thenAcceptAsync(m1 -> {
            logger.config("Message Created");
            AvoidRateLimits();
            CompletableFuture<IMessage> f7 = m1.edit("editted content");
            f7.exceptionally(ex -> {
                logger.severe("Test Failed");
                ex.printStackTrace();
                System.exit(7);
                return null;
            });
            f7.thenAcceptAsync(m2 -> {
                logger.config("Message Edited");
                AvoidRateLimits();
                CompletableFuture<IMessage> f8 = m2.pin();
                f8.exceptionally(ex -> {
                    logger.severe("Test Failed");
                    ex.printStackTrace();
                    System.exit(8);
                    return null;
                });
                f8.thenAcceptAsync(m3 -> {
                    logger.config("Message Pinned");
                    AvoidRateLimits();
                    CompletableFuture<IMessage> f9 = m3.unpin();
                    f9.exceptionally(ex -> {
                        logger.severe("Test Failed");
                        ex.printStackTrace();
                        System.exit(9);
                        return null;
                    });
                    f9.thenAcceptAsync(m4 -> {
                        logger.config("Message Unpinned");
                        AvoidRateLimits();
                        CompletableFuture<Void> f10 = m4.addReaction("🍠");
                        f10.exceptionally(ex -> {
                            logger.severe("Test Failed");
                            ex.printStackTrace();
                            System.exit(10);
                            return null;
                        });
                        f10.thenAcceptAsync(n -> {
                            logger.config("Reaction added");
                            AvoidRateLimits();
                            CompletableFuture<IMessage> f11 = m4.deleteAllReactions();
                            f11.exceptionally(ex -> {
                                logger.severe("Test Failed");
                                ex.printStackTrace();
                                System.exit(11);
                                return null;
                            });
                            f11.thenAcceptAsync(m5 -> {
                                logger.config("Reaction removed");
                                AvoidRateLimits();
                                future.complete(null);
                            });
                        });
                    });
                });
            });
        });
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IMessage(io.discloader.discloader.entity.message.IMessage) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) File(java.io.File)

Aggregations

RichEmbed (io.discloader.discloader.core.entity.message.embed.RichEmbed)4 IMessage (io.discloader.discloader.entity.message.IMessage)4 File (java.io.File)3 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)2 Lists (com.google.common.collect.Lists)1 Resource (io.discloader.discloader.client.render.util.Resource)1 ModContainer (io.discloader.discloader.common.discovery.ModContainer)1 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)1 LanguageRegistry (io.discloader.discloader.common.language.LanguageRegistry)1 CommandRegistry (io.discloader.discloader.common.registry.CommandRegistry)1 DLUtil (io.discloader.discloader.util.DLUtil)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 CompletableFuture (java.util.concurrent.CompletableFuture)1