X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=blobdiff_plain;f=Context.pm;fp=Context.pm;h=7f1d2cc58e9654c71c3208c527486bd91615a737;hp=5810ca4e97dc9cc369b2d6327e716d50ea67fd02;hb=468a4e3e07c0d9e6ed66a75c73f0d7ff2921b90a;hpb=cd18307dc7e3886266937935feffbb41b1df422d diff --git a/Context.pm b/Context.pm index 5810ca4..7f1d2cc 100644 --- a/Context.pm +++ b/Context.pm @@ -23,21 +23,10 @@ use warnings; use feature ':5.10'; use Moose; +use namespace::autoclean; use Set::Object (); -has host => ( - is => 'ro', - isa => 'Str', - required => 1 -); - -has nick => ( - is => 'ro', - isa => 'Str', - required => 1 -); - has channel => ( is => 'ro', isa => 'Str', @@ -56,6 +45,12 @@ has uid => ( lazy_build => 1 ); +has username => ( + is => 'ro', + isa => 'Str', + lazy_build => 1 +); + has disp => ( is => 'ro', isa => 'Object', @@ -68,18 +63,12 @@ has model => ( required => 1 ); -has server => ( +has bot => ( is => 'ro', isa => 'Object', required => 1 ); -has reply_string => ( - is => 'ro', - isa => 'Str', - required => 1, -); - sub assert_user_roles { my ($self,@roles) = @_; return 1 unless @roles; @@ -101,48 +90,12 @@ sub check_user_roles { } sub reply { - my ($self,$msg) = @_; - - my @command = split / /, $self->reply_string; - $self->message(@command, $msg); } sub message { - my ($self,$command, $target, $msg) = @_; - - $msg =~ s`(.*?)`${\(chr(2))}$1${\(chr(15))}`gi; - $msg =~ s`(.*?)`${\(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 replyId { } sub intel_log { @@ -169,9 +122,9 @@ sub _build_roles { my $query = $self->model->prepare(q{ SELECT role FROM group_roles WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid) - WHERE hostmask = $1) + WHERE uid = $1) }); - $query->execute($self->host); + $query->execute($self->uid); my @roles; while (my $group = $query->fetchrow_hashref){ @@ -183,29 +136,30 @@ WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid) sub _build_uid { my ($self) = @_; + return -4; +} + +sub _build_username { + my ($self) = @_; + my $query = $self->model->prepare(q{ -SELECT uid FROM users -WHERE hostmask = $1 +SELECT username FROM users +WHERE uid = $1 }); - $query->execute($self->host); + $query->execute($self->uid); - if (my ($uid) = $query->fetchrow_array){ + if (my ($username) = $query->fetchrow_array){ $query->finish; - return $uid; + return $username; } - return -4; + return "Anonymous"; } sub valuecolor { shift @_; my $s = $_; - $s = $_[1] if $#_ >= 1; - $s = "" unless defined $s; - return "$s" if $s eq 'Hostile'; - return "$s" if $s eq 'Friendly'; - return "$s" if $s eq 'Nap' or $s eq 'NAP'; - return "$s" if $_[0]; return $s; } +__PACKAGE__->meta->make_immutable; 1;