All pastes #629915 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-07-22 19:35 UTC
rendered paste body
use strict;

## Brief docs

## 1) Place vtvauto.pl in $HOME/.irssi/scripts

## 2) Place vtvshows.txt in $HOME/.irssi/ where each shows is on their own line
## you can use regular expressions

## /script load vtvauto 
## to load the script

## /set dcc_autoget ON
## /set dcc_autoget_masks *!*botty@benzoate.mine.nu
## /set dcc_download_path ~/launchmanydir

## the dcc_download_path is the most important ingredient

## YOU NEED TO HAVE BitTorrent or BitTornado launchmany.py or launchmanycurses.py 
## watching that dcc_download_path

## /vtvreload to reload vtvshows.txt
## /vtvshows to display current list
## /vtvdebug to change debug level, 0 = no debug, 1 = general debug, 2 = verbose debug
## changelog:
## 20050916
## - added support for non "!trigger" triggers
## 20050913
## - fixed nick detection to use hostmask instead
## - detects now secondary announces too if you happened to be on netsplit 
##   when first one occured
## - added /vtvdebug 
## 20050910
## - initial version

use vars qw($VERSION %IRSSI);
$VERSION = "20050916";
%IRSSI = (
    authors     => "",
    contact     => "",
    name        => "",
    description => "vtv autoloader",
    license     => "to kill",
    url         => "",
    changed     => "$VERSION",
);

use Irssi;

our @shows;
our %seentriggers;

my $announcebot = "botty\@crystallum.mine.nu"; ## ident for the announce bot
my $debug       = 0;                           ## enable debug, by putting 1 instead of 0
					       ## verbose debug with 2
sub sig_pubmessage
{
	my ($server, $text, $nick, $address, $target) = @_;

	$text =~ s/\x03\d?\d?(,\d?\d?)?|\x02|\x1f|\x16|\x06|\x07|\x0f//g;
	
	#  begin with |, capture 1: non ")", match: non ")" inside (), capture 2: ! + non ")"
	if ($address=~/$announcebot/ && $text =~m{([^)]+)\s\([^)]+\)\s\(Trigger\s=\s([^)]+)\)}) { 
		my $matchshow = $1;
		my $trigger = $2; 

		Irssi::print("debug: match $matchshow ==> $trigger") if $debug;

		foreach my $show (our @shows) {
			chomp($show);
			if(!length $show) { next; }
			
			Irssi::print("debug: going to match $show") if($debug > 1);
			
			if ($matchshow =~ /$show/i) {
				if(!defined $seentriggers{$trigger}) {
					Irssi::print("Download ($show) - $trigger");
					$server->command ("msg $target $trigger");
					$seentriggers{$trigger} = 1;
					last;
				} else {
					Irssi::print("debug: already triggered '$trigger' for ($show)") if $debug;
				}
			} else {
				Irssi::print("debug: $matchshow !~ /$show/i") if($debug > 1);
			}
		}
	}
}

sub cmd_reload {
	my $file = Irssi::get_irssi_dir."/vtvshows.txt";
	if (-r $file) {
		open(DAT, "< $file");
		our @shows = <DAT>;
		close(DAT);

		Irssi::print("Reloaded shows from vtvshows.txt");
	} else {
		Irssi::print("Couldn't open vtvshows.txt");
	}
}

sub cmd_shows {
	Irssi::print("-- shows --");

	foreach my $show (our @shows) {
		chomp($show);
		Irssi::print($show);
	}

	Irssi::print("-- shows --");
}

sub cmd_debug {
	my ($data, $server, $channel) = @_;
	
	Irssi::print("Setting vtvauto debuglevel to $data");
	$debug = $data;
}

Irssi::signal_add_last("message public", "sig_pubmessage");
Irssi::command_bind('vtvreload','cmd_reload');
Irssi::command_bind('vtvshows','cmd_shows');
Irssi::command_bind('vtvdebug','cmd_debug');

cmd_reload();