use IO::File;
+has disp => (
+ is => 'rw',
+ isa => 'Object',
+ lazy_build => 1
+);
+
# We registered for all events, this will produce some debug info.
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
);
$irc->plugin_add( 'Connector' => $heap->{connector} );
- $kernel->signal($session => 'USR2');
-
$irc->yield( register => 'all' );
$irc->yield( connect => { server => 'irc.netgamers.org' } );
}
sub sig_usr2 {
- my $heap = $_[HEAP];
+ my $self = shift @_;
+
+ $self->disp($self->_build_disp);
+}
+sub _build_disp {
+ my ($self) = @_;
my $disp = new NDIRC::Dispatcher;
if (my $commands = new IO::File 'commands'){
$disp->add_channel($chan,\@types);
}
- $heap->{disp} = $disp;
+ return $disp;
}
sub sig_DIE {
}
sub irc_001 {
- my ($sender,$heap,$kernel) = @_[SENDER,HEAP,KERNEL];
+ my ($self,$sender,$kernel) = @_[OBJECT,SENDER,KERNEL];
# Since this is an irc_* event, we can get the component's object by
# accessing the heap of the sender. Then we register and connect to the
$irc->yield( mode => $irc->nick_name, '+ix');
# we join our channels
- $irc->yield( join => $_ ) for grep /^#/, keys %{$heap->{disp}->channels};
+ $irc->yield( join => $_ ) for grep /^#/, keys %{$self->disp->channels};
return;
}
sub irc_invite {
- my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
+ my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, HEAP, ARG0 .. ARG1];
my $irc = $sender->get_heap();
- $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$heap->{disp}->channels}
+ $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$self->disp->channels}
}
sub irc_public {
sub irc_join {
}
+sub parseCommand {
+ my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
+
+ return if $channel !~ /^#/ && $msg =~ /^~/;
+ $msg = ".$msg" if $channel !~ /^#/ && $msg =~ /^[^.!]/;
+
+ my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
+
+ if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
+ if (!$command || $command =~ m{^http://}){
+ ($p,$command,$args) = ('.','addscan',$msg);
+ }elsif($command ne 'addscan'){
+ $self->parseCommand (".addscan $msg", $server, $nick, $address, $channel, $model)
+ }
+ }
+
+ return 0 unless $self->disp->has_command($command,$channel);
+
+ my $reply_string;
+ given ($p){
+ when ('!'){
+ $reply_string = "privmsg $nick";
+ }
+ when ('~'){
+ $reply_string = "privmsg $channel";
+ }
+ default {
+ $reply_string = "notice $nick";
+ }
+ }
+
+ $address =~ s/.*@(.*)/$1/;
+ my $c = NDIRC::Context->new({
+ host => $address,
+ nick => $nick,
+ channel => $channel,
+ disp => $self->disp,
+ model => $model,
+ server => $server,
+ reply_string => $reply_string,
+ });
+
+ return $self->disp->run_command($c,$command,$args);
+}
+
1;
extends 'NDIRC::Bot';
use POE::Session;
-use NDIRC::Misc;
use ND::DB;
sub irc_public {
- my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
+ my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2];
my ($nick,$username,$address) = ( split /[!@]/, $who );
my $channel = $where->[0];
my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
$seen->execute($address);
- if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
+ if ($msg =~ /^(\S+): (.+)$/ && $self->disp->has_command('anon',$channel)){
my $_ = $1;
my $text = $2;
unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
}
}
- if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},$dbh)){
+ if ($self->parseCommand($msg,$irc,$nick,$address,$channel,$dbh)){
#Command parsed and run successfully
}
}
sub irc_msg {
- my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
+ my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2];
my ($nick,$username,$address) = ( split /[!@]/, $who );
my $irc = $sender->get_heap();
my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
$seen->execute($address);
- if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},$dbh)){
+ if ($self->parseCommand($msg,$irc,$nick,$address,'pm',$dbh)){
#Command parsed and run successfully
}else{
$irc->yield(notice => $nick, "unknown command");
}
sub irc_join {
- my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
+ my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
my ($nick,$username,$address) = ( split /[!@]/, $who );
my $irc = $sender->get_heap();
my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
$seen->execute($address);
- if($heap->{disp}->has_command('voice',$channel)){
+ if($self->disp->has_command('voice',$channel)){
my $flags = $dbh->prepare_cached(q{
SELECT DISTINCT flag
FROM users u
extends 'NDIRC::Bot';
use POE::Session;
-use NDIRC::Misc;
use ND::DB;
my ($tick,$stattick) = DB()->selectrow_array(q{SELECT tick(),max(tick) FROM planet_stats});
my $last_announcement = 0;
sub irc_public {
- my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
+ my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2];
my ($nick,$username,$address) = ( split /[!@]/, $who );
my $channel = $where->[0];
my $irc = $sender->get_heap();
- if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
+ if ($msg =~ /^(\S+): (.+)$/ && $self->disp->has_command('anon',$channel)){
my $_ = $1;
my $text = $2;
unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
}
}
- if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},DB())){
+ if ($self->parseCommand($msg,$irc,$nick,$address,$channel,DB())){
#Command parsed and run successfully
}
}
sub irc_msg {
- my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
+ my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2];
my ($nick,$username,$address) = ( split /[!@]/, $who );
my $irc = $sender->get_heap();
- if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},DB())){
+ if ($self->parseCommand($msg,$irc,$nick,$address,'pm',DB())){
#Command parsed and run successfully
}else{
- my $disp = $heap->{disp};
+ my $disp = $self->disp;
$irc->yield(privmsg => $disp->targets->{def}, chr(3)."04 $nick >> $msg");
- parseCommand("~report_incs $msg",$irc,$nick,' BATCH ',$disp->targets->{def},$heap->{disp},DB());
+ $self->parseCommand("~report_incs $msg",$irc,$nick,' BATCH ',$disp->targets->{def},DB());
}
}
sub irc_join {
- my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
+ my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
my ($nick,$username,$address) = ( split /[!@]/, $who );
my $irc = $sender->get_heap();
- my $disp = $heap->{disp};
+ my $disp = $self->disp;
my $dbh = DB();
}
sub refresh {
- my ($kernel,$heap) = @_[KERNEL,HEAP];
+ my ($self,$kernel,$heap) = @_[OBJECT,KERNEL,HEAP];
$kernel->delay( refresh => 60 );
print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
my $irc = $heap->{irc};
- my $disp = $heap->{disp};
+ my $disp = $self->disp;
my $dbh = DB();
my @row = $dbh->selectrow_array(q{SELECT tick(), max(tick) FROM planet_stats});
while (my $req = $ircreqs->fetchrow_hashref){
if ($req->{channel} eq 'def'){
$irc->yield(privmsg => $disp->targets->{def}, chr(3)."04 ## $req->{username} via webbie ## >> $req->{message}");
- parseCommand("~report_incs $req->{message}",$irc,$req->{username},' BATCH ',$disp->targets->{def},$heap->{disp},$dbh);
+ $self->parseCommand("~report_incs $req->{message}",$irc,$req->{username},' BATCH ',$disp->targets->{def},$dbh);
}elsif(exists $disp->targets->{$req->{channel}}){
$irc->yield(privmsg => $disp->targets->{$req->{channel}}, "<$req->{username} via webbie> $req->{message}");
}
our @ISA = qw/Exporter/;
-our @EXPORT = qw/valuecolor parseCommand/;
+our @EXPORT = qw/valuecolor/;
sub valuecolor {
my $s = $_;
return $s;
}
-sub parseCommand {
- my ($msg, $server, $nick, $address, $channel, $disp,$model) = @_;
-
- return if $channel !~ /^#/ && $msg =~ /^~/;
- $msg = ".$msg" if $channel !~ /^#/ && $msg =~ /^[^.!]/;
-
- my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
-
- if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
- if (!$command || $command =~ m{^http://}){
- ($p,$command,$args) = ('.','addscan',$msg);
- }elsif($command ne 'addscan'){
- parseCommand (".addscan $msg", $server, $nick, $address, $channel, $disp,$model)
- }
- }
-
- return 0 unless $disp->has_command($command,$channel);
-
- my $reply_string;
- given ($p){
- when ('!'){
- $reply_string = "privmsg $nick";
- }
- when ('~'){
- $reply_string = "privmsg $channel";
- }
- default {
- $reply_string = "notice $nick";
- }
- }
-
- $address =~ s/.*@(.*)/$1/;
- my $c = NDIRC::Context->new({
- host => $address,
- nick => $nick,
- channel => $channel,
- disp => $disp,
- model => $model,
- server => $server,
- reply_string => $reply_string,
- });
-
- return $disp->run_command($c,$command,$args);
-}
1;