Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package irc.bot;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Timer;
- import java.util.TimerTask;
- import org.jibble.pircbot.IrcException;
- import org.jibble.pircbot.PircBot;
- import org.jibble.pircbot.User;
- import java.util.regex.*;
- /**
- *
- * @author s095815
- */
- public class IrcBot extends PircBot {
- public final static String SERVER = "irc.gamesurge.net";
- public final static String CHANNEL = "#turtleexpress";
- public final static String CHANNEL_AND_PASS = CHANNEL + " bettina";
- private final static Pattern numberPattern = Pattern.compile("^\\d$");
- private HashMap<String,Integer> countdowners;
- public IrcBot(){
- this.setName("PerBot2");
- countdowners = new HashMap<String, Integer>(37);
- }
- @Override
- protected void onMessage(String channel, String sender, String login, String hostname, String message){
- if(channel.trim().equalsIgnoreCase(CHANNEL)){
- System.err.println("channel to message");
- if(message.startsWith(".insultall")){
- System.err.println("somebody wants insults! :O");
- User[] users = this.getUsers(CHANNEL);
- for(User user : users){
- this.sendMessage(user.getNick(), insult(user));
- }
- }
- else if(message.startsWith(".hiall")){
- User[] users = this.getUsers(CHANNEL);
- String msg = "hello ";
- for(User user : users){
- msg += user.getNick() + " ";
- }
- this.sendMessage(CHANNEL, msg);
- } else if(numberPattern.matcher(message).matches()){
- int newCount = Integer.parseInt(message);
- Integer counter = countdowners.get(sender);
- if(counter == null){
- if(newCount == 3){
- countdowners.put(sender, newCount);
- }
- } else if(counter-1 != newCount){
- if(counter == 3){
- countdowners.put(sender, newCount);
- } else {
- countdowners.remove(sender);
- }
- } else {//counter-1 = newCount
- if(newCount == 0){
- countdowners.remove(sender);
- this.sendMessage(CHANNEL, "THIS IS THE FINAL COUNTDOWN, TUDUDUUUDU");
- Timer t = new Timer();
- t.schedule(new TimerTask() {
- @Override
- public void run() {
- sendMessage(CHANNEL, "TUDU-DU-DU-DUUUU");
- }
- }, 1000);
- } else {
- System.out.println("counted down");
- countdowners.put(sender, newCount);
- }
- }
- } else if(sender.toLowerCase().contains("xupwup") &&
- (message.toLowerCase().contains("linux") ||
- message.toLowerCase().contains("fedora"))){
- this.sendMessage(channel, "hur dur linux dur");
- } else if(message.startsWith("perbot solve")){
- this.sendMessage(channel, "recent scientific studies have shown that the answer to your query equals "+(int)(Math.random()*500));
- } else if(message.startsWith(".bpt")){
- String[] choices = message.split("\\s+");
- if(choices.length>0)
- this.sendMessage(channel, "The answer is, undoubtedly, according to Per's Theorem, equal to "+choices[1+(int)(Math.random()*(choices.length-1))]);
- } else if(message.startsWith(".insult")){
- String[] names = message.split("\\s+");
- if(names.length > 0)
- this.sendMessage(CHANNEL, insult(names[1]));
- }
- else if(contain(message,new String[][]{{this.getName(),"<3"},{this.getName(),"love"}})){
- this.sendMessage(channel, "i love you too "+sender);
- }
- }
- }
- private static boolean contain(String s, String[][] words){
- for(String[] w : words){
- boolean temp = true;
- for(String a : w){
- temp &= s.toLowerCase().contains(a.toLowerCase());
- }
- if(temp) return true;
- }
- return false;
- }
- private final static String[] INSULTS = {
- "Fuck you, .",
- "., you are an idiotic Whipper-Snapper",
- "., you are a disease ridden Pipsqueek.",
- "., you are a decomposing Old-Buzzard",
- "., you are a wastrel Xenophobe",
- "., you are a degenerate Pillow-Biter",
- "., you are a war-mongering Dough-Boy",
- "., you are a decomposing Boozer",
- "., you are a rabid Hack",
- "., you are a mindless Bastard",
- "., you are a necropheliac Roody-Poo",
- };
- private String insult(User user){
- return insult(user.getNick());
- }
- private String insult(String nick){
- String insult = INSULTS[(int)(Math.random()*INSULTS.length)];
- return insult.replace(".",nick);
- }
- @Override
- protected void onKick(String channel, String kickerNick, String kickerLogin, String kickerHostname, String recipientNick, String reason){
- int closeBrack = reason.indexOf(')');
- String name;
- if(closeBrack > 0){
- name = reason.substring(1, closeBrack);
- } else {
- name = kickerNick;
- }
- System.out.println(reason);
- this.joinChannel(CHANNEL_AND_PASS);
- this.sendMessage(CHANNEL_AND_PASS, "fuck you "+name);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException, IrcException {
- // Now start our bot up.
- IrcBot bot = new IrcBot();
- // Enable debugging output.
- bot.setVerbose(true);
- // Connect to the IRC server.
- bot.connect(SERVER);
- // Join the #pircbot channel.
- bot.joinChannel(CHANNEL_AND_PASS);
- }
- }
Add Comment
Please, Sign In to add comment