1# rot13.pl 2# Mariusz "Craig" Cie�la <craig at fish.mac.edu.pl> 3# ROT13-encodes and decodes messages on the channel :) 4 5use strict; 6 7use vars qw($VERSION %IRSSI); 8 9$VERSION = "2003121202"; 10 11%IRSSI = ( 12 authors => "Mariusz 'Craig' Ciesla", 13 contact => "craig\@fish.mac.edu.pl", 14 name => "rot13", 15 description => "ROT13 encoding and reverse :)", 16 license => "GPLv2", 17 changed => "$VERSION", 18 commands => "rot13 unrot13" 19); 20 21use Irssi 20020324; 22 23sub text2rot ($) 24{ 25 my ($text) = @_; 26 27 $text =~ y/N-ZA-Mn-za-m/A-Za-z/; 28 29 return $text." "; 30} 31 32sub rot2text ($) 33{ 34 my ($text) = @_; 35 36 $text =~ y/A-Za-z/N-ZA-Mn-za-m/; 37 38 return $text; 39} 40 41sub rot13_decode ($$$) 42{ 43 my ($server, $target, $text) = @_; 44 45 return unless ($text =~ /(^|.*?) /g); 46 my $witem = $server->window_item_find($target); 47 48 return unless ($witem); 49 $witem->print("%B[ROT13]>>%n ".rot2text($1), MSGLEVEL_CLIENTCRAP); 50} 51 52sub cmd_rot13 ($$$) 53{ 54 my ($arg, $server, $witem) = @_; 55 56 if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')) 57 { 58 $witem->command('MSG '.$witem->{name}.' '.text2rot($arg)); 59 } else { 60 print CLIENTCRAP "%B>>%n ".text2rot($arg); 61 } 62} 63 64sub cmd_unrot13 ($$$) 65{ 66 my ($arg, $server, $witem) = @_; 67 68 print CLIENTCRAP "%B>>%n ".rot2text($arg); 69} 70 71Irssi::command_bind('rot13',\&cmd_rot13); 72Irssi::command_bind('unrot13',\&cmd_unrot13); 73 74Irssi::signal_add('message public',sub {rot13_decode($_[0], $_[4], $_[1]);} ); 75Irssi::signal_add('message own_public',sub {rot13_decode($_[0], $_[2], $_[1]);}); 76 77print "%B>>%n ".$IRSSI{name}." ".$VERSION." loaded"; 78