Subject: | is_away() support in State.pm |
The following patch adds support for checking the away status of nicks
tracked by State.pm.
Subject: | away.diff |
--- State.pm.old 2008-01-12 06:38:00.000000000 +0000
+++ State.pm 2008-01-12 06:42:57.000000000 +0000
@@ -228,6 +228,18 @@
return PCI_EAT_NONE;
}
+sub S_305 {
+ my ($self,$irc) = splice @_, 0, 2;
+ delete $self->{STATE}->{away};
+ return PCI_EAT_NONE;
+}
+
+sub S_306 {
+ my ($self,$irc) = splice @_, 0, 2;
+ $self->{STATE}->{away} = 1;
+ return PCI_EAT_NONE;
+}
+
# Channel MODE
sub S_mode {
my ($self,$irc) = splice @_, 0, 2;
@@ -379,6 +391,12 @@
if ( $status =~ /\*/ ) {
$self->{STATE}->{Nicks}->{ $unick }->{IRCop} = 1;
}
+ if ( $status =~ /G/ ) {
+ $self->{STATE}->{Nicks}->{ $unick }->{Away} = 1;
+ }
+ else {
+ $self->{STATE}->{Nicks}->{ $unick }->{Away} = 0;
+ }
return PCI_EAT_NONE;
}
@@ -684,6 +702,20 @@
return map { $self->{STATE}->{Nicks}->{$_}->{Nick} } keys %{ $self->{STATE}->{Chans}->{ $channel }->{Nicks} };
}
+sub is_away {
+ my $self = shift;
+ my $mapping = $self->isupport('CASEMAPPING');
+ my $nick = u_irc $_[0], $mapping || return;
+ return unless $self->_nick_exists($nick);
+ if ($nick eq u_irc $self->{RealNick}) {
+ # more accurate
+ return 1 if $self->{STATE}->{away};
+ return 0;
+ }
+ return 1 if $self->{STATE}->{Nicks}->{ $nick }->{Away};
+ return 0;
+}
+
sub is_operator {
my $self = shift;
my $mapping = $self->isupport('CASEMAPPING');
@@ -1039,6 +1071,11 @@
Expects a channel as parameter. Returns a list of all nicks on the specified channel. If the component happens
to not be on that channel an empty list will be returned.
+=item is_away
+
+Expects a nick as parameter. Returns 1 if the specified nick is away or 0 otherwise. If the nick does
+not exist in the state then a 0 will be returned.
+
=item is_operator
Expects a nick as parameter. Returns 1 if the specified nick is an IRC operator or 0 otherwise. If the nick does