All pastes #629319 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-07-22 04:05 UTC
rendered paste body
import org.jibble.pircbot.*;
import com.google.soap.search.*;
import org.jibble.jmegahal.*;
import java.util.*;
import java.io.*;
import javax.swing.*;

public class TMSModBot extends PircBot {
    
    // Set up runtime variables.
    private static final String googleKey = "it+is+none+of+your+buisiness";
    boolean disabler = true;
    boolean killer = false;
    boolean trainingMode = true;
    private JMegaHal hal;
    private HashMap lastSeen = new HashMap( );
    private Random random = new Random( );
    String[] add = { "Empty quote.", "Empty quote.", "Empty quote.", "Empty quote.","Empty quote.","Empty quote.","Empty quote.","Empty quote.","Empty quote.","Empty quote.", };
    
@@    // Set up the management frame.
@@    JFrame myFrame = new JFrame();
@@    myFrame.setTitle("asdf");
  
    
    // Set up bot main information.
    public TMSModBot() {
        this.setName("TMSModBot");
        this.setLogin("yourmom");
        hal = new JMegaHal( );
    }
    
    public void onConnect() {
    	this.sendRawLine("ns IDENTIFY thepasswordisnoneofyourbuisiness");
    }
    
    // If the bot disconnects, then report it to the user and exit.
    public void onDisconnect() {
		while (!isConnected()) {
			if (killer == false) {
    		try {
    			System.out.println("Reconnection: Attempt 1");
        		reconnect();
   		} catch (Exception e1) {
				try {
					System.out.println("Reconnection: Attempt 2");
					reconnect();
				} catch (Exception e2) {
					try {
						System.out.println("Reconnection: Attempt 3");
						reconnect();
					} catch (Exception e3) {
						System.out.println("Could not reconnect to server.");
						System.exit(0);
					}
				}
    	}
	} else {
		System.out.println("Disconnected on request.");
		System.exit(0);
	}
	}
    }
    
    public void onJoin(String channel, String sender, String login, String hostname) {
    	if (sender.equalsIgnoreCase("TMSModBot")) {
    		sendMessage(channel, "Sup. TMSModBot v4.0 here, type %help for a list of available commands.");
    	}
    }
    
    // If the bot is kicked, rejoin.
    public void onKick(String channel, String sender, String login, String hostname, String message, String recipientNick) {
		if (!channel.equals("#PureZC")) {
			sendMessage(channel, "0WN3D");
    	}
    }
    
    public void onPrivateMessage(String sender, String login, String hostname, String message) {
    	if (message.startsWith("join ") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	String channelToJoin = message.substring(5).trim();
        	joinChannel(channelToJoin);
        	sendMessage(sender, "Attempted to join " + channelToJoin + ".");
        }
        
        if (message.startsWith("part ") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	String channelToPart = message.substring(5).trim();
        	this.sendRawLine("part " + channelToPart + " I was told to leave this channel. Bye!");
        	sendMessage(sender, "I have parted from channel " + channelToPart + ".");
        }
        
        if (message.startsWith("raw ") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	String command = message.substring(4).trim();
        	this.sendRawLine(command);
        	sendMessage(sender, "Raw command executed.");
        }
        
    	// Help library.
    	if (message.equalsIgnoreCase("help")) {
    		sendMessage(sender, "Welcome to TMSModBot! Here is a list of my current commands. Commands that are bold are being developed.");
    		sendMessage(sender, "fortune, coin, 8ball, google, seen, roll, quote");
    		sendMessage(sender, "Note that all commands are prefixed with a % (percent sign). ALSO NOTE THAT COMMANDS CAN ONLY BE USED IN A CHANNEL!");
    	} else {
            // Make the bot learn the message.
            hal.add(message);
    	}

        
    }
    
