package com.tterrag.k9.commands;

import java.io.File;
import java.util.stream.Collectors;

import org.apache.commons.io.IOUtils;

import com.google.common.base.Charsets;
import com.google.gson.Gson;
import com.tterrag.k9.K9;
import com.tterrag.k9.commands.api.Command;
import com.tterrag.k9.commands.api.CommandBase;
import com.tterrag.k9.commands.api.CommandContext;
import com.tterrag.k9.listeners.CommandListener;

import discord4j.core.DiscordClient;
import reactor.core.publisher.Mono;

@Command
public class CommandAbout extends CommandBase {
    
    public CommandAbout() {
        super("about", false);
    }
    
    private final Mono<String> recentChanges = Mono.fromCallable(() -> {
        return IOUtils.readLines(K9.class.getResourceAsStream("/recent-changes.txt"), Charsets.UTF_8)
                .stream()
                .collect(Collectors.joining("\n"));
    }).cache();
    
    @Override
    public void onRegister(DiscordClient client) {
        super.onRegister(client);
        recentChanges.subscribe();
    }

    @Override
    public Mono<?> process(CommandContext ctx) {
        String ver = K9.getVersion();
        return ctx.getClient().getSelf()
            .flatMap(u -> ctx.reply(spec ->
                spec.setThumbnail(u.getAvatarUrl())
                    .setDescription("A bot for looking up Minecraft mappings, and other useful things.\nFor more info, try `" + CommandListener.getPrefix(ctx.getGuildId()) + "help`.")
                    .setTitle("K9 " + ver)
                    .setUrl("http://tterrag.com/k9")
                    .addField("Source", "https://github.com/tterrag1098/K9", false)
                    .addField("Recent Changes", recentChanges.block(), false)
            ));
    }

    @Override
    public String getDescription(CommandContext ctx) {
        return "Provides info about the current version of the bot.";
    }

}

@@ -31,29 +31,8 @@
 s;%0A%0A
-import java.io.File;%0A
 impo
@@ -63,16 +63,16 @@
 ectors;%0A
+
 %0Aimport 
@@ -147,37 +147,8 @@
 ts;%0A
-import com.google.gson.Gson;%0A
 impo
@@ -360,16 +360,50 @@
 istener;
+%0Aimport com.tterrag.k9.util.Monos;
 %0A%0Aimport
@@ -1176,17 +1176,63 @@
    .
-flatMap(u
+transform(Monos.flatZipWith(recentChanges, (u, changes)
  -%3E 
@@ -1717,29 +1717,15 @@
 s%22, 
-recentChanges.block()
+changes
 , fa
@@ -1741,16 +1741,17 @@
         
+)
 ));%0A    

Remove block call in CommandAbout