# # rainbow.pl # # Usage: # /rainbow text to display in rainbow colors # # widyono 20050427 # # put in $HOME/.xchat2 (tested under xchat 2.4.3, need at least 2.0.8) # autoloaded # # $Id: rainbow.pl,v 1.3 2005/04/28 02:48:29 widyono Exp widyono $ # # Manually in IRC (using Xchat2): # # %B bold toggle # %C## set colour to ## # %U underline toggle # %O reset all # %R reverse toggle # $xchatvers = 1; ($major, $minor, $revision) = split('\.', IRC::get_info(0)); # 0 = version if ($major eq 2) { if ($minor eq 0 and $revision ge 8) { $xchatvers = 2; } elsif ($minor gt 0) { $xchatvers = 2; } } #IRC::print("version \"$major.$minor.$revision\": using version $xchatvers"); # debug $rainbowname = "rainbow"; $rainbowvers = "1.1"; if ($xchatvers eq 1) { IRC::register($rainbowname, $rainbowvers, "", ""); $do_sethandler = \&IRC::add_command_handler; $do_output = \&IRC::command; } elsif ($xchatvers eq 2) { Xchat::register($rainbowname, $rainbowvers); $do_sethandler = \&Xchat::hook_command; $do_output = \&Xchat::command; } &$do_sethandler($rainbowname, "rainbow_func"); sub rainbow_func { $text = ""; @colors = ("05", "04", "07", "08", "09", "03", "11", "10", "12", "02", "06", "13", "15", "14"); $colorlen = scalar @colors; $colornum = int(rand($colorlen-1)); if ($xchatvers eq 1) { $line = join(' ', @_); $command = "/say"; } else { $line = $_[1][1]; $command = "say"; } foreach $letter (split('', $line)) { if ($letter =~ /\s/) { # \w for words instead of letters $text .= "$letter"; } else { $text .= "\cC$colors[$colornum++]$letter"; } if ($colornum > ($colorlen - 1)) { $colornum = 0; } } &$do_output("$command $text"); return 1; }