use Irssi;
use locale;

sub cmd_rows {
  	my ($data, $server, $channel) = @_;

  	if(defined($channel) && $channel) {
		if($data ne "") {
			my @words = split(/\s+/, $data);
			my $len=0;
			foreach(@words) {
				if(length($_) > $len) {
					$len = length($_);
				}
			}
			for(my $i = 0; $i < $len; $i++) {
				my $out = "";
				for(my $j = 0; $j < @words; $j++) {
					$words[$j] =~ s/^(.)//;
					if(defined($1)) {
						$out .= $1;
					} else {
                                        	$out .= " ";
					}
					$j < @words - 1 and $out .= " ";
				}
				$channel->command("/say " . $out);
			}
		}
  	}
}

Irssi::command_bind('rows', 'cmd_rows');
