package Xchat::b0at::KBTemp; use strict; use warnings; # This is the default kb time my $time_default = 80; # in seconds my $NAME = 'KBTemp'; my $VERSION = '0.1.1'; my $COMMAND = "KBTEMP"; my $DESC = "Kickban with timed unban"; my $PREFIX = "\02$NAME\02"; my $USAGE = "Usage: $COMMAND [nick] [-time ] [reason]\n". " (default time: $time_default seconds)"; Xchat::register($NAME, $VERSION, $DESC); Xchat::hook_command( $COMMAND, \&command, {help_text=>$USAGE} ); Xchat::print("\02$NAME $VERSION\02 by b0at (use /$COMMAND)"); sub command { my (undef, $nick, @args) = @{ $_[0] }; if( not $nick ) { # If nick isn't specified, prompt for it. # On cancel, nothing's done. # On okay, GETSTR will send 'kbtemp ! [args]' # '!' can't be in a nick, so it's a good flag Xchat::command( 'GETSTR '. '"" '. # default value '"'.$COMMAND.' !" '. # command to run '"Temporarily kick/ban which nick?"' # prompt ); return Xchat::EAT_ALL; # leave it to GETSTR to continue } elsif( $nick eq '!' ) { # from GETSTR $nick = shift @args; return Xchat::EAT_ALL if( not $nick ); # nothing entered } my $time; if( scalar @args > 0 ) { if( $args[0] =~ /^-time$/i ) { # /kbtemp nick -time foo shift @args; $time = shift @args; } elsif( $args[$#args-1] =~ /^-time$/i ) { $time = pop @args; } } # if -time not give OR if -time WAS given, but no number followed $time = $time_default if( not defined $time); if( $time =~ /\D/ ) { Xchat::print("$PREFIX Argument to -time must be an integer."); return Xchat::EAT_ALL; } # grab user data to get their host and ident my $info = Xchat::user_info($nick); if( not defined $info or ref $info ne 'HASH' or not exists $info->{host}) { Xchat::print("$PREFIX Can't find ".$nick."'s user info!"); return Xchat::EAT_ALL; } my ($user, $host) = split("\@", $info->{host}); my $bantype = Xchat::get_prefs('irc_ban_type'); my $mask; if( $bantype == 0 ) { $mask = "*!*\@*" .($host=~/((?:\.\w+)+)$/)[0]; } elsif( $bantype == 1 ) { $mask = "*!*\@$host"; } elsif( $bantype == 2 ) { $mask = "*!*$user\@*".($host=~/((?:\.\w+)+)$/)[0]; } elsif( $bantype == 3 ) { $mask = "*!*$user\@$host"; } else { # don't think this should happen Xchat::print("Unknown irc_ban_type '$bantype', reverting to type 1 (*!*\@host)."); $mask = "*!*\@$host" } my $reason = join(' ', @args) || ''; # kick first or ban first? # kick first seems to work well without letting the victim see the ban mask # if something goes wrong, you might want to switch the kick and ban command lines Xchat::command("kick $nick $reason"); Xchat::command("ban $mask"); Xchat::command("timer $time unban $mask"); return Xchat::EAT_ALL; } 1; __END__ by: b0at license: public domain Version History: 0.0.1, 14 April 2004 - initial release 0.0.2, 28 April 2004 - added the neglected $reason arg for kick 0.0.3, 15 May 2004 - added '-time' argument - added irc_ban_type check 0.1.0, 06 June 2004 - use strict;, I can't believe I forgot! - added getstr prompt when no nick specified - /^\D$/ wouldn't have worked: I needed /\D/ - added $PREFIX to output for clarity - cleaned it up a bit 011, 11 June 2004 - added package back