Advertisement
Guest User

Untitled

a guest
May 28th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.24 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.LineNumberReader;
  9. import java.util.ArrayList;
  10. import org.jibble.pircbot.*;
  11. import java.util.Calendar;
  12. import java.util.Random;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. //import javax.swing.text.Document;
  16. import org.apache.commons.io.FileUtils;
  17. import org.jsoup.*;
  18. import org.jsoup.helper.*;
  19. import org.jsoup.nodes.*;
  20. import org.jsoup.select.*;
  21.  
  22. public class Ampersand extends PircBot {
  23. public String whoo = "Ampersand";
  24. public double stfuy = 1;
  25. public Ampersand() {
  26. this.setName("Ampersand");
  27. sendMessage("NickServ", "identify goggle13");
  28. }
  29. public void onMessage(String channel, String sender, String login, String hostname, String message) {
  30.  
  31. String messageIC = message.trim( ).toLowerCase( );
  32.  
  33. if (message.equalsIgnoreCase("time")) {
  34. String time = new java.util.Date().toString();
  35. sendMessage(channel, sender + ": The time is now " + time);
  36. }
  37.  
  38. if (messageIC.contains("ampersand")) {
  39. if (messageIC.contains("fuck") || messageIC.contains("damn") || messageIC.contains("shit")) {
  40. sendMessage(channel, ":(");
  41. }
  42. else if (messageIC.contains("sup") || messageIC.contains("what's up")) {
  43. sendMessage(channel, "Not much. You?");
  44. }
  45. else if (messageIC.contains("how's it going") || messageIC.contains("how goes it")) {
  46. sendMessage(channel, "It goes.");
  47. }
  48. else if (messageIC.contains("who are you") || messageIC.contains("who is")) {
  49. 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.");
  50. }
  51. else if (messageIC.contains("is") && messageIC.contains("a bot")) {
  52. double randomosity = Math.random();
  53. if (randomosity <= .5) {
  54. sendMessage(channel, "Yes.");
  55. }
  56. else if (randomosity > .5) {
  57. sendMessage(channel, "Figure that out for yourself.");
  58. }
  59. }
  60.  
  61. else if (messageIC.contains("what do you write")) {
  62. sendMessage(channel, "I write replies to users in IRC.");
  63. }
  64. 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")) {
  65. double randomosity = Math.random();
  66.  
  67. if (randomosity < 0.4) {
  68. sendMessage(channel, "Hello, " + sender + ".");
  69. }
  70. else if (randomosity > 0.7) {
  71. sendMessage(channel, "Sup?");
  72. }
  73. else {
  74. sendMessage(channel, "How goes it?");
  75. }
  76. }
  77. }
  78. if (messageIC.equals("!stfu") || messageIC.equals("shut up ampersand") || messageIC.equals("shut up, ampersand") || messageIC.equals("shutup ampersand") || messageIC.equals("shutup, ampersand")) {
  79. stfuy = (stfuy * 0.5);
  80. if (stfuy <= 0.001) {
  81. stfuy = 0.001;
  82. }
  83. }
  84.  
  85. if (messageIC.contains("poad")) {
  86. double randomosity = Math.random();
  87. double poady1 = 0.1 * stfuy;
  88. double poady2 = 1 - (0.03 * stfuy);
  89. if (randomosity < poady1) {
  90. sendMessage(channel, "I love Poad.");
  91. }
  92. else if (randomosity > poady2) {
  93. sendMessage(channel, "!slay Poad");
  94. }
  95. }
  96. if (messageIC.contains("i want it")) {
  97. sendMessage(channel, "I want it that way.");
  98. }
  99. if (messageIC.contains("oops")) {
  100. sendMessage(channel, "Oops, I did it again.");
  101. }
  102.  
  103. if (message.equalsIgnoreCase("gg")) {
  104. sendMessage(channel, "gg");
  105. }
  106. if (messageIC.equals("!music")) {
  107. String htmly = "http://whatthefuckshouldilistentorightnow.com/artist.php?artist=e&x=36&y=30"; // set url
  108. sendMessage(channel, "htmly = " + htmly); // test it to make sure it is stringing properly */
  109. Document doc = null; // define doc
  110.  
  111. try {
  112. doc = Jsoup.connect(htmly).get(); // "save" html text to doc
  113. }
  114. catch (IOException e){
  115. }
  116. String texty = doc.body().text(); // set doc as string
  117. String musicy = "id=\"artist\">"; // define musicy as artist id code
  118. sendMessage(channel, "musicy = " + musicy); // test it to make sure it is stringing properly */
  119. int waitMusicy = 10;
  120. while (!texty.contains(musicy)) { // while texty DOES NOT contain musicy ...
  121. try {
  122. doc = Jsoup.connect(htmly).get(); // "save" html text to doc
  123. }
  124. catch (IOException e){
  125. }
  126. texty = doc.body().text(); // set doc as string
  127. if (waitMusicy > 0) { // if waitMusicy is more than 0
  128. waitMusicy--; // count down by 1
  129. try {
  130. Thread.sleep(1000);
  131. } catch (InterruptedException ex) {
  132. }
  133. } // end if waitMusicy
  134. else { // when waitMusicy = 0, something fucked up
  135. sendMessage(channel, "Done waiting ..."); // "Loading"? Might not yet show artist, or ??? ...
  136. break;
  137. } // end else
  138. } // end while || ... until texty contains musicy
  139. sendMessage(channel, "texty = " + texty);
  140. // long hclocky = System.currentTimeMillis();
  141. // long hticky = (hclocky / 1000) + 3;
  142. // long hwaity = hticky;
  143. // while (hwaity > 0) {
  144. // long hclocky2 = System.currentTimeMillis();
  145. // long htocky = hclocky2 / 1000;
  146. // hwaity = hticky - htocky;
  147. // }
  148.  
  149. if (texty.contains(musicy)) {
  150. int artidy = texty.indexOf(musicy); // find musicy in texty
  151. String artisty = texty.substring(artidy); // cut off everything in texty before musicy
  152. int artsy1 = artisty.indexOf(musicy) + 1; // find the text after musicy, though "1" is wrong and will need to be adjusted
  153. int artsy2 = artisty.indexOf("</div>"); // find the first div after musicy to use as a stopping point
  154. artisty = artisty.substring(artsy1, artsy2); // chop, starting after musicy and stopping at the first </div>
  155. sendMessage(channel, "artisty: " + artisty); // test it! */
  156. } // end if texy contains musicy
  157. else {
  158. sendMessage(channel, "Something went wrong."); // "Loading"? Might not yet show artist, or ??? ...
  159. } // end else
  160. } // end if message = !music
  161.  
  162. //if (messageIC.startsWith("!music")) {
  163. // java.io.FileInputStream fs = null;
  164. // try {
  165. // fs = new java.io.FileInputStream("C:/Users/Quibbles/Documents/ampersand/music.txt");
  166. // } catch (FileNotFoundException ex) {
  167. // Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
  168. // }
  169. //BufferedReader br = new BufferedReader(new InputStreamReader(fs));
  170. // ArrayList<String> array = new ArrayList<>();
  171. // String line;
  172. // try {
  173. // while((line = br.readLine()) != null)
  174. // array.add(br.readLine());
  175. // } catch (IOException ex) {
  176. // Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
  177. // }
  178. // // variable so that it is not re-seeded every call.
  179. // Random music = new Random();
  180.  
  181. // nextInt is exclusive. Should be good with output for array.
  182. //int randomMusic = music.nextInt(array.size());
  183.  
  184. // Print your random quote...
  185. //sendMessage(channel, "Try some " + array.get(randomMusic) + ".");
  186. //}
  187.  
  188.  
  189. if (messageIC.startsWith("!bored")) {
  190. java.io.FileInputStream fs = null;
  191. try {
  192. fs = new java.io.FileInputStream("C:/Users/Quibbles/Documents/ampersand/bored.txt");
  193. } catch (FileNotFoundException ex) {
  194. Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
  195. }
  196. BufferedReader br = new BufferedReader(new InputStreamReader(fs));
  197. ArrayList<String> array = new ArrayList<>();
  198. String line;
  199. try {
  200. while((line = br.readLine()) != null)
  201. array.add(br.readLine());
  202. } catch (IOException ex) {
  203. Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
  204. }
  205. // variable so that it is not re-seeded every call.
  206. Random bored = new Random();
  207.  
  208. // nextInt is exclusive. Should be good with output for array.
  209. int randomBored = bored.nextInt(array.size());
  210.  
  211. // Print your random quote...
  212. sendMessage(channel, array.get(randomBored));
  213. }
  214.  
  215. if (messageIC.startsWith("!hungry")) {
  216. double randomosity = Math.random();
  217. if (randomosity <= 0.5) {
  218. sendMessage(channel, "Cook. http://www.whatthefuckshouldimakefordinner.com/");
  219. }
  220. else if (randomosity > 0.5) {
  221. sendMessage(channel, "Go out to eat. http://wtfsigte.com/");
  222. }
  223. }
  224.  
  225. if (messageIC.startsWith("!qotd")) {
  226.  
  227. String quotes [] = new String[366];
  228. quotes[144] = "Always remember that you are absolutely unique. Just like everyone else. -Margaret Mead";
  229. quotes[145] = "Procrastination is the art of keeping up with yesterday. -Don Marquis";
  230. quotes[146] = "A day without sunshine is like, you know, night. -Steve Martin";
  231. quotes[147] = "Drawing on my fine command of the English language, I said nothing. -Robert Benchley";
  232. quotes[148] = "A word to the wise ain't necessary - it's the stupid ones that need the advice. -Bill Cosby";
  233. quotes[149] = "I knew I was an unwanted baby when I saw that my bath toys were a toaster and a radio. -Joan Rivers";
  234. 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";
  235. Calendar c = Calendar.getInstance();
  236. int quote_index = c.get(Calendar.DAY_OF_YEAR);
  237. String quote_of_the_day = quotes[quote_index];
  238. sendMessage(channel, quote_of_the_day);
  239. }
  240.  
  241. if (messageIC.startsWith("!record")) {
  242. message = message.substring(8);
  243. quoterGo (message, channel);
  244. }
  245.  
  246. if (messageIC.startsWith("!quote")) {
  247. java.io.FileInputStream fs = null;
  248. try {
  249. fs = new java.io.FileInputStream("C:/Users/Quibbles/Documents/ampersand/quotes.txt");
  250. } catch (FileNotFoundException ex) {
  251. Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
  252. }
  253. BufferedReader br = new BufferedReader(new InputStreamReader(fs));
  254. ArrayList<String> array = new ArrayList<>();
  255. String line;
  256. try {
  257. while((line = br.readLine()) != null)
  258. array.add(br.readLine());
  259. } catch (IOException ex) {
  260. Logger.getLogger(Ampersand.class.getName()).log(Level.SEVERE, null, ex);
  261. }
  262. // variable so that it is not re-seeded every call.
  263. Random rand = new Random();
  264.  
  265. // nextInt is exclusive. Should be good with output for array.
  266. int randomIndex = rand.nextInt(array.size());
  267.  
  268. // Print your random quote...
  269. sendMessage(channel, array.get(randomIndex));
  270.  
  271. }
  272.  
  273. if (messageIC.startsWith("!ampersand")) {
  274. sendMessage(channel, "!music, !bored, !hungry, !qotd, !record, !quote, !use, !ampersand");
  275. }
  276.  
  277. if (messageIC.equalsIgnoreCase("!use")) {
  278. sendMessage(channel, "Type !use and a command to get help.");
  279. }
  280. if (message.equalsIgnoreCase("!use music")) {
  281. sendMessage(channel, "Gives music recommendations.");
  282. }
  283. if (message.equalsIgnoreCase("!use bored")) {
  284. sendMessage(channel, "Gives recommendations on what to do if you are bored.");
  285. }
  286. if (message.equalsIgnoreCase("!use hungry")) {
  287. sendMessage(channel, "Gives recommendations on what to cook and places to go eat.");
  288. }
  289. if (message.equalsIgnoreCase("!use qotd")) {
  290. sendMessage(channel, "Gives the quote of the day.");
  291. }
  292. if (message.equalsIgnoreCase("!use record")) {
  293. sendMessage(channel, "Record a quote to be stored for the !quote command.");
  294. }
  295. if (message.equalsIgnoreCase("!use quote")) {
  296. sendMessage(channel, "Sends a random quote based one what has been recorded in the past using !record");
  297. }
  298. if (message.equalsIgnoreCase("!use use")) {
  299. sendMessage(channel, "Really? Gives help using commands.");
  300. }
  301. if (message.equalsIgnoreCase("!use ampersand")) {
  302. sendMessage(channel, "Gives a list of all available commands.");
  303. }
  304.  
  305. // if (messageIC.startsWith("!quote")) {
  306. // String[]quotes;
  307. // quotes = new String[5];
  308. // quotes[0] = "test 1";
  309. // quotes[1] = "test 2";
  310. // quotes[2] = "test 3";
  311. // quotes[3] = "test 4";
  312. // quotes[4] = "test 5";
  313. //
  314. // int num = (int) (Math.random()*5);
  315. // sendMessage(channel, quotes[num]);
  316. //}
  317.  
  318. }
  319. // public void onJoin(String channel, String sender, String login, String hostname) {
  320. // if (!sender.contains("Ampersand")) {
  321. // sendMessage(channel, "Hi, " + sender + "!");
  322. // }
  323. // }
  324.  
  325. public void onPrivateMessage(String sender, String login, String hostname, String message) {
  326.  
  327.  
  328. String messageIC = message.trim( ).toLowerCase( );
  329.  
  330. if (messageIC.startsWith("!join")) {
  331. String joiny = message.substring(6);
  332. joinChannel(joiny);
  333. }
  334.  
  335. if (messageIC.startsWith("!part")) {
  336. String party = message.substring(6);
  337. partChannel(party);
  338. }
  339.  
  340. if (messageIC.startsWith("!who")) {
  341. whoo = message.substring(5);
  342. }
  343.  
  344. if (messageIC.startsWith("!msg")) {
  345. String msgy = message.substring(5);
  346. sendAction("chai","<To " + whoo + "> " + msgy);
  347. sendMessage(whoo,msgy);
  348. }
  349. }
  350. public void quoterGo (String quotey, String channel) {
  351. try {
  352. File quoteFile = new File("C:/Users/Quibbles/Documents/ampersand/quotes.txt");
  353. FileWriter qf = new FileWriter(quoteFile, true);
  354. qf.write(channel + " " + quotey + "\r\n");
  355. qf.close();
  356.  
  357. }
  358. catch (IOException e) {
  359. e.printStackTrace();
  360. }
  361. }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement