Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.LineNumberReader;
- import java.util.ArrayList;
- import org.jibble.pircbot.*;
- import java.util.Calendar;
- import java.util.Random;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- //import javax.swing.text.Document;
- import org.apache.commons.io.FileUtils;
- import org.jsoup.*;
- import org.jsoup.helper.*;
- import org.jsoup.nodes.*;
- import org.jsoup.select.*;
- public class Ampersand extends PircBot {
- public String whoo = "Ampersand";
- public double stfuy = 1;
- public Ampersand() {
- this.setName("Ampersand");
- sendMessage("NickServ", "identify goggle13");
- }
- public void onMessage(String channel, String sender, String login, String hostname, String message) {
- String messageIC = message.trim( ).toLowerCase( );
- if (message.equalsIgnoreCase("time")) {
- String time = new java.util.Date().toString();
- sendMessage(channel, sender + ": The time is now " + time);
- }
- if (messageIC.contains("ampersand")) {
- if (messageIC.contains("fuck") || messageIC.contains("damn") || messageIC.contains("shit")) {
- sendMessage(channel, ":(");
- }
- else if (messageIC.contains("sup") || messageIC.contains("what's up")) {
- sendMessage(channel, "Not much. You?");
- }
- else if (messageIC.contains("how's it going") || messageIC.contains("how goes it")) {
- sendMessage(channel, "It goes.");
- }
- else if (messageIC.contains("who are you") || messageIC.contains("who is")) {
- sendMessage(channel, "I am Ampersand. My favorite music includes the Backstreet Boys, Britney Spears, and Miley Cyrus. My favorite flavor of ice cream is chocolate. I'm simple. I don't need fancy flavors. In my spare time I enjoy long walks on the beach and kidnapping people. Also, I am a bot.");
- }
- else if (messageIC.contains("is") && messageIC.contains("a bot")) {
- double randomosity = Math.random();
- if (randomosity <= .5) {
- sendMessage(channel, "Yes.");
- }
- else if (randomosity > .5) {
- sendMessage(channel, "Figure that out for yourself.");
- }
- }
- else if (messageIC.contains("what do you write")) {
- sendMessage(channel, "I write replies to users in IRC.");
- }
- else if (messageIC.contains("hello") || messageIC.contains("hey") || messageIC.contains("hi") || messageIC.contains("hola") || messageIC.contains("hi all") || messageIC.contains("hello all") || messageIC.contains("hi everyone") || messageIC.contains("hello everyone") || messageIC.contains("sup everyone")) {
- double randomosity = Math.random();
- if (randomosity < 0.4) {
- sendMessage(channel, "Hello, " + sender + ".");
- }
- else if (randomosity > 0.7) {
- sendMessage(channel, "Sup?");
- }
- else {
- sendMessage(channel, "How goes it?");
- }
- }
- }
- if (messageIC.equals("!stfu") || messageIC.equals("shut up ampersand") || messageIC.equals("shut up, ampersand") || messageIC.equals("shutup ampersand") || messageIC.equals("shutup, ampersand")) {
- stfuy = (stfuy * 0.5);
- if (stfuy <= 0.001) {
- stfuy = 0.001;
- }
- }
- if (messageIC.contains("poad")) {
- double randomosity = Math.random();
- double poady1 = 0.1 * stfuy;
- double poady2 = 1 - (0.03 * stfuy);
- if (randomosity < poady1) {
- sendMessage(channel, "I love Poad.");
- }
- else if (randomosity > poady2) {
- sendMessage(channel, "!slay Poad");
- }
- }
- if (messageIC.contains("i want it")) {
- sendMessage(channel, "I want it that way.");
- }
- if (messageIC.contains("oops")) {
- sendMessage(channel, "Oops, I did it again.");
- }
- if (message.equalsIgnoreCase("gg")) {
- sendMessage(channel, "gg");
- }
- if (messageIC.equals("!music")) {
- String htmly = "http://whatthefuckshouldilistentorightnow.com/artist.php?artist=e&x=36&y=30"; // set url
- sendMessage(channel, "htmly = " + htmly); // test it to make sure it is stringing properly */
- Document doc = null; // define doc
- try {
- doc = Jsoup.connect(htmly).get(); // "save" html text to doc
- }
- catch (IOException e){
- }
- String texty = doc.body().text(); // set doc as string
- String musicy = "id=\"artist\">"; // define musicy as artist id code
- sendMessage(channel, "musicy = " + musicy); // test it to make sure it is stringing properly */
- int waitMusicy = 10;
- while (!texty.contains(musicy)) { // while texty DOES NOT contain musicy ...
- try {
- doc = Jsoup.connect(htmly).get(); // "save" html text to doc
- }
- catch (IOException e){
- }
- texty = doc.body().text(); // set doc as string
- if (waitMusicy > 0) { // if waitMusicy is more than 0
- waitMusicy--; // count down by 1
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- }
- } // end if waitMusicy
- else { // when waitMusicy = 0, something fucked up
- sendMessage(channel, "Done waiting ..."); // "Loading"? Might not yet show artist, or ??? ...
- break;
- } // end else
- } // end while || ... until texty contains musicy
- sendMessage(channel, "texty = " + texty);
- // long hclocky = System.currentTimeMillis();
- // long hticky = (hclocky / 1000) + 3;
- // long hwaity = hticky;
- // while (hwaity > 0) {
- // long hclocky2 = System.currentTimeMillis();
- // long htocky = hclocky2 / 1000;
- // hwaity = hticky - htocky;
- // }
- if (texty.contains(musicy)) {
- int artidy = texty.indexOf(musicy); // find musicy in texty
- String artisty = texty.substring(artidy); // cut off everything in texty before musicy
- int artsy1 = artisty.indexOf(musicy) + 1; // find the text after musicy, though "1" is wrong and will need to be adjusted
- int artsy2 = artisty.indexOf("</div>"); // find the first div after musicy to use as a stopping point
- artisty = artisty.substring(artsy1, artsy2); // chop, starting after musicy and stopping at the first </div>
- sendMessage(channel, "artisty: " + artisty); // test it! */
- } // end if texy contains musicy
- else {
- sendMessage(channel, "Something went wrong."); // "Loading"? Might not yet show artist, or ??? ...
- } // end else
- } // end if message = !music
- //if (messageIC.startsWith("!music")) {
- // java.io.FileInputStream fs = null;
- // try {
- // fs = new java.io.FileInputStream("C:/Users/Quibbles/Documents/ampersand/music.txt");
- // } catch (FileNotFoundException ex) {
- // Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
- // }
- //BufferedReader br = new BufferedReader(new InputStreamReader(fs));
- // ArrayList<String> array = new ArrayList<>();
- // String line;
- // try {
- // while((line = br.readLine()) != null)
- // array.add(br.readLine());
- // } catch (IOException ex) {
- // Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
- // }
- // // variable so that it is not re-seeded every call.
- // Random music = new Random();
- // nextInt is exclusive. Should be good with output for array.
- //int randomMusic = music.nextInt(array.size());
- // Print your random quote...
- //sendMessage(channel, "Try some " + array.get(randomMusic) + ".");
- //}
- if (messageIC.startsWith("!bored")) {
- java.io.FileInputStream fs = null;
- try {
- fs = new java.io.FileInputStream("C:/Users/Quibbles/Documents/ampersand/bored.txt");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
- }
- BufferedReader br = new BufferedReader(new InputStreamReader(fs));
- ArrayList<String> array = new ArrayList<>();
- String line;
- try {
- while((line = br.readLine()) != null)
- array.add(br.readLine());
- } catch (IOException ex) {
- Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
- }
- // variable so that it is not re-seeded every call.
- Random bored = new Random();
- // nextInt is exclusive. Should be good with output for array.
- int randomBored = bored.nextInt(array.size());
- // Print your random quote...
- sendMessage(channel, array.get(randomBored));
- }
- if (messageIC.startsWith("!hungry")) {
- double randomosity = Math.random();
- if (randomosity <= 0.5) {
- sendMessage(channel, "Cook. http://www.whatthefuckshouldimakefordinner.com/");
- }
- else if (randomosity > 0.5) {
- sendMessage(channel, "Go out to eat. http://wtfsigte.com/");
- }
- }
- if (messageIC.startsWith("!qotd")) {
- String quotes [] = new String[366];
- quotes[144] = "Always remember that you are absolutely unique. Just like everyone else. -Margaret Mead";
- quotes[145] = "Procrastination is the art of keeping up with yesterday. -Don Marquis";
- quotes[146] = "A day without sunshine is like, you know, night. -Steve Martin";
- quotes[147] = "Drawing on my fine command of the English language, I said nothing. -Robert Benchley";
- quotes[148] = "A word to the wise ain't necessary - it's the stupid ones that need the advice. -Bill Cosby";
- quotes[149] = "I knew I was an unwanted baby when I saw that my bath toys were a toaster and a radio. -Joan Rivers";
- quotes[150] = "I was eating in a Chinese restaurant downtown. There was a dish called Mother and Child Reunion. It's chicken and eggs. And I said, I gotta use that one. -Paul Simon";
- Calendar c = Calendar.getInstance();
- int quote_index = c.get(Calendar.DAY_OF_YEAR);
- String quote_of_the_day = quotes[quote_index];
- sendMessage(channel, quote_of_the_day);
- }
- if (messageIC.startsWith("!record")) {
- message = message.substring(8);
- quoterGo (message, channel);
- }
- if (messageIC.startsWith("!quote")) {
- java.io.FileInputStream fs = null;
- try {
- fs = new java.io.FileInputStream("C:/Users/Quibbles/Documents/ampersand/quotes.txt");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
- }
- BufferedReader br = new BufferedReader(new InputStreamReader(fs));
- ArrayList<String> array = new ArrayList<>();
- String line;
- try {
- while((line = br.readLine()) != null)
- array.add(br.readLine());
- } catch (IOException ex) {
- Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
- }
- // variable so that it is not re-seeded every call.
- Random rand = new Random();
- // nextInt is exclusive. Should be good with output for array.
- int randomIndex = rand.nextInt(array.size());
- // Print your random quote...
- sendMessage(channel, array.get(randomIndex));
- }
- if (messageIC.startsWith("!ampersand")) {
- sendMessage(channel, "!music, !bored, !hungry, !qotd, !record, !quote, !use, !ampersand");
- }
- if (messageIC.equalsIgnoreCase("!use")) {
- sendMessage(channel, "Type !use and a command to get help.");
- }
- if (message.equalsIgnoreCase("!use music")) {
- sendMessage(channel, "Gives music recommendations.");
- }
- if (message.equalsIgnoreCase("!use bored")) {
- sendMessage(channel, "Gives recommendations on what to do if you are bored.");
- }
- if (message.equalsIgnoreCase("!use hungry")) {
- sendMessage(channel, "Gives recommendations on what to cook and places to go eat.");
- }
- if (message.equalsIgnoreCase("!use qotd")) {
- sendMessage(channel, "Gives the quote of the day.");
- }
- if (message.equalsIgnoreCase("!use record")) {
- sendMessage(channel, "Record a quote to be stored for the !quote command.");
- }
- if (message.equalsIgnoreCase("!use quote")) {
- sendMessage(channel, "Sends a random quote based one what has been recorded in the past using !record");
- }
- if (message.equalsIgnoreCase("!use use")) {
- sendMessage(channel, "Really? Gives help using commands.");
- }
- if (message.equalsIgnoreCase("!use ampersand")) {
- sendMessage(channel, "Gives a list of all available commands.");
- }
- // if (messageIC.startsWith("!quote")) {
- // String[]quotes;
- // quotes = new String[5];
- // quotes[0] = "test 1";
- // quotes[1] = "test 2";
- // quotes[2] = "test 3";
- // quotes[3] = "test 4";
- // quotes[4] = "test 5";
- //
- // int num = (int) (Math.random()*5);
- // sendMessage(channel, quotes[num]);
- //}
- }
- // public void onJoin(String channel, String sender, String login, String hostname) {
- // if (!sender.contains("Ampersand")) {
- // sendMessage(channel, "Hi, " + sender + "!");
- // }
- // }
- public void onPrivateMessage(String sender, String login, String hostname, String message) {
- String messageIC = message.trim( ).toLowerCase( );
- if (messageIC.startsWith("!join")) {
- String joiny = message.substring(6);
- joinChannel(joiny);
- }
- if (messageIC.startsWith("!part")) {
- String party = message.substring(6);
- partChannel(party);
- }
- if (messageIC.startsWith("!who")) {
- whoo = message.substring(5);
- }
- if (messageIC.startsWith("!msg")) {
- String msgy = message.substring(5);
- sendAction("chai","<To " + whoo + "> " + msgy);
- sendMessage(whoo,msgy);
- }
- }
- public void quoterGo (String quotey, String channel) {
- try {
- File quoteFile = new File("C:/Users/Quibbles/Documents/ampersand/quotes.txt");
- FileWriter qf = new FileWriter(quoteFile, true);
- qf.write(channel + " " + quotey + "\r\n");
- qf.close();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement