SHARE
TWEET

Untitled

a guest Sep 16th, 2011 162 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl -w
  2.  
  3. # for Irssi 0.7.98.4 and newer
  4. # Written by Jakub Jankowski <shasta@atn.pl>
  5. # And Adam Lee <adam8157#gmail.com> (since v1.5)
  6.  
  7. # USAGE:
  8. #
  9. # /rsay <text>
  10. #  - same as /say, but outputs a colored text
  11. #
  12. # /rme <text>
  13. #  - same as /me, but outputs a colored text
  14. #
  15. # /rtopic <text>
  16. #  - same as /topic, but outputs a colored text
  17. #
  18. # /rkick <nick> [reason]
  19. #  - kicks nick from the current channel with colored reason
  20.  
  21. # CHANGES:
  22. #
  23. # 2002.01.25: Initial release (v1.0)
  24. # 2002.01.26: /rtopic added (v1.1)
  25. # 2002.01.29: /rsay works with dcc chats now (v1.2)
  26. # 2002.02.02: make_colors() doesn't assign any color to spaces (v1.3)
  27. # 2002.02.23: /rkick added(v1.4)
  28. # 2011.09.16: add utf8 support(v1.5)
  29.  
  30. use strict;
  31. use vars qw($VERSION %IRSSI);
  32. use Encode qw(_utf8_on _utf8_off);
  33.  
  34. $VERSION = "1.5";
  35. %IRSSI = (
  36.         authors     => 'Jakub Jankowski, Adam Lee',
  37.         name        => 'rainbow',
  38.         description => 'Prints colored text.',
  39.         license     => 'GNU GPLv2 or later',
  40. );
  41.  
  42. use Irssi;
  43. use Irssi::Irc;
  44.  
  45. # colors list
  46. #  4 == light red
  47. #  8 == yellow
  48. #  9 == light green
  49. # 11 == light cyan
  50. # 12 == light blue
  51. # 13 == light magenta
  52. my @colors = ('4', '8', '9', '11', '12', '13');
  53.  
  54. # str make_colors($string)
  55. # returns random-colored string
  56. sub make_colors {
  57.         my $oldstr = join '',@_;
  58.         my $newstr = "";
  59.         my $last = 255;
  60.         my $color = 0;
  61.  
  62.         _utf8_on($oldstr);
  63.         @_ = split //,$oldstr;
  64.         foreach(@_) {
  65.                 if ($_ eq ' ') {
  66.                         $newstr .= $_;
  67.                         next;
  68.                 }
  69.                 while (($color = int(rand(scalar(@colors)))) == $last) {};
  70.                 $last = $color;
  71.                 $newstr .= "\003";
  72.                 $newstr .= sprintf("%02d", $colors[$color]);
  73.                 $newstr .= sprintf "$_";
  74.         }
  75.         _utf8_off($oldstr);
  76.  
  77.         return $newstr;
  78. }
  79.  
  80. # void rsay($text, $server, $destination)
  81. # handles /rsay
  82. sub rsay {
  83.         my ($text, $server, $dest) = @_;
  84.  
  85.         if (!$server || !$server->{connected}) {
  86.                 Irssi::print("Not connected to server");
  87.                 return;
  88.         }
  89.  
  90.         return unless $dest;
  91.  
  92.         if ($dest->{type} eq "CHANNEL" || $dest->{type} eq "QUERY") {
  93.                 $dest->command("/msg " . $dest->{name} . " " . make_colors($text));
  94.         }
  95. }
  96.  
  97. # void rme($text, $server, $destination)
  98. # handles /rme
  99. sub rme {
  100.         my ($text, $server, $dest) = @_;
  101.  
  102.         if (!$server || !$server->{connected}) {
  103.                 Irssi::print("Not connected to server");
  104.                 return;
  105.         }
  106.  
  107.         if ($dest && ($dest->{type} eq "CHANNEL" || $dest->{type} eq "QUERY")) {
  108.                 $dest->command("/me " . make_colors($text));
  109.         }
  110. }
  111.  
  112. # void rtopic($text, $server, $destination)
  113. # handles /rtopic
  114. sub rtopic {
  115.         my ($text, $server, $dest) = @_;
  116.  
  117.         if (!$server || !$server->{connected}) {
  118.                 Irssi::print("Not connected to server");
  119.                 return;
  120.         }
  121.  
  122.         if ($dest && $dest->{type} eq "CHANNEL") {
  123.                 $dest->command("/topic " . make_colors($text));
  124.         }
  125. }
  126.  
  127. # void rkick($text, $server, $destination)
  128. # handles /rkick
  129. sub rkick {
  130.         my ($text, $server, $dest) = @_;
  131.  
  132.         if (!$server || !$server->{connected}) {
  133.                 Irssi::print("Not connected to server");
  134.                 return;
  135.         }
  136.  
  137.         if ($dest && $dest->{type} eq "CHANNEL") {
  138.                 my ($nick, $reason) = split(/ +/, $text, 2);
  139.                 return unless $nick;
  140.                 $reason = "Irssi power!" if ($reason =~ /^[\ ]*$/);
  141.                 $dest->command("/kick " . $nick . " " . make_colors($reason));
  142.         }
  143. }
  144.  
  145. Irssi::command_bind("rsay", "rsay");
  146. Irssi::command_bind("rtopic", "rtopic");
  147. Irssi::command_bind("rme", "rme");
  148. Irssi::command_bind("rkick", "rkick");
RAW Paste Data
Top