/*
 * The MIT License
 *
 * Copyright (c) 2016 Marcelo "Ataxexe" Guimarães <ataxexe@devnull.tools>
 *
 * Permission  is hereby granted, free of charge, to any person obtaining
 * a  copy  of  this  software  and  associated  documentation files (the
 * "Software"),  to  deal  in the Software without restriction, including
 * without  limitation  the  rights to use, copy, modify, merge, publish,
 * distribute,  sublicense,  and/or  sell  copies of the Software, and to
 * permit  persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * The  above  copyright  notice  and  this  permission  notice  shall be
 * included  in  all  copies  or  substantial  portions  of the Software.
 *
 * THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY OF ANY KIND,
 * EXPRESS  OR  IMPLIED,  INCLUDING  BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN  NO  EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM,  DAMAGES  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT  OR  OTHERWISE,  ARISING  FROM,  OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE   OR   THE   USE   OR   OTHER   DEALINGS  IN  THE  SOFTWARE.
 */

package tools.devnull.boteco.plugins.help;

import tools.devnull.boteco.AlwaysActive;
import tools.devnull.boteco.message.IncomeMessage;
import tools.devnull.boteco.message.MessageProcessor;
import tools.devnull.boteco.message.checker.Command;
import tools.devnull.boteco.plugin.Plugin;

import java.util.List;
import java.util.stream.Collectors;

@Command("help")
@AlwaysActive
public class HelpMessageProcessor implements MessageProcessor {

  private final List<Plugin> plugins;

  public HelpMessageProcessor(List<Plugin> plugins) {
    this.plugins = plugins;
  }

  @Override
  public void process(IncomeMessage message) {
    message.command()
        .on("plugin", String.class, name -> message.reply("Ui"))
        .orElseReturn(buildPluginList());
  }

  private String buildPluginList() {
    return "List of plugins:\n" +
        this.plugins.stream().map(Plugin::description).collect(Collectors.joining("\n"));
  }

}

@@ -2108,67 +2108,238 @@
 am()
+%0A            
 .map(
-P
+p
 lugin
-::description).collect(Collectors.joining(%22%5Cn%22))
+ -%3E String.format(%22- %5Ba%5D%25s%5B/a%5D: %25s%22, plugin.id(), plugin.description()))%0A            .collect(Collectors.joining(%22%5Cn%22)) +%0A        %22%5CnTo get help for a specific plugin, send the command %5Bv%5Dhelp %3Cplugin%3E%5B/v%5D%22
 ;%0A  

update reply message