	public void onAction(String sender, String login, String hostname, String target, String action) {
		 if (action.equalsIgnoreCase("hands TMSModBot a soda.") && disabler == true || action.equalsIgnoreCase("hands TMSModBot a soda") && disabler == true || action.equalsIgnoreCase("gives TMSModBot a soda.") && disabler == true || action.equalsIgnoreCase("hands TMSModBot a soda") && disabler == true || action.equalsIgnoreCase("hands a soda to TMSModBot") && disabler == true || action.equalsIgnoreCase("hands a soda to TMSModBot.") && disabler == true || action.equalsIgnoreCase("gives a soda to TMSModBot.") && disabler == true || action.equalsIgnoreCase("gives a soda to TMSModBot") && disabler == true) {
		 	sendAction(target, "throws the soda at " + sender + "'s face, he doesn't drink soda!");
		 }
		 
		 if (action.equalsIgnoreCase("pokes TMSModBot.") && disabler == true || action.equalsIgnoreCase("pokes TMSModBot")) {
		 	sendAction(target, "screams: OW!!!");
		 }
		 
	}
    
    public void onInvite(String targetNick,  String sourceNick, String sourceLogin, String sourceHostname, String channel) {
    	if (targetNick.equals("TMSModBot")) {
    		this.sendRawLine("join " + channel);
    	} 
    }
    
