###########################################################################
##
## ROT26 for irssi 
## Like ROT13 plugin but uses ROT26 :-)
##
## RootBear / OH3NWQ Dec 2009
##
## See the color formats near the end of the script
##
## Based on MORSE for irssi by
## Goblet / OH2MMY  Nov 2001
##
## Does not support WTF8, but who the *uck cares.
##
## This script is published under EVVKTVH license: http://evvk.com/evvktvh.html
## Insert your bug reports and/or complaints into your ass.
##
###########################################################################

use Irssi;
use Irssi::Irc;
use Irssi::UI;
use strict;

sub do_rot26 {
  my ($str) = @_;
  return $str;
}

sub cmd_rot26_say {
  my ($data,$server,$witem) = @_;
  my $window = Irssi::active_win();

  if (!$server || !$server->{connected}) {
      Irssi::print("Not connected to server");
      return;
  }
 
  if ($data && $witem->{type} eq "CHANNEL") {
      $witem->command("^MSG ".$witem->{name}.
                      " |*E*|ROT26|1.0|".do_rot26($data)."|");
  } else {
      Irssi::print("No active channel in window");
  }
  $window->printformat(MSGLEVEL_MSGS,'rot26_own',$data);
}

sub check_rot26 {
  my ($srv, $data, $nick, $addr) = @_;
  my ($dest, $text) = split(/ :/, $data, 2);
  my $server = Irssi::active_server();
  my ($dummy, $tag, $proto, $ver, $txt) = split(/\|/,$text);
  if ($tag eq "*E*" && $proto eq "ROT26") {
    $server->printformat($dest,MSGLEVEL_PUBLIC,'rot26_pub',
                         $nick,do_rot26($txt));
    Irssi::signal_stop();
  }
}

# Here you can change the color formats

Irssi::theme_register([
  'rot26_own', '%yROT26 %n%w>%g $0-',
  'rot26_pub', '%yROT26 %n%c<$0>%n $1-'
]);   

Irssi::signal_add("event privmsg", "check_rot26");
Irssi::command_bind("rot26", "cmd_rot26_say");
Irssi::print("ROT26 1.01 loaded :-P");
