#!/usr/bin/perl # # change nick on special events (like timeout, part, etc.) # by x29a @ 2011 # install: simply place in ~/.xchat2/ and ensure perl is installed # doc: http://xchat.org/docs/xchat2-perl.html # toggle for printing debug messages $debug = 1; # seconds to wait at least between nickchanges $changeDelay = 30; #================== End of user config=========== $version = "1.0"; @lastChange = 0; sub mylog { if ($debug) { Xchat::print "nickChanger: $_" foreach(@_); } } sub myunload { #called when the plugin is unloaded Xchat::print "nickChanger unloaded!"; return Xchat::EAT_NONE; } Xchat::register( "nickChanger", "$fl_frversion", "nickChanger", \&myunload ); Xchat::print "Resistance is futile. Your nick will be changed!"; mylog "Debug on!"; # event when someone joins IRC::add_message_handler("JOIN", "changeNick"); # event when someone quits (or timeouts, like the own nick) IRC::add_message_handler("QUIT", "changeNick"); # event when someone leaves a channel IRC::add_message_handler("PART", "changeNick"); sub changeNick { mylog "checking nick status"; $currentNick=Xchat::get_info("nick"); $wantedNick=Xchat::get_prefs("irc_nick1"); if($currentNick ne $wantedNick) { mylog "nick should be changed"; $networkId = Xchat::get_info("network"); if( !defined $lastChange[$networkId] ) { $lastChange[$networkId] = 0; } $now = time; $last = $lastChange[$networkId]+$changeDelay; mylog "now: ${now}"; mylog "last: ${last}"; mylog "network: ${networkId}"; if($now >= $last) { mylog "it's time to change the nick"; Xchat::command("NICK ${wantedNick}"); # check if nickchange was successfull $currentNick=Xchat::get_info("nick"); $wantedNick=Xchat::get_prefs("irc_nick1"); if($currentNick == $wantedNick) { $lastChange[$networkId] = time; mylog "nickchange succesful"; } else { # nickchange seems to have failed, lets try again in at least 5s $lastChange[$networkId] = time-$changeDelay+5; mylog "nickchange failed"; } } else { mylog "nickchange too recently"; } } return Xchat::EAT_NONE; }