// 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 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;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
        Matcher cancelTransferMatcher = cancelTransferPattern.matcher( text );
        Matcher acceptTransferMatcher = acceptTransferPattern.matcher( text );
        Matcher rejectTransferMatcher = rejectTransferPattern.matcher( text );

        if ( transferMatcher.matches() )
            transferKarma( event, transferMatcher );
        if ( cancelTransferMatcher.matches() )
            cancelTransfer( event );
        if ( acceptTransferMatcher.matches() )
            acceptTransfer( event );
        if ( rejectTransferMatcher.matches() )
            rejectTransfer( event );
    }

    private void transferKarma( GenericMessageEvent event, Matcher transferMatcher )
    {
        // Prevent users from transferring karma outside of #thefoobar
        if ( !( event instanceof MessageEvent )
            || !( (MessageEvent) event ).getChannel().getName().equals( Vilebot.getConfig().get( "ircChannel1" ) ) )
        {
            event.respondWith( "You must be in " + Vilebot.getConfig().get( "ircChannel1" ) + " to transfer karma." );
            return;
        }

        synchronized ( currentTransferMutex )
        {
            // No existing transfer
            if ( currentTransaction == null )
            {
                // Check if sender is the same as the receiver
// 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/KarmaTransfer.java
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;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

        Matcher cancelTransferMatcher = cancelTransferPattern.matcher( text );
        Matcher acceptTransferMatcher = acceptTransferPattern.matcher( text );
        Matcher rejectTransferMatcher = rejectTransferPattern.matcher( text );

        if ( transferMatcher.matches() )
            transferKarma( event, transferMatcher );
        if ( cancelTransferMatcher.matches() )
            cancelTransfer( event );
        if ( acceptTransferMatcher.matches() )
            acceptTransfer( event );
        if ( rejectTransferMatcher.matches() )
            rejectTransfer( event );
    }

    private void transferKarma( GenericMessageEvent event, Matcher transferMatcher )
    {
        // Prevent users from transferring karma outside of #thefoobar
        if ( !( event instanceof MessageEvent )
            || !( (MessageEvent) event ).getChannel().getName().equals( Vilebot.getConfig().get( "ircChannel1" ) ) )
        {
            event.respondWith( "You must be in " + Vilebot.getConfig().get( "ircChannel1" ) + " to transfer karma." );
            return;
        }

        synchronized ( currentTransferMutex )
        {
            // No existing transfer
            if ( currentTransaction == null )
            {
                // Check if sender is the same as the receiver
                String sender = BaseNick.toBaseNick( event.getUser().getNick() );