All pastes #748647 Raw Edit

Anonymous

public text v1 · immutable
#748647 ·published 2007-10-25 00:04 UTC
rendered paste body
import org.jibble.pircbot.*;
import com.google.soap.search.*;
import org.jibble.jmegahal.*;
import java.util.*;
import java.io.*;

public class PyroBot extends PircBot {
    
    // A map of String (nickname) to ArrayList (message Strings).
    private HashMap messages = new HashMap( );
    
...

    String prefix = "?";
    
    public PyroBot() {
    	this.setLogin("fire");
        this.setName("PyroBot");
    }
    
    
    JMegaHal hal = new JMegaHal();
    
    public void onMessage(String channel, String sender, String login, String hostname, String message) {
        
        String[] tokens = message.split("\\s+");
        
        // Tell
        if (tokens.length > 2 && tokens[0].equalsIgnoreCase(prefix+"tell")) {
            String nick = tokens[1];
            message = message.substring(message.indexOf(nick) + nick.length( ) + 1);
            
            // Convert the nickname to lowercase for use in the HashMap.
            String key = nick.toLowerCase( );
            ArrayList list = (ArrayList) messages.get(key);
            if (list == null) {
                // Create a new ArrayList if the HashMap entry is empty.
                list = new ArrayList( );
                messages.put(key, list);
            }
            
            // Add the message to the list for the target nickname.
            list.add(sender + " asked me to tell you " + message);
            sendMessage(channel, "Okay, " + sender);
        }
        
...


        
        
    public void onJoin(String channel, String sender, String login, String hostname) {
        
        // Convert the nickname to lowercase to get the HashMap key.
        String key = sender.toLowerCase( );
        ArrayList list = (ArrayList) messages.get(key);
        if (list != null) {
            // Send all messages to the user.
            for (int i = 0; i < list.size( ); i++) {
                String message = (String) list.get(i);
                sendMessage(channel, sender + ", " + message);
            }
            // Now erase all messages for this user.
            messages.put(key, null);
        }
    };
    
    
    }
}