<>; Note: THERE IS NO NEED TO EDIT THIS SCRIPT. Description: Nick Recovery v004 Recover the global, first preferrer nick name when it becomes available. This script works across all connected networks. To override the global default nick, use /RECOVERY some_other_nick (eg in a connect command). Usage: No configuation is strictly necessary -- the script checks quits and nick changes for the preferred nick becoming free. If you want nick availablility continually polled (usually this is useful), add your preferred nick to the notify list: /notify some_nick if it isn't already there. q use strict; use warnings; use Xchat qw( :all ); register my $NAME = 'Nick Recovery', my $VERSION = '004', 'Recover preferred nick when it becomes available.'; my $PREFIX = "\cBRecovery\cB\t"; my $COMMAND = 'RECOVERY'; prnt "\02$NAME $VERSION\02 by b0at (use /$COMMAND)"; # set global recovery nickname to first choice in server list my $recover_nick = get_prefs('irc_nick1'); my %hooks = map{$_=>undef} qw(ison quit nick); my $USAGE = join("\n", "Usage: $COMMAND -on [nickname], defaults to first global nick", " $COMMAND -off", " $COMMAND, to show status" ); hook_command($COMMAND, \&recovery_command, {help_text => $USAGE}); recovery_command( [$COMMAND, '-on'] ); # turn it on sub ison_wrangler { # notify list must have preferred nick in it for( split(' ', substr($_[1][3],1)), undef ) { # list of nicks returned last if not defined $_; return EAT_NONE if nickcmp($recover_nick, $_) == 0; # preferred nick is online } recover_nick(); return EAT_NONE; } sub quit_and_nick_wrangler { # check quits and nick changes for the nick my $nick = $_[0][0]; recover_nick() if nickcmp($recover_nick, $nick) == 0; return EAT_NONE; } sub recover_nick { # attempt to recover nick if appropriate return if get_info('nick') eq $recover_nick; prnt [$PREFIX,' Recovering "',$recover_nick,'"...']); command(join('','nick ',$recover_nick)); } sub recovery_command { # handle user input my $switch = lc $_[0][1]; my $new_nick = $_[0][2]; if( not $switch ) { prnt [$PREFIX, " Status: \02",($hooks{ison}?'on':'off'),"\02", ', Nick: "',$recover_nick,'".' ]; } elsif( $switch eq '-off' ) { for( keys %hooks ) { unhook($hooks{$_}); undef($hooks{$_}); } prnt "$PREFIX Turned off."; } elsif( $switch eq '-on' ) { if( $hooks{ison} ) { # if already on if( $new_nick and $new_nick ne $recover_nick) { # set a new nick prnt [$PREFIX, ' No longer watching for "',$recover_nick,'", ', 'now watching for "',$new_nick,'".']; $recover_nick = $new_nick; } else { # nothing to set prnt [$PREFIX, ' Already watching for "',$recover_nick,'".']; } } else { # not hooked yet, hook it $recover_nick = $new_nick if $new_nick; if( $recover_nick ) { $hooks{ison} = hook_server('303', \&ison_wrangler); $hooks{quit} = hook_print('Quit', \&quit_and_nick_wrangler); $hooks{nick} = hook_print('Change Nick', \&quit_and_nick_wrangler); prnt [$PREFIX, ' Now watching for "',$recover_nick,'".']; } else { prnt $USAGE } # no nick specified to watch } } return EAT_ALL; # exclusive use of the command } __END__ by: b0at license: public domain recovers the first global nick preference