altcaps: the irssi plugin

Posted on Wednesday 08 November 2006

#
#  hahaha ? i wrote an irssi script..
#

use strict;
use vars qw($VERSION %IRSSI $random_caps);
use subs qw(rand_cap);

use Irssi qw(signal_add command_bind);

$VERSION = '0.01';

$random_caps = 0;

%IRSSI = (
    author      => 'Michael Gregorowicz',
    contact     => 'junk@mg2.org',
    name        => 'altcaps',
    description => 'i want to make altcaps a hit again.. just like 80s music',
    license     => 'Freely Distributable'
);

sub altcaps {
    my ( $data, $server, $window ) = @_;
    if ($window) {
        if ( $data =~ /^set random_caps (1|0|true|false)$/ ) {
            if ( $1 eq "true" || $1 eq "1" ) {
                $random_caps = 1;
            } else {
                $random_caps = 0;
            }
            $window->print("random_caps set to $random_caps");
            return;
        }
        my $channel = $window->{name};
        my $altcaps = altcapify($data);
        $server->command( 'msg ' . $channel . " $altcaps" );
    }
}

sub altcapify {
    my ($data) = @_;
    my $altcaps;
    my $cap = rand_cap;
    foreach my $byte ( split( //, $data ) ) {
        if ($cap) {
            $altcaps .= uc($byte);
            $cap = 0;
        } else {
            $altcaps .= lc($byte);
            $cap = 1;
        }
        $cap = rand_cap if $random_caps;
    }
    return $altcaps;
}

sub rand_cap {

    # randomly returns 0 or 1.
    return rand(10) % 2;
}

# bind the altcaps sub...
command_bind( altcaps => \&altcaps );
Files: altcaps.pl

Leave a comment

(required)

(optional)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.