Guest User

Untitled

a guest
Jul 12th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.33 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package irc.bot;
  6.  
  7. import java.io.IOException;
  8. import java.util.HashMap;
  9. import java.util.Timer;
  10. import java.util.TimerTask;
  11. import org.jibble.pircbot.IrcException;
  12. import org.jibble.pircbot.PircBot;
  13. import org.jibble.pircbot.User;
  14. import java.util.regex.*;
  15.  
  16. /**
  17.  *
  18.  * @author s095815
  19.  */
  20. public class IrcBot extends PircBot {
  21.    
  22.     public final static String SERVER = "irc.gamesurge.net";
  23.     public final static String CHANNEL = "#turtleexpress";
  24.     public final static String CHANNEL_AND_PASS = CHANNEL + " bettina";
  25.    
  26.     private final static Pattern numberPattern = Pattern.compile("^\\d$");
  27.    
  28.     private HashMap<String,Integer> countdowners;
  29.    
  30.     public IrcBot(){
  31.         this.setName("PerBot2");
  32.         countdowners = new HashMap<String, Integer>(37);
  33.     }
  34.    
  35.     @Override
  36.     protected void onMessage(String channel, String sender, String login, String hostname, String message){
  37.         if(channel.trim().equalsIgnoreCase(CHANNEL)){
  38.             System.err.println("channel to message");
  39.             if(message.startsWith(".insultall")){
  40.                 System.err.println("somebody wants insults! :O");
  41.                 User[] users = this.getUsers(CHANNEL);
  42.                 for(User user : users){
  43.                     this.sendMessage(user.getNick(), insult(user));
  44.                 }
  45.             }
  46.             else if(message.startsWith(".hiall")){
  47.                 User[] users = this.getUsers(CHANNEL);
  48.                 String msg = "hello ";
  49.                 for(User user : users){
  50.                     msg += user.getNick() + " ";
  51.                 }
  52.                 this.sendMessage(CHANNEL, msg);
  53.             } else if(numberPattern.matcher(message).matches()){
  54.                 int newCount = Integer.parseInt(message);
  55.                 Integer counter = countdowners.get(sender);
  56.                 if(counter == null){
  57.                     if(newCount == 3){
  58.                         countdowners.put(sender, newCount);
  59.                     }
  60.                 } else if(counter-1 != newCount){
  61.                     if(counter == 3){
  62.                         countdowners.put(sender, newCount);
  63.                     } else {
  64.                         countdowners.remove(sender);
  65.                     }
  66.                 } else {//counter-1 = newCount
  67.                     if(newCount == 0){
  68.                         countdowners.remove(sender);
  69.                         this.sendMessage(CHANNEL, "THIS IS THE FINAL COUNTDOWN, TUDUDUUUDU");
  70.                         Timer t = new Timer();
  71.                         t.schedule(new TimerTask() {
  72.  
  73.                             @Override
  74.                             public void run() {
  75.                                 sendMessage(CHANNEL, "TUDU-DU-DU-DUUUU");
  76.                             }
  77.                         }, 1000);
  78.                     } else {
  79.                         System.out.println("counted down");
  80.                         countdowners.put(sender, newCount);
  81.                     }
  82.                 }
  83.             } else if(sender.toLowerCase().contains("xupwup") &&
  84.                     (message.toLowerCase().contains("linux") ||
  85.                     message.toLowerCase().contains("fedora"))){
  86.                 this.sendMessage(channel, "hur dur linux dur");
  87.             } else if(message.startsWith("perbot solve")){
  88.                 this.sendMessage(channel, "recent scientific studies have shown that the answer to your query equals "+(int)(Math.random()*500));
  89.             } else if(message.startsWith(".bpt")){
  90.                 String[] choices = message.split("\\s+");
  91.                 if(choices.length>0)
  92.                 this.sendMessage(channel, "The answer is, undoubtedly, according to Per's Theorem, equal to "+choices[1+(int)(Math.random()*(choices.length-1))]);
  93.             } else if(message.startsWith(".insult")){
  94.                 String[] names = message.split("\\s+");
  95.                 if(names.length > 0)
  96.                     this.sendMessage(CHANNEL, insult(names[1]));
  97.             }
  98.             else if(contain(message,new String[][]{{this.getName(),"<3"},{this.getName(),"love"}})){
  99.                 this.sendMessage(channel, "i love you too "+sender);
  100.             }
  101.         }
  102.     }
  103.  
  104.     private static boolean contain(String s, String[][] words){
  105.         for(String[] w : words){
  106.             boolean temp = true;
  107.             for(String a : w){
  108.                 temp &= s.toLowerCase().contains(a.toLowerCase());
  109.             }
  110.             if(temp) return true;
  111.         }
  112.         return false;
  113.     }
  114.    
  115.     private final static String[] INSULTS = {
  116.         "Fuck you, .",
  117.         "., you are an idiotic Whipper-Snapper",
  118.         "., you are a disease ridden Pipsqueek.",
  119.         "., you are a decomposing Old-Buzzard",
  120.         "., you are a wastrel Xenophobe",
  121.         "., you are a degenerate Pillow-Biter",
  122.         "., you are a war-mongering Dough-Boy",
  123.         "., you are a decomposing Boozer",
  124.         "., you are a rabid Hack",
  125.         "., you are a mindless Bastard",
  126.         "., you are a necropheliac Roody-Poo",
  127.     };
  128.    
  129.     private String insult(User user){
  130.         return insult(user.getNick());
  131.     }
  132.    
  133.     private String insult(String nick){
  134.         String insult = INSULTS[(int)(Math.random()*INSULTS.length)];
  135.         return insult.replace(".",nick);
  136.     }
  137.    
  138.     @Override
  139.     protected void onKick(String channel, String kickerNick, String kickerLogin, String kickerHostname, String recipientNick, String reason){
  140.         int closeBrack = reason.indexOf(')');
  141.         String name;
  142.         if(closeBrack > 0){
  143.             name = reason.substring(1, closeBrack);
  144.         } else {
  145.             name = kickerNick;
  146.         }
  147.         System.out.println(reason);
  148.         this.joinChannel(CHANNEL_AND_PASS);
  149.         this.sendMessage(CHANNEL_AND_PASS, "fuck you "+name);
  150.     }
  151.  
  152.     /**
  153.      * @param args the command line arguments
  154.      */
  155.     public static void main(String[] args) throws IOException, IrcException {
  156.         // Now start our bot up.
  157.         IrcBot bot = new IrcBot();
  158.         // Enable debugging output.
  159.         bot.setVerbose(true);
  160.        
  161.         // Connect to the IRC server.
  162.         bot.connect(SERVER);
  163.  
  164.         // Join the #pircbot channel.
  165.         bot.joinChannel(CHANNEL_AND_PASS);
  166.     }
  167. }
Add Comment
Please, Sign In to add comment