Created
July 12, 2013 16:09
-
-
Save jmurth1234/5985618 to your computer and use it in GitHub Desktop.
wtf is with this code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.rymate.markoveriewer; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.jibble.jmegahal.JMegaHal; | |
import org.jibble.pircbot.PircBot; | |
/** | |
* | |
* @author Ryan | |
*/ | |
public class AIBot extends PircBot { | |
public AIBot() { | |
this.setName("markoveriewer"); | |
} | |
public void onMessage(String channel, String sender, String login, String hostname, String message) { | |
File globalFile = new File("brain"); | |
if (message.startsWith("markoverviewer, emulate ") || message.startsWith("markoverviewer: emulate ")) { | |
try { | |
String username = message.substring(message.lastIndexOf(" ") + 1); | |
System.out.println("User is \"" + username + "\""); | |
File userFile = new File(username.toLowerCase()); | |
JMegaHal hal = new JMegaHal(); | |
hal.addDocument(userFile.toURI().toString()); | |
sendMessage(channel, "<" + username + "> " + hal.getSentence()); | |
} catch (IOException ex) { | |
Logger.getLogger(AIBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} else if (message.startsWith("markoverviewer, what is ") || message.startsWith("markoverviewer: what is ")) { | |
try { | |
System.out.println("Object is \"" + message.substring(message.lastIndexOf(" ") + 1) + "\""); | |
JMegaHal hal = new JMegaHal(); | |
hal.addDocument(globalFile.toURI().toString()); | |
sendMessage(channel, hal.getSentence(message.substring(message.lastIndexOf(" ") + 1))); | |
} catch (IOException ex) { | |
Logger.getLogger(AIBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} else { | |
sender = sender.replace("_", ""); | |
File userFile = new File(sender.toLowerCase()); | |
try { | |
if (!userFile.exists() && !globalFile.exists()) { | |
userFile.createNewFile(); | |
globalFile.createNewFile(); | |
} | |
appendToFile(userFile, message); | |
appendToFile(globalFile, message); | |
} catch (IOException ex) { | |
Logger.getLogger(AIBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} | |
public void appendToFile(File f, String s) throws IOException { | |
FileWriter fileWritter = new FileWriter(f.getName(), true); | |
BufferedWriter bufferWritter = new BufferedWriter(fileWritter); | |
bufferWritter.write(s + "."); | |
bufferWritter.write("\n"); | |
bufferWritter.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment