Search in sources :

Example 11 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class ExampleCommand method execute.

@Override
public void execute(MessageCreateEvent e) {
    IMessage message = e.getMessage();
    message.getChannel().sendMessage(String.format("Hello %s\nThis is an example command", message.getAuthor().toString()));
}
Also used : IMessage(io.discloader.discloader.entity.message.IMessage)

Example 12 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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);
    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(command.getUnlocalizedName()).addField("Description", this.getCommandDesc(command), true).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) RichEmbed(io.discloader.discloader.core.entity.RichEmbed) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) 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.RichEmbed) List(java.util.List) File(java.io.File)

Example 13 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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>();
            for (ModContainer mcs : ModRegistry.mods.values()) {
                modList.add(String.format("%s", mcs.modInfo.name()));
            }
            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.RichEmbed)

Example 14 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class TextChannel method sendMessage.

@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, File file) {
    Attachment attachment = file == null ? null : new Attachment(file.getName());
    SendableMessage sendable = new SendableMessage(content, false, embed, attachment, file);
    CompletableFuture<IMessage> future = new CompletableFuture<>();
    CompletableFuture<MessageJSON> mcf = loader.rest.request(Methods.POST, Endpoints.messages(getID()), new RESTOptions(sendable), MessageJSON.class);
    mcf.thenAcceptAsync(e -> {
        future.complete(new Message<>(this, e));
    });
    mcf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) MessageJSON(io.discloader.discloader.network.json.MessageJSON) SendableMessage(io.discloader.discloader.entity.sendable.SendableMessage) IMessage(io.discloader.discloader.entity.message.IMessage) Attachment(io.discloader.discloader.entity.sendable.Attachment)

Example 15 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class Message method delete.

@Override
public CompletableFuture<IMessage> delete() {
    CompletableFuture<IMessage> future = new CompletableFuture<>();
    CompletableFuture<Void> cf = loader.rest.request(Methods.DELETE, Endpoints.message(getChannel().getID(), getID()), new RESTOptions(), Void.class);
    cf.thenAcceptAsync(Null -> {
        future.complete(this);
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IMessage(io.discloader.discloader.entity.message.IMessage)

Aggregations

IMessage (io.discloader.discloader.entity.message.IMessage)23 MessageJSON (io.discloader.discloader.network.json.MessageJSON)12 CompletableFuture (java.util.concurrent.CompletableFuture)10 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)8 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)6 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)6 File (java.io.File)5 Message (io.discloader.discloader.core.entity.message.Message)3 Attachment (io.discloader.discloader.entity.sendable.Attachment)3 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)2 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)2 RichEmbed (io.discloader.discloader.core.entity.RichEmbed)2 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)2 IPrivateChannel (io.discloader.discloader.entity.channel.IPrivateChannel)2 IReaction (io.discloader.discloader.entity.message.IReaction)2 IUser (io.discloader.discloader.entity.user.IUser)2 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)2 HashMap (java.util.HashMap)2 Lists (com.google.common.collect.Lists)1