package com.avairebot.orion.contracts.commands;

import com.avairebot.orion.Orion;
import com.avairebot.orion.chat.PlaceholderMessage;
import com.avairebot.orion.commands.CommandPriority;
import com.avairebot.orion.factories.MessageFactory;
import com.avairebot.orion.utilities.RandomUtil;
import net.dv8tion.jda.core.entities.Message;

import java.awt.*;
import java.util.Collections;
import java.util.List;

public abstract class InteractionCommand extends Command {

    private final String interaction;
    private final boolean overwrite;

    public InteractionCommand(Orion orion, String interaction, boolean overwrite) {
        super(orion, false);

        this.overwrite = overwrite;
        this.interaction = interaction;
    }

    public InteractionCommand(Orion orion, String interaction) {
        this(orion, interaction, false);
    }

    @Override
    public String getDescription() {
        return String.format("Sends the **%s** interaction to the mentioned user.", interaction);
    }

    @Override
    public List<String> getUsageInstructions() {
        return Collections.singletonList("`:command <user>`");
    }

    @Override
    public String getExampleUsage() {
        return "`:command @Orion`";
    }

    @Override
    public List<String> getMiddleware() {
        return Collections.singletonList("throttle:user,1,5");
    }

    @Override
    public CommandPriority getCommandPriority() {
        return CommandPriority.HIGH;
    }

    public Color getInteractionColor() {
        return null;
    }

    public abstract List<String> getInteractionImages();

    @Override
    public boolean onCommand(Message message, String[] args) {
        if (message.getMentionedUsers().isEmpty()) {
            return sendErrorMessage(message, "You must mention a use you want to use the interaction for.");
        }

        PlaceholderMessage placeholderMessage = MessageFactory.makeEmbeddedMessage(
            message.getChannel(), null, buildMessage(message)
        ).setImage(getInteractionImages().get(
            RandomUtil.getInteger(getInteractionImages().size())
        ));

        if (getInteractionColor() != null) {
            placeholderMessage.setColor(getInteractionColor());
        }

        placeholderMessage.queue();
        return true;
    }

    private String buildMessage(Message message) {
        if (overwrite) {
            return String.format(interaction,
                message.getMember().getEffectiveName(),
                message.getGuild().getMember(message.getMentionedUsers().get(0)).getEffectiveName()
            );
        }

        return String.format("**%s** %s **%s**",
            message.getMember().getEffectiveName(),
            interaction,
            message.getGuild().getMember(message.getMentionedUsers().get(0)).getEffectiveName()
        );
    }
}

@@ -108,251 +108,309 @@
 on.c
-hat.PlaceholderMessage;%0Aimport com.avairebot.orion.commands.CommandPriority;%0Aimport com.avairebot.orion.factories.MessageFactory;%0Aimport com.avairebot.orion.utilities.RandomUtil;%0Aimport net.dv8tion.jda.core.entities.Message;%0A%0Aimport java.awt.*
+ommands.CommandPriority;%0Aimport com.avairebot.orion.utilities.RandomUtil;%0Aimport net.dv8tion.jda.core.EmbedBuilder;%0Aimport net.dv8tion.jda.core.MessageBuilder;%0Aimport net.dv8tion.jda.core.entities.Message;%0A%0Aimport java.awt.*;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.net.URL
 ;%0Aim
@@ -1914,124 +1914,396 @@
     
-PlaceholderMessage placeho
+message.getChannel().sendTyping().queue();%0A%0A        int imageIndex = RandomUtil.getInteger(getInteractionImages().size());%0A%0A        MessageBui
 lder
-M
+ m
 essage
- = MessageFactory.makeEmbeddedMessage(%0A            message.getChannel(), null, 
+Builder = new MessageBuilder();%0A        EmbedBuilder embedBuilder = new EmbedBuilder();%0A%0A        embedBuilder%0A            .setImage(%22attachment://%22 + getClass().getSimpleName() + %22-%22 + imageIndex + %22.gif%22)%0A            .setDescription(
 buil
@@ -2319,25 +2319,30 @@
 message)
-%0A
+)%0A    
         
 ).setIma
@@ -2337,18 +2337,17 @@
     
-)
 .set
-Image
+Color
 (get
@@ -2361,86 +2361,74 @@
 tion
-Images().get(%0A            RandomUtil.getInteger(getInteractionImages().size
+Color());%0A%0A        messageBuilder.setEmbed(embedBuilder.build
 ())
+;%0A
 %0A   
@@ -2432,20 +2432,21 @@
         
-));%0A
+try %7B
 %0A       
@@ -2450,155 +2450,311 @@
     
-if (getInteractionColor() != null) %7B%0A            placeholderMessage.setColor(getInteractionColor());%0A        %7D%0A%0A        placeholderMessage.queue();
+    InputStream stream = new URL(getInteractionImages().get(imageIndex)).openStream();%0A%0A            message.getChannel().sendFile(stream, getClass().getSimpleName() + %22-%22 + imageIndex + %22.gif%22, messageBuilder.build()).queue();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D
 %0A   

Make interaction command upload images instead of using slow links