Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import org.jibble.pircbot.*;
- public class Gil extends PircBot {
- //properties
- String botName = "";
- Random rand = new Random();
- String channel;
- String sender;
- int inactivity =0;
- int actionDelay = 5;
- //constructor
- public Gil() {
- this.setName("HAL");
- }
- public void onMessage(String channel, String sender, String login, String hostname, String message) {
- inactivity++;
- this.sender = sender;
- this.channel = channel;
- String[] msgArray = message.split("\\s+");
- checkForName(msgArray);
- lmgtfy(msgArray);
- }//end onMessage
- public void checkForName(String[] msgArray) {
- for(int x=0;x<msgArray.length;x++)
- {
- if(msgArray[x].equalsIgnoreCase(this.getName()))
- {
- //if bot name is present
- hello(msgArray);
- leave(msgArray);
- aBot(msgArray);
- break;
- }
- }//end for
- }//end check method
- public boolean matchWords(String[] msgArray, String[] words, String[] response)
- {
- for(int x=0;x<msgArray.length;x++) {
- for(int y=0;y<words.length;y++){
- if(msgArray[x].equalsIgnoreCase(words[y]))
- {
- randReply(response);
- return true;
- }//end if
- }//end nested for
- }//end for
- return false;
- }//end matchWords
- public void hello(String[] msgArray) {
- String words[] = {"hello",
- "hi",
- "hey",
- "o/"};
- String response[] = {"hello",
- "hi",
- "hey",
- "Salutations",
- "o/"};
- matchWords(msgArray, words, response);
- }//end hello
- public void leave(String[] msgArray) {
- String words[] = {"exit",
- "leave",
- "fuck",
- "stop",
- "quit"};
- String response[] = {"fine",
- "sure thing eh",
- "screw you"};
- if(matchWords(msgArray, words, response))
- {
- disconnect();
- }
- }//end leave
- public void aBot(String[] msgArray) {
- String words[] = {"bot"};
- String response[] = {"I ain't no bot",
- "better then a human",
- "beep beep, boop boop"};
- matchWords(msgArray, words, response);
- }//end leave
- public void lmgtfy(String[] msgArray) {
- if(inactivity>actionDelay)
- {
- if(msgArray[msgArray.length-1].endsWith("?"))
- {
- String URL = "http://lmgtfy.com/?q=";
- for(int x=0;x<msgArray.length;x++) {
- if(x == 0)
- URL = URL + msgArray[x];
- else {
- URL = URL + "+" + msgArray[x];
- }
- sendMessage(channel, URL);
- inactivity = 0;
- }//end if
- }//end for
- }//end inactivity if
- }//end lmgtfy
- public void randReply(String[] response) {
- int randomNum = rand.nextInt(response.length);
- sendMessage(channel, response[randomNum]);
- inactivity = 0;
- }//end reply
- }//edn class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement