#!/usr/bin/env perl
# Copyright (C) 2004 by İsmail Dönmez, Wouter Coekaerts
# Licensed under GPL v2 or later at your option

use warnings;
use strict;

my $PORT= shift;
my $SERVER= shift;
my $TARGET= shift;

my $i = 0;

if(!@ARGV){
    exec 'dcop', $PORT, 'Konversation', 'error', 'Colorizer script needs a message argument!';
}

my $input = join " ", @ARGV;

if( utf8::valid($input) ) {
    utf8::decode($input);
}

my ($command, $arguments) = ($input =~ /^(\/\S*\s|)(.*)/);
my @chars = split //, $arguments;
@chars = map { "%C" . ((($i++)%15)+1) . $_ } @chars;
$arguments = join "", @chars;

system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, $command . $arguments;

