]> ruin.nu Git - NDIRC.git/blobdiff - Context.pm
Split long lines, using the algorithm from irssi splitlong.pl
[NDIRC.git] / Context.pm
index 5d0fb1c34f44d0747eb462f91747514a112b3a05..8a0a911a3b2abbaca49a0e8995dc853540c8b19d 100644 (file)
@@ -97,7 +97,67 @@ sub check_user_roles {
 sub reply {
        my ($self,$msg) = @_;
 
-       $self->server->command($self->reply_string . $msg);
+       my @command = split / /, $self->reply_string;
+       $self->message(@command, $msg);
+}
+
+sub message {
+       my ($self,$command, $target, $msg) = @_;
+
+       $msg =~ s`<b>(.*?)</b>`${\(chr(2))}$1${\(chr(15))}`gi;
+       $msg =~ s`<c(\d+)>(.*?)</c>`${\(chr(3))}$1$2${\(chr(15))}`gi;
+
+       #Split the message, using the, slightly modified, algorithm from splitlong.pl in the irssi distribution.
+       if ($command eq 'privmsg'){
+               my $lend = ' ...';
+               my $lstart = '... ';
+               my $maxlength = $self->server->{msg_length} - bytes::length("privmsg $target :" . $self->server->nick_name());
+               my $maxlength2 = $maxlength - bytes::length($lend);
+
+               if (bytes::length($msg) > ($maxlength)) {
+                       my @spltarr;
+
+                       while (bytes::length($msg) > ($maxlength)) {
+                               my $pos = rindex($msg, " ", $maxlength2);
+                               push @spltarr, substr($msg, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2  : $pos)  . $lend;
+                               $msg = $lstart . substr($msg, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
+                       }
+
+                       push @spltarr, $msg;
+                       for (@spltarr) {
+                               $self->command($command, $target, $_);
+                       }
+                       return;
+               }
+       }
+       $self->command($command, $target, $msg);
+}
+
+sub command {
+       my ($self,@command) = @_;
+
+       $self->server->yield(@command);
+}
+
+sub intel_log {
+       my ($c,$planet, $message) = @_;
+       my $log = $c->model->prepare_cached(q{
+INSERT INTO forum_posts (ftid,uid,message) VALUES(
+       (SELECT ftid FROM planets WHERE pid = $3)
+       ,(SELECT uid FROM users WHERE hostmask ILIKE $1)
+       ,$2)
+               });
+       $log->execute($c->host,$message,$planet);
+}
+
+sub def_log {
+       my ($c,$call, $message) = @_;
+       my $log = $c->model->prepare(q{
+INSERT INTO forum_posts (ftid,uid,message) VALUES(
+       (SELECT ftid FROM calls WHERE call = $3)
+       ,(SELECT uid FROM users WHERE hostmask ILIKE $1),$2)
+               });
+       $log->execute($c->host,$message,$call);
 }
 
 sub _build_roles {