All pastes #542826 Raw Edit

Unnamed

public java v1 · immutable
·published 2007-06-05 22:55 UTC
rendered paste body
import org.jibble.pircbot.*;import java.io.*;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;import javax.xml.parsers.SAXParserFactory;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import java.util.Scanner;import java.util.ArrayList;public class Bot extends PircBot {    public final String PARENT = "C:\\Documents and Settings\\Tanner Rogalsky\\My Documents\\RPG\\users";        public String mainChannel;    public ArrayList<Profile> profiles;    public Bot(String channel, String nick) {        setName(nick);        setLogin(nick);        mainChannel = channel;    }             public void onMessage(String channel, String sender, String login, String hostname, String message) {         }        public void onPrivateMessage(String sender, String login, String hostname, String message){        String[] command = message.toLowerCase().trim().split(" ");        if ((command[0].equals("die,")) && (command[1].equals("mothafucka"))){            quitServer ("Peace out, yo.");        } else if (command[0].equals("help")){            sendMessage(sender, "create <filename>, creates a file");            sendMessage(sender, "load <filename>, loads a file and displays its info");        } else if (command[0].equals("create")){            try {                File f = new File(PARENT, command[1] + ".txt");                if (!f.createNewFile()){                    sendMessage(sender, "The requested file already exists.");                } else {                    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));                    out.println(command[1]);                    out.println(sender + "!" + login + "@" + hostname);                    out.close();                    sendMessage(sender, "File created succesfully.");                }            } catch(Exception e){                sendMessage(sender, "An error occured while trying to create the file.");            }        } else if (command[0].equals("load")){            if (!new File(PARENT, command[1] + ".txt").exists()){                sendMessage(sender, "This file does not exist.");            } else {                Profile temp = readProfile(command[1]);                System.out.println(temp.toString());                                if (temp.equals(null)){                    sendMessage (sender, "And error occured while trying to load the file.");                } else {                    sendMessage(sender, "The name of this file is: " + temp.getName());                    sendMessage(sender, "The creator of this file is: " + temp.getCreator());                }            }        }    }        public void onJoin(String channel, String sender, String login, String hostname){        sendNotice(sender, "Type \"/msg " + getNick() + " help\" for help.");    }        public void onDisconnect(){        System.exit(0);    }        public Profile readProfile(String name){        Scanner s = null;        StringBuffer buffer = new StringBuffer();        try {            s = new Scanner(new BufferedReader(new FileReader(new File(PARENT, name + ".txt"))));            while (s.hasNextLine()) {                buffer.append(s.nextLine());            }        } catch(Exception e){            s.close();            return null;        } finally {            if (s != null) {                s.close();            }        }        if (buffer.length() > 0){            return new Profile(buffer.toString());        } else return null;    }        public void message(String message){        sendMessage(mainChannel, message);    } }