All pastes #613607 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-11 02:21 UTC
rendered paste body
import org.jibble.pircbot.*;import javax.swing.*;import java.util.*;import java.util.Timer;import java.io.*;

public class iKitty extends PircBot {

	private Timer unbanTimer;
	private TimerUnbanTask unbanTask = new TimerUnbanTask();
	String noise;

	public iKitty() {
		this.setName("iKitty");
		this.setLogin("iKitty");
		sendMessage("nickserv", "identify Kitty_Cat");
		this.unbanTask.setBot(this);
	}

	public void onJoin(String channel, String sender, String login, String hostname) {

		// We only want to change ourself.
		if (sender.equalsIgnoreCase(this.getNick())) {


			// Give us the modes we are entitled to. 
			setMode(getNick(), "+T");
			setMode(getNick(), "+p");
			setMode(getNick(), "+B");
		}
	}



	public void onMessage(String channel, String sender, String login, String hostname, String message) {
		// Check for annoying mesages. 
		if (message.startsWith("Playing: [") && message.endsWith("mp3 ]")) {
			if (noise.equals("noisy")) {
				// Make sure that they can't talk on this channel for at least a minute.
				// "Nice" way to give them a hint.
				ban(channel, hostname);
				kick(channel, sender, "The mp3 script isn't welcome.  Turn it off.  Your ban will be removed in 1 minute");
	
				// Tell our handler what to allow again.
				this.unbanTask.setInfo(channel, login);

				// Start their timer.
				this.unbanTimer = new Timer();
				this.unbanTimer.schedule(unbanTask, 60 * 1000, 0);
			}
			else {}
		}
		if (message.equals("!noisy")) {
			if (sender.equals("Kitty_Cat")) {
				noise = "noisy";
			}
		}
		if (message.equals("!quiet")) {
			if (sender.equals("Kitty_Cat")) {
				noise = "quiet";
			}
		}
	}


}

// This is what is fired when the timer is up.
class TimerUnbanTask extends TimerTask {

	// Teh data we need to undo our ban.
	private String channel = "";
	private String hostmask = "";

	// The bot we are doing this for.
	private iKitty bot;

	// Default constructor. Doesn't do anything.
	public TimerUnbanTask() {}

	// Set the info at creation.
	public TimerUnbanTask(String channel, String hostmask) {
		this.setInfo(channel, hostmask);
	}

	// Set the info at creation, including the bot.
	public TimerUnbanTask(String channel, String hostmask, iKitty bot) {
		this.setInfo(channel, hostmask);
		this.setBot(bot);
	}

	// Set the info after the object has been created.
	public void setInfo(String channel, String hostmask) {
		this.channel = channel;
		this.hostmask = hostmask;
	}

	// Register a new bot.
	public void setBot(iKitty bot) {
		this.bot = bot; 
	}

	// Unban the individual.
	public void run() {
		this.bot.unBan(this.channel, this.hostmask); 
	}
}