// Path: vilebot/src/main/java/com/oldterns/vilebot/util/BaseNick.java
// public class BaseNick
// {
//     // This would grab the leading x out of a nick that actually contains it
//     private static Pattern nickPattern = Pattern.compile( "(?:x|)([a-zA-Z0-9]+)(?:\\p{Punct}+[a-zA-Z0-9]*|)" );
// 
//     private static String primaryBotNick;
// 
//     private static Set<String> allBotNicks = new HashSet<>();
// 
//     public static String toBaseNick( String nick )
//     {
//         if ( allBotNicks.contains( nick ) )
//         {
//             nick = primaryBotNick;
//         }
//         else
//         {
//             Matcher nickMatcher = nickPattern.matcher( nick );
// 
//             if ( nickMatcher.find() )
//             {
//                 return nickMatcher.group( 1 );
//             }
//         }
//         return nick;
//     }
// 
//     public static String getPrimaryBotNick()
//     {
//         return primaryBotNick;
//     }
// 
//     public static void setPrimaryBotNick( String primaryNick )
//     {
//         primaryBotNick = primaryNick;
//     }
// 
//     public static Set<String> getBotNicks()
//     {
//         return allBotNicks;
//     }
// 
//     public static void addBotNick( String nick )
//     {
//         allBotNicks.add( nick );
//     }
// }


import java.security.SecureRandom;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.oldterns.vilebot.Vilebot;
import com.oldterns.vilebot.db.KarmaDB;
import com.oldterns.vilebot.util.BaseNick;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.MessageEvent;
import org.pircbotx.hooks.types.GenericMessageEvent;
package com.oldterns.vilebot.handlers.user;



public class KarmaRoll
    extends ListenerAdapter
{
    private static final Pattern rollPattern = Pattern.compile( "!roll(?: for|)(?: +([0-9]+)|)" );

    private static final Pattern cancelPattern = Pattern.compile( "!roll ?cancel" );

    private static final int UPPER_WAGER = 10;

    private RollGame currentGame;

    private final Object currentGameMutex = new Object();

    @Override
    public void onGenericMessage( final GenericMessageEvent event )
    {
        String text = event.getMessage();

        Matcher rollMatcher = rollPattern.matcher( text );
        Matcher cancelMatcher = cancelPattern.matcher( text );

        if ( rollMatcher.matches() )
            userHelp( event, rollMatcher );
        if ( cancelMatcher.matches() )
            manualCancel( event );
    }

    // @Handler
    private void userHelp( GenericMessageEvent event, Matcher rollMatcher )
    {
// Path: vilebot/src/main/java/com/oldterns/vilebot/util/BaseNick.java
// public class BaseNick
// {
//     // This would grab the leading x out of a nick that actually contains it
//     private static Pattern nickPattern = Pattern.compile( "(?:x|)([a-zA-Z0-9]+)(?:\\p{Punct}+[a-zA-Z0-9]*|)" );
// 
//     private static String primaryBotNick;
// 
//     private static Set<String> allBotNicks = new HashSet<>();
// 
//     public static String toBaseNick( String nick )
//     {
//         if ( allBotNicks.contains( nick ) )
//         {
//             nick = primaryBotNick;
//         }
//         else
//         {
//             Matcher nickMatcher = nickPattern.matcher( nick );
// 
//             if ( nickMatcher.find() )
//             {
//                 return nickMatcher.group( 1 );
//             }
//         }
//         return nick;
//     }
// 
//     public static String getPrimaryBotNick()
//     {
//         return primaryBotNick;
//     }
// 
//     public static void setPrimaryBotNick( String primaryNick )
//     {
//         primaryBotNick = primaryNick;
//     }
// 
//     public static Set<String> getBotNicks()
//     {
//         return allBotNicks;
//     }
// 
//     public static void addBotNick( String nick )
//     {
//         allBotNicks.add( nick );
//     }
// }


// Path: vilebot/src/main/java/com/oldterns/vilebot/handlers/user/KarmaRoll.java
import java.security.SecureRandom;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.oldterns.vilebot.Vilebot;
import com.oldterns.vilebot.db.KarmaDB;
import com.oldterns.vilebot.util.BaseNick;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.MessageEvent;
import org.pircbotx.hooks.types.GenericMessageEvent;

package com.oldterns.vilebot.handlers.user;



public class KarmaRoll
    extends ListenerAdapter
{
    private static final Pattern rollPattern = Pattern.compile( "!roll(?: for|)(?: +([0-9]+)|)" );

    private static final Pattern cancelPattern = Pattern.compile( "!roll ?cancel" );

    private static final int UPPER_WAGER = 10;

    private RollGame currentGame;

    private final Object currentGameMutex = new Object();

    @Override
    public void onGenericMessage( final GenericMessageEvent event )
    {
        String text = event.getMessage();

        Matcher rollMatcher = rollPattern.matcher( text );
        Matcher cancelMatcher = cancelPattern.matcher( text );

        if ( rollMatcher.matches() )
            userHelp( event, rollMatcher );
        if ( cancelMatcher.matches() )
            manualCancel( event );
    }

    // @Handler
    private void userHelp( GenericMessageEvent event, Matcher rollMatcher )
    {
        String sender = BaseNick.toBaseNick( event.getUser().getNick() );