Advertisement
jared314

Untitled

Feb 13th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. import org.jibble.pircbot.*;
  4.  
  5. public class Gil extends PircBot {
  6.  
  7. //properties
  8. String botName = "";
  9. Random rand = new Random();
  10. String channel;
  11. String sender;
  12. int inactivity =0;
  13. int actionDelay = 5;
  14.  
  15. //constructor
  16. public Gil() {
  17. this.setName("HAL");
  18. }
  19.  
  20. public void onMessage(String channel, String sender, String login, String hostname, String message) {
  21. inactivity++;
  22. this.sender = sender;
  23. this.channel = channel;
  24. String[] msgArray = message.split("\\s+");
  25.  
  26. checkForName(msgArray);
  27. lmgtfy(msgArray);
  28. }//end onMessage
  29.  
  30. public void checkForName(String[] msgArray) {
  31.  
  32. for(int x=0;x<msgArray.length;x++)
  33. {
  34. if(msgArray[x].equalsIgnoreCase(this.getName()))
  35. {
  36. //if bot name is present
  37. hello(msgArray);
  38. leave(msgArray);
  39. aBot(msgArray);
  40. break;
  41. }
  42. }//end for
  43. }//end check method
  44.  
  45. public boolean matchWords(String[] msgArray, String[] words, String[] response)
  46. {
  47. for(int x=0;x<msgArray.length;x++) {
  48. for(int y=0;y<words.length;y++){
  49. if(msgArray[x].equalsIgnoreCase(words[y]))
  50. {
  51. randReply(response);
  52. return true;
  53. }//end if
  54. }//end nested for
  55. }//end for
  56. return false;
  57. }//end matchWords
  58.  
  59.  
  60.  
  61.  
  62. public void hello(String[] msgArray) {
  63. String words[] = {"hello",
  64. "hi",
  65. "hey",
  66. "o/"};
  67. String response[] = {"hello",
  68. "hi",
  69. "hey",
  70. "Salutations",
  71. "o/"};
  72. matchWords(msgArray, words, response);
  73. }//end hello
  74.  
  75. public void leave(String[] msgArray) {
  76. String words[] = {"exit",
  77. "leave",
  78. "fuck",
  79. "stop",
  80. "quit"};
  81. String response[] = {"fine",
  82. "sure thing eh",
  83. "screw you"};
  84. if(matchWords(msgArray, words, response))
  85. {
  86. disconnect();
  87. }
  88. }//end leave
  89.  
  90. public void aBot(String[] msgArray) {
  91. String words[] = {"bot"};
  92. String response[] = {"I ain't no bot",
  93. "better then a human",
  94. "beep beep, boop boop"};
  95. matchWords(msgArray, words, response);
  96. }//end leave
  97.  
  98. public void lmgtfy(String[] msgArray) {
  99.  
  100. if(inactivity>actionDelay)
  101. {
  102. if(msgArray[msgArray.length-1].endsWith("?"))
  103. {
  104. String URL = "http://lmgtfy.com/?q=";
  105.  
  106. for(int x=0;x<msgArray.length;x++) {
  107. if(x == 0)
  108. URL = URL + msgArray[x];
  109. else {
  110. URL = URL + "+" + msgArray[x];
  111. }
  112.  
  113. sendMessage(channel, URL);
  114. inactivity = 0;
  115. }//end if
  116. }//end for
  117. }//end inactivity if
  118. }//end lmgtfy
  119.  
  120. public void randReply(String[] response) {
  121. int randomNum = rand.nextInt(response.length);
  122. sendMessage(channel, response[randomNum]);
  123. inactivity = 0;
  124. }//end reply
  125.  
  126. }//edn class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement