1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDIRC::IrcContext;
26 use namespace::autoclean;
27 extends "NDIRC::Context";
58 my @command = split / /, $self->reply_string;
59 $self->message(@command, $msg);
63 my ($self,$command, $target, $msg) = @_;
65 $msg =~ s`<b>(.*?)</b>`${\(chr(2))}$1${\(chr(15))}`gi;
66 $msg =~ s`<c(\d+)>(.*?)</c>`${\(chr(3))}$1$2${\(chr(15))}`gi;
68 #Split the message, using the, slightly modified, algorithm from splitlong.pl in the irssi distribution.
69 if ($command eq 'privmsg'){
72 my $maxlength = $self->server->{msg_length} - bytes::length("privmsg $target :" . $self->server->nick_name());
73 my $maxlength2 = $maxlength - bytes::length($lend);
75 if (bytes::length($msg) > ($maxlength)) {
78 while (bytes::length($msg) > ($maxlength)) {
79 my $pos = rindex($msg, " ", $maxlength2);
80 push @spltarr, substr($msg, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos) . $lend;
81 $msg = $lstart . substr($msg, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
86 $self->command($command, $target, $_);
91 $self->command($command, $target, $msg);
95 my ($self,@command) = @_;
97 $self->server->yield(@command);
103 my $query = $self->model->prepare(q{
104 SELECT uid FROM users
107 $query->execute($self->host);
109 if (my ($uid) = $query->fetchrow_array){
119 $s = $_[1] if $#_ >= 1;
120 $s = "" unless defined $s;
121 return "<c05>$s</c>" if $s eq 'Hostile';
122 return "<c03>$s</c>" if $s eq 'Friendly';
123 return "<c12>$s</c>" if $s eq 'Nap' or $s eq 'NAP';
124 return "<b>$s</b>" if $_[0];
128 __PACKAGE__->meta->make_immutable;