/**
 * Copyright (C) 2013 Oldterns
 *
 * This file may be modified and distributed under the terms
 * of the MIT license. See the LICENSE file for details.
 */
package com.oldterns.vilebot.handlers.user;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.engio.mbassy.listener.Handler;
import ca.szc.keratin.bot.annotation.HandlerContainer;
import ca.szc.keratin.core.event.message.recieve.ReceivePrivmsg;

@HandlerContainer
public class Help
{
    private static final Pattern helpPattern = Pattern.compile( "!help" );

    private static final String helpMessage = generateHelpMessage();

    /**
     * Reply to user !help command with help info
     */
    @Handler
    private void userHelp( ReceivePrivmsg event )
    {
        String text = event.getText();
        Matcher matcher = helpPattern.matcher( text );

        if ( matcher.matches() )
        {
            event.replyPrivately( helpMessage );
        }
    }

    private static String generateHelpMessage()
    {
        StringBuilder sb = new StringBuilder();

        sb.append( "Available Commands:" );

        sb.append( "  General:" );
        sb.append( " { !help }" );
        sb.append( " { !ping }" );
        sb.append( "  Karma:" );
        sb.append( " { noun++ }" );
        sb.append( " { noun-- }" );
        sb.append( " { !rank <noun> }" );
        sb.append( " { !revrank <place> }" );
        sb.append( " { !unrank <noun> }" );
        sb.append( " { !rankn <place> }" );
        sb.append( " { !revrankn <place> }" );
        sb.append( " { !topthree }" );
        sb.append( " { !bottomthree }" );
        sb.append( " { !roll [for] [karma wager] }" );
        sb.append( " { !rollcancel }" );
        sb.append( "  Facts/Quotes:" );
        sb.append( " { !fact <noun> }" );
        sb.append( " { !quote <noun> }" );
        sb.append( " { !factadd <noun> <quote> }" );
        sb.append( " { !quoteadd <noun> <quote> }" );
        sb.append( "\n" );
        sb.append( "{ !factsearch <noun> <regex> }" );
        sb.append( " { !quotesearch <noun> <regex> }" );
        sb.append( "  Utility:" );
        sb.append( " { s/foo/bar[/[g]] }" );
        sb.append( " { !decide [noun] {prefix} <choice1>[|choice2]... }" );
        sb.append( " { !weather [IATA code] }" );
        sb.append( " { !lessweather [IATA code] }" );
        sb.append( " { !moreweather [IATA code] }" );
        sb.append( "  Userlists:" );
        sb.append( " { !list <listname> }" );
        sb.append( " { !listadd <listname> <noun>[,|, | ][noun2]... }" );
        sb.append( " { !listrem <listname> <noun>[,|, | ][noun2]... }" );
        sb.append( " { listname: [message] }" );
        sb.append( "  Fun:" );
        sb.append( " { !excuse }" );
        sb.append( " { !randommeme }" );
        sb.append( " { !chuck }" );
        sb.append( " { !dance }" );

        return sb.toString();
    }
}

@@ -1647,16 +1647,17 @@
  %5Bfor%5D %5B
+%3C
 karma wa
@@ -1659,16 +1659,17 @@
 ma wager
+%3E
 %5D %7D%22 );%0A
@@ -2152,16 +2152,25 @@
 bar%5B/%5Bg%5D
+ %5B%3Cnoun%3E%5D
 %5D %7D%22 );%0A
@@ -2205,21 +2205,25 @@
 de %5B
+%3C
 noun
+%3E
 %5D %7B
+%3C
 prefix
+%3E
 %7D %3Cc
@@ -2235,15 +2235,17 @@
 1%3E%5B%7C
+%3C
 choice2
+%3E
 %5D...
@@ -2276,32 +2276,33 @@
 ( %22 %7B !weather %5B
+%3C
 IATA code%5D %7D%22 );
@@ -2286,32 +2286,33 @@
 ther %5B%3CIATA code
+%3E
 %5D %7D%22 );%0A        
@@ -2332,32 +2332,33 @@
 %7B !lessweather %5B
+%3C
 IATA code%5D %7D%22 );
@@ -2342,32 +2342,33 @@
 ther %5B%3CIATA code
+%3E
 %5D %7D%22 );%0A        
@@ -2396,16 +2396,17 @@
 eather %5B
+%3C
 IATA cod
@@ -2406,16 +2406,17 @@
 ATA code
+%3E
 %5D %7D%22 );%0A
@@ -2548,37 +2548,39 @@
  %3Cnoun%3E%5B,%7C, %7C %5D%5B
+%3C
 noun2
+%3E
 %5D... %7D%22 );%0A     
@@ -2632,21 +2632,23 @@
 ,%7C, %7C %5D%5B
+%3C
 noun2
+%3E
 %5D... %7D%22 

Update help file