    // Command Library
    public void onMessage(String channel, String sender, String login, String hostname, String message) {
        
		
        if (message.equalsIgnoreCase("%help") && disabler == true) {
        	this.sendRawLine("NOTICE "+sender+" :Welcome to TMSModBot! Here is a list of my current commands. Commands that are bold are being developed.");
    		this.sendRawLine("NOTICE "+sender+" :fortune, coin, 8ball, google, seen, roll");
    		this.sendRawLine("NOTICE "+sender+" :Note that all commands are prefixed with a % (percent sign).");
    		this.sendRawLine("NOTICE "+sender+" :Quotation help: To add/delete/view a quotation, type %add[quotenumber]/%clear[quotenumber]/%quote[quotenumber], respectively.");
    		this.sendRawLine("NOTICE "+sender+" :Note that there is no spaces between those quotation commands and the quotenumber! Up to 10 quotes can be stored.");
        }
        
        if (message.startsWith("%raw ") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	String command = message.substring(5).trim();
        	this.sendRawLine(command);
        	sendMessage(channel, "Raw command executed.");
        }
        
    	if (message.startsWith("%join ") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	String channelToJoin = message.substring(6).trim();
        	if (channelToJoin != "0") {
        		joinChannel(channelToJoin);
        		sendMessage(sender, "Attempted to join " + channelToJoin + ".");
        	}
        }
        
        if (message.startsWith("%part ") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	String channelToPart = message.substring(6).trim();
        	this.sendRawLine("part " + channelToPart + " I was told to leave this channel. Bye!");
        	sendMessage(sender, "I have parted from channel " + channelToPart + ".");
        }        
        
        if (message.equalsIgnoreCase("%disable") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	disabler = false;
        	sendMessage(channel, "I have been disabled.");
        }
        
        if (message.equalsIgnoreCase("%enable") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	disabler = true;
        	sendMessage(channel, "I have been enabled.");
        }
        
        if (message.equalsIgnoreCase("%kill") && sender.equalsIgnoreCase("TheMasterSwordsman")) {
        	this.sendRawLine("quit I've been killed from this server! Oh Noes!!!");
        	killer = true;
        	
        }
    	
    	// Quotations
		if (message.startsWith("%add1 ")) {
			String add1 = message.substring(6).trim();
			add[0] = add1;
			sendMessage(channel, "The quote \""+ add1 + "\" has successfully been added.");
		} else if (message.startsWith("%add2 ")) {
			String add2 = message.substring(6).trim();
			add[1] = add2;
			sendMessage(channel, "The quote \""+ add2 + "\" has successfully been added.");
		} else if (message.startsWith("%add3 ")) {
			String add3 = message.substring(6).trim();
			add[2] = add3;
			sendMessage(channel, "The quote \""+ add3 + "\" has successfully been added.");
		} else if (message.startsWith("%add4 ")) {
			String add4 = message.substring(6).trim();
			add[3] = add4;
			sendMessage(channel, "The quote \""+ add4 + "\" has successfully been added.");
		} else if (message.startsWith("%add5 ")) {
			String add5 = message.substring(6).trim();
			add[4] = add5;
			sendMessage(channel, "The quote \""+ add5 + "\" has successfully been added.");
		} else if (message.startsWith("%add6 ")) {
			String add6 = message.substring(6).trim();
			add[5] = add6;
			sendMessage(channel, "The quote \""+ add6 + "\" has successfully been added.");
		} else if (message.startsWith("%add7 ")) {
			String add7 = message.substring(6).trim();
			add[6] = add7;
			sendMessage(channel, "The quote \""+ add7 + "\" has successfully been added.");
		} else if (message.startsWith("%add8 ")) {
			String add8 = message.substring(6).trim();
			add[7] = add8;
			sendMessage(channel, "The quote \""+ add8 + "\" has successfully been added.");
		} else if (message.startsWith("%add9 ")) {
			String add9 = message.substring(6).trim();
			add[8] = add9;
			sendMessage(channel, "The quote \""+ add9 + "\" has successfully been added.");
		} else if (message.startsWith("%add10 ")) {
			String add10 = message.substring(6).trim();
			add[9] = add10;
			sendMessage(channel, "The quote \""+ add10 + "\" has successfully been added.");
		}
		
		if (message.equalsIgnoreCase("%clear1")) {
			add[0] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear2")) {
			add[1] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear3")) {
			add[2] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear4")) {
			add[3] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear5")) {
			add[4] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear6")) {
			add[5] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear7")) {
			add[6] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear8")) {
			add[7] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear9")) {
			add[8] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clear10")) {
			add[9] = "Empty quote.";
			sendMessage(channel, "Quote has been erased.");
		} else if (message.equalsIgnoreCase("%clearall") && sender.equals("TheMasterSwordsman")) {
			add[0] = "Empty quote.";
			add[1] = "Empty quote.";
			add[2] = "Empty quote.";
			add[3] = "Empty quote.";
			add[4] = "Empty quote.";
			add[5] = "Empty quote.";
			add[6] = "Empty quote.";
			add[7] = "Empty quote.";
			add[8] = "Empty quote.";
			add[9] = "Empty quote.";
		}
		
		if (message.equalsIgnoreCase("%quote1")) {
			sendMessage(channel, add[0]);
		} else if (message.equalsIgnoreCase("%quote2")) {
			sendMessage(channel, add[1]);
		} else if (message.equalsIgnoreCase("%quote3")) {
			sendMessage(channel, add[2]);
		} else if (message.equalsIgnoreCase("%quote4")) {
			sendMessage(channel, add[3]);
		} else if (message.equalsIgnoreCase("%quote5")) {
			sendMessage(channel, add[4]);
		} else if (message.equalsIgnoreCase("%quote6")) {
			sendMessage(channel, add[5]);
		} else if (message.equalsIgnoreCase("%quote7")) {
			sendMessage(channel, add[6]);
		} else if (message.equalsIgnoreCase("%quote8")) {
			sendMessage(channel, add[7]);
		} else if (message.equalsIgnoreCase("%quote9")) {
			sendMessage(channel, add[8]);
		} else if (message.equalsIgnoreCase("%quote10")) {
			sendMessage(channel, add[9]);
		}
    	
    	// Dice
        if (message.equals("%dice")) {
            sendMessage(channel, "The die comes to a stop on " + (random.nextInt(6) + 1) + ".");
        } else if (message.equals("%dice double")) {
        	sendMessage(channel, "The dice comes to a stop on " + (random.nextInt(12) + 1) + ".");
        } else if (message.equals("%dice triple")) {
        	sendMessage(channel, "The dice comes to a stop on " + (random.nextInt(18) + 1) + ".");
        }
    	
    	// Magic 8 Ball
        if (message.startsWith("%8ball ") && disabler == true || message.startsWith("%8Ball ") && disabler == true) {
        	Random eightBallRandom = new Random();
        	int responseNumber = eightBallRandom.nextInt(10) + 1;
        	if (responseNumber == 1) {
        		sendMessage(channel, "The 8-Ball Replys: Yes.");
        	} else if (responseNumber == 2) {
        		sendMessage(channel, "The 8-Ball Replys: No.");
        	} else if (responseNumber == 3) {
        		sendMessage(channel, "The 8-Ball Replys: Reply hazy, try asking again.");
        	} else if (responseNumber == 4) {
        		sendMessage(channel, "The 8-Ball Replys: Concentrate and ask again.");
        	} else if (responseNumber == 5) {
        		sendMessage(channel, "The 8-Ball Replys: My sources say yes.");
        	} else if (responseNumber == 6) {
        		sendMessage(channel, "The 8-Ball Replys: My sources say no.");
        	} else if (responseNumber == 7) {
        		sendMessage(channel, "The 8-Ball Replys: Don't count on it.");
        	} else if (responseNumber == 8) {
        		sendMessage(channel, "The 8-Ball Replys: You may rely on it.");
        	} else if (responseNumber == 9) {
        		sendMessage(channel, "The 8-Ball Replys: As I see it, yes.");
        	} else {
        		sendMessage(channel, "The 8-Ball Replys: As I see it, no.");
        	}
        } else if (message.startsWith("%8ball") && disabler == false || message.startsWith("%8Ball ") && disabler == false) {
        	
        }
    	
		if (message.equals("%chanlist")) {
			sendMessage(channel, "TMSModBot is currently connected to the following channels: ");
	    	for (String s : getChannels()) {
    			sendMessage(channel, s);
   			}
		}
    	
    	// Coin flipper
        if (message.equalsIgnoreCase("%coin") && disabler == true) {
        	Random coinRandom = new Random();
        	int coin = coinRandom.nextInt(1000) + 1;
        	if (coin < 500) {
        		sendMessage(channel, "The coin landed on heads.");
        	} else if (coin > 500) {
        		sendMessage(channel, "The coin landed on tails.");
        	} else if (coin == 500) {
        		sendMessage(channel, "The coin landed on the side! Oh noes!");
        	}
        } else if (message.equalsIgnoreCase("%coin") && disabler == false) {
        	
        }
        
        // Fortune teller
        if (message.startsWith("%fortune") && disabler == true) {
        	Random fortuneRandom = new Random();
        	int fortune = fortuneRandom.nextInt(20) + 1;
        	if (fortune == 1) {
        		sendMessage(channel, "Fortune for " + sender + ": You're feeling good? Oh really? GET THE HELMETS!");
        	} else if (fortune == 2) {
        		sendMessage(channel, "Fortune for " + sender + ": You better be glad I'm a bot, because if I wasn't I'd come find you. I WOULD.");
        	} else if (fortune == 3) {
        		sendMessage(channel, "Fortune for " + sender + ": Why ask me? Call 1-800-FORTUNE for a better reading. OH WAIT, YOU HAVE DIALUP! HA HA HA!");
        	} else if (fortune == 4) {
        		sendMessage(channel, "Fortune for " + sender + ": It's going to be a good day. Go sleep with a washrag.");
        	} else if (fortune == 5) {
        		sendMessage(channel, "Fortune for " + sender + ": Today shall be your last. (FINALLY...)");
        	} else if (fortune == 6) {
        		sendMessage(channel, "Fortune for " + sender + ": I'd say that you're really more of a... supernerd.");
        	} else if (fortune == 7) {
        		sendMessage(channel, "Fortune for " + sender + ": True love is among us. The next person to send a message to this channel (other than me) will be your love.");
        	} else if (fortune == 8) {
        		sendMessage(channel, "Fortune for " + sender + ": You must be really bored for asking a BOT to tell your future or something like that...");
        	} else if (fortune == 9) {
        		sendMessage(channel, "Fortune for " + sender + ": IRC is the best place for fortune. It has some really good people in it. So why are you in here?");
        	} else if (fortune == 10) {
        		sendMessage(channel, "Fortune for " + sender + ": The next time you use this command... I am going to reach my hand through your modem and punch you in the face.");
        	} else if (fortune == 11) {
        		sendMessage(channel, "Fortune for " + sender + ": You know, I have censors. I wonder why I never kicked you in the first place...");
        	} else if (fortune == 12) {
        		sendMessage(channel, "Fortune for " + sender + ": When I don't know what to say, this is the message that appears. Deal with it.");
        	} else if (fortune == 13) {
        		sendMessage(channel, "Fortune for " + sender + ": If you are a chatroom addict, all I can say is GTFO.");
        	} else if (fortune == 14) {
        		sendMessage(channel, "Fortune for " + sender + ": You know, I never did like you. That's why I'm not going to give a fortune to you.");
        	} else if (fortune == 15) {
        		sendMessage(channel, "Fortune for " + sender + ": Get a sword and stab yourself. It's the only thing appropriate to tell you.");
        	} else if (fortune == 16) {
        		sendMessage(channel, "Fortune for " + sender + ": The Triforce is with you. But not right now. (Thank God)");
        	} else if (fortune == 17) {
        		sendMessage(channel, "Fortune for " + sender + ": This was a randomly generated reply using random numbers. Why are you wasting my time?");
        	} else if (fortune == 18) {
        		sendMessage(channel, "Fortune for " + sender + ": Go eat a cheeseburger. And while you're there, pick me up a number 2 extra large with a Biggie-sized Dr. Pepper.");
        	} else if (fortune == 19) {
        		sendMessage(channel, "Fortune for " + sender + ": You've been shot. I'm putting down the gun. (YES!)");
        	} else {
        		sendMessage(channel, "Fortune for " + sender + ": If you're seeing this message, you'll be living until you actually try something new. (Like that'll ever happen. Sigh...)");
        	}
        } else if (message.equalsIgnoreCase("%fortune") && disabler == false) {
        	
        }
    	
    	// Google search
        if (message.startsWith("%google ") && disabler == true) {
            String searchTerms = message.substring(8);
            
            String result = null;
            try {
                GoogleSearch search = new GoogleSearch( );
                search.setKey(googleKey);
                search.setQueryString(searchTerms);
                search.setMaxResults(1);
                GoogleSearchResult searchResult = search.doSearch( );
                GoogleSearchResultElement[] elements =
                        searchResult.getResultElements( );
                if (elements.length == 1) {
                    GoogleSearchResultElement element = elements[0];
                    // Remove all HTML tags from the title.
                    String title = element.getTitle( ).replaceAll("<.*?>", "");
                    result = element.getURL( ) + " (" + title + ")";
                    if (!element.getCachedSize( ).equalsIgnoreCase("0")) {
                        result = result + " - " + element.getCachedSize( );
                    }
                }
            }
            catch (GoogleSearchFault e) {
                // Something went wrong. Say why.
                result = "Unable to perform your search: " + e;
            }
            
            if (result == null) {
                // No results were found for the search terms.
                result = "Nothing to be found... Try changing your search terms to something a little less specific.";
            }
            
            // Send the result to the channel.
            sendMessage(channel, sender + ": " + result);
        } else if (message.startsWith("%google ") && disabler == false) {
        	
        }
    	
    	
    	if (message.toLowerCase( ).indexOf("fuck".toLowerCase()) >= 0 || message.toLowerCase( ).indexOf("shit".toLowerCase()) >= 0 || message.toLowerCase( ).indexOf("whore".toLowerCase()) >= 0 || message.toLowerCase( ).indexOf("rape".toLowerCase()) >= 0) {
    		sendMessage(channel, sender + " used bad language on " + new Date() + ".");
    	}

    	
       if (message.toLowerCase( ).indexOf(getNick( ).toLowerCase( )) >= 0 && disabler == true) {
        	// If the bot's nickname was mentioned, generate a random reply for this channel.
            String sentence = hal.getSentence( );
            sendMessage(channel, sentence);
        }
    	
        if (message.startsWith("%seen ") && disabler == true) {
            String nick = message.substring(6).trim( );
            String seen = (String) lastSeen.get(nick.toLowerCase( ));
            if (seen != null) {
                // Tell the channel when this nickname was last seen.
                sendMessage(channel, nick + " was last seen on " + seen);
            } else {
           	// Someone wasn't here, so let's tell them.
                sendMessage(channel, "I haven't seen " + nick + " on this server.");
            }
        } else if (message.startsWith("%seen") && disabler == false) {
        	
        }
        
        if (message.startsWith("%training ") && sender.equals("TheMasterSwordsman")) {
        	String setTraining = message.substring(10).trim();
        	if (setTraining.equals("enable") || setTraining.equals("e")) {
        		trainingMode = true;
        		sendMessage(channel, "Artificial Intelligence Training has been enabled.");
        	} else if (setTraining.equals("disable") || setTraining.equals("d")) {
        		trainingMode = false;
        		sendMessage(channel, "Artificial Intelligence Training has been disabled.");
        	} else {
        		sendMessage(channel, "The value must be enable or disable. (alternatives are e and d)");
        	}
        }
        
        else if (message != "" && trainingMode == true) {
            // Make the bot learn the message.
            hal.add(message);
        }
    	
            
    }
    	